using System.Threading.Tasks; namespace Kerobot.Services { /// /// Base class for Kerobot service. /// /// /// 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. /// internal abstract class Service { private readonly Kerobot _kb; public Kerobot Kerobot => _kb; public string Name => this.GetType().Name; public Service(Kerobot kb) { _kb = kb; } /// /// Initializes database tables per-guild. Called when entering a guild. /// /// An opened database connection with the appropriate schema option set. /// If overriding, calling the base method is not necessary. public virtual Task CreateDatabaseTablesAsync(Npgsql.NpgsqlConnection db) => Task.CompletedTask; /// /// Creates a log message. /// /// Logging message contents. /// Determines if the log message should be sent to a reporting channel. /// protected Task Log(string message, bool report = false) => Kerobot.InstanceLogAsync(report, Name, message); } }