2018-05-11 06:13:00 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2018-05-06 20:09:17 +00:00
|
|
|
|
|
|
|
|
|
namespace Kerobot.Services
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-06-06 22:19:21 +00:00
|
|
|
|
/// Base class for Kerobot services.
|
2018-05-06 20:09:17 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Services provide the core functionality of this program. Modules are expected to call into methods
|
|
|
|
|
/// provided by services for the times when processor-intensive or shared functionality needs to be utilized.
|
|
|
|
|
/// </remarks>
|
2018-05-11 06:13:00 +00:00
|
|
|
|
internal abstract class Service
|
2018-05-06 20:09:17 +00:00
|
|
|
|
{
|
2018-06-06 22:19:21 +00:00
|
|
|
|
public Kerobot Kerobot { get; }
|
2018-05-06 20:09:17 +00:00
|
|
|
|
|
2018-05-11 06:13:00 +00:00
|
|
|
|
public string Name => this.GetType().Name;
|
|
|
|
|
|
2018-06-06 22:19:21 +00:00
|
|
|
|
public Service(Kerobot kb) => Kerobot = kb;
|
2018-05-11 06:13:00 +00:00
|
|
|
|
|
2018-06-05 00:15:18 +00:00
|
|
|
|
/// <summary>
|
2018-06-06 22:19:21 +00:00
|
|
|
|
/// Initializes database tables per-guild.
|
|
|
|
|
/// This method is called by GuildStateService when entering a guild.
|
2018-06-05 00:15:18 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="db">An opened database connection with the appropriate schema option set.</param>
|
|
|
|
|
/// <remarks>If overriding, calling the base method is not necessary.</remarks>
|
|
|
|
|
public virtual Task CreateDatabaseTablesAsync(Npgsql.NpgsqlConnection db) => Task.CompletedTask;
|
|
|
|
|
|
2018-05-11 06:13:00 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a log message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">Logging message contents.</param>
|
|
|
|
|
/// <param name="report">Determines if the log message should be sent to a reporting channel.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected Task Log(string message, bool report = false) => Kerobot.InstanceLogAsync(report, Name, message);
|
2018-05-06 20:09:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|