mcdiscordbot/MinecraftDiscordBot/Services/ChatBoxService.cs

27 lines
1.3 KiB
C#
Raw Normal View History

using Discord.WebSocket;
using MinecraftDiscordBot.Commands;
namespace MinecraftDiscordBot.Services;
public class ChatBoxService : CommandRouter {
private readonly ITaskWaitSource _taskSource;
public ChatBoxService(ITaskWaitSource taskSource) => _taskSource = taskSource;
public override string HelpTextPrefix => "!chat ";
public override Task<ResponseType> FallbackHandler(SocketUserMessage message, string method, string[] parameters, CancellationToken ct)
=> throw new ReplyException($"The chat box cannot do '{method}'!");
private Task<T> Method<T>(string methodName, Func<string, T> parser, CancellationToken ct, Dictionary<string, object>? parameters = null)
=> RootCommandService.Method(_taskSource, methodName, parser, ct, parameters);
public Task<bool> SendMessageAsync(string message, string prefix, CancellationToken ct) => Method("send", RootCommandService.Deserialize<bool>(), ct, new() {
["message"] = message,
["prefix"] = prefix
});
public Task<bool> SendMessageToPlayerAsync(string message, string username, string prefix, CancellationToken ct) => Method("send", RootCommandService.Deserialize<bool>(), ct, new() {
["message"] = message,
["username"] = username,
["prefix"] = prefix
});
}