using Discord.WebSocket;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Kerobot.Modules.AutoResponder
{
///
/// Provides the capability to define text responses to pattern-based triggers for fun or informational
/// purposes. Although in essence similar to , it is a better
/// fit for non-moderation use cases and has specific features suitable to that end.
///
[KerobotModule]
class AutoResponder : ModuleBase
{
public AutoResponder(Kerobot kb) : base(kb)
{
DiscordClient.MessageReceived += DiscordClient_MessageReceived;
}
private async Task DiscordClient_MessageReceived(SocketMessage arg)
{
if (!(arg.Channel is SocketGuildChannel ch)) return;
if (arg.Author.IsBot || arg.Author.IsWebhook) return;
var definitions = GetGuildState>(ch.Guild.Id);
if (definitions == null) return; // No configuration in this guild; do no further processing
var tasks = new List();
foreach (var def in definitions)
{
tasks.Add(Task.Run(async () => await ProcessMessageAsync(arg, def)));
}
await Task.WhenAll(tasks);
}
public override Task