using Discord.WebSocket;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Kerobot.Modules.AutoScriptResponder
{
///
/// Meant to be highly identical to AutoResponder, save for its differentiating feature.
/// This may not be the best approach to it, but do try and copy any relevant changes from one into
/// the other whenever they occur.
/// The feature in question: It executes external scripts and replies with their output.
///
[KerobotModule]
class AutoScriptResponder : ModuleBase
{
public AutoScriptResponder(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