RegexBot/Module/ModLogs/ModLogs.cs

49 lines
1.9 KiB
C#
Raw Normal View History

2018-03-04 23:08:57 +00:00
using Discord.WebSocket;
2018-02-20 08:58:16 +00:00
using Newtonsoft.Json.Linq;
using Noikoio.RegexBot.ConfigItem;
2018-03-04 23:08:57 +00:00
using System.Threading.Tasks;
namespace Noikoio.RegexBot.Module.ModLogs
{
2018-02-20 08:58:16 +00:00
/// <summary>
/// Logs certain events of note to a database for moderators to keep track of user behavior.
/// Makes use of a helper class, <see cref="MessageCache"/>.
/// </summary>
class ModLogs : BotModule
{
2018-02-20 08:58:16 +00:00
private readonly MessageCache _msgCacheInstance;
public ModLogs(DiscordSocketClient client) : base(client)
{
2018-02-23 02:05:50 +00:00
// Do nothing if database unavailable. The user will be informed by ProcessConfiguration.
if (!RegexBot.Config.DatabaseAvailable) return;
2018-02-20 08:58:16 +00:00
// MessageCache (reporting of MessageEdit, MessageDelete) handled by helper class
2018-03-27 22:15:13 +00:00
_msgCacheInstance = new MessageCache(client, Log, delegate (ulong id) { return GetState<GuildState>(id); });
LogEntry.CreateTables();
2018-02-20 08:58:16 +00:00
// TODO add handlers for detecting joins, leaves, bans, kicks, user edits (nick/username/discr)
// TODO add handler for processing the log query command
2018-02-20 08:58:16 +00:00
}
public override async Task<object> CreateInstanceState(JToken configSection)
2018-02-20 08:58:16 +00:00
{
if (configSection == null) return null;
2018-02-20 08:58:16 +00:00
if (configSection.Type != JTokenType.Object)
throw new RuleImportException("Configuration for this section is invalid.");
if (!RegexBot.Config.DatabaseAvailable)
{
2018-02-23 02:05:50 +00:00
await Log("Database access is not available. This module be unavailable.");
2018-02-20 08:58:16 +00:00
return null;
}
2018-03-27 22:15:13 +00:00
var conf = new GuildState((JObject)configSection);
if (conf.RptTypes != LogEntry.LogType.None)
2018-03-04 23:08:57 +00:00
await Log("Enabled event autoreporting to " + conf.RptTarget);
return conf;
2018-02-20 08:58:16 +00:00
}
}
}