Added peripheral list

This commit is contained in:
Michael Chen
2022-01-18 14:44:31 +01:00
parent a6ee52f70e
commit 82c8313cb9
3 changed files with 22 additions and 5 deletions

View File

@ -3,6 +3,7 @@ using Fleck;
using MinecraftDiscordBot.Commands;
using MinecraftDiscordBot.Models;
using Newtonsoft.Json;
using System.Linq;
namespace MinecraftDiscordBot.Services;
@ -18,7 +19,7 @@ public class RootCommandService : CommandRouter, ITaskWaitSource {
Chat = new ChatBoxService(this);
}
public static async Task<T> Method<T>(ITaskWaitSource taskSource, string methodName, Func<string, T> parser, CancellationToken ct, Dictionary<string, object>? parameters) {
public static async Task<T> Method<T>(ITaskWaitSource taskSource, string methodName, Func<string, T> parser, CancellationToken ct, Dictionary<string, object>? parameters = null) {
var waiter = taskSource.GetWaiter(parser, ct);
await taskSource.Send(new RequestMessage(waiter.ID, methodName, parameters));
return await waiter.Task;
@ -97,9 +98,13 @@ public class RootCommandService : CommandRouter, ITaskWaitSource {
return waiter;
}
public Task<Dictionary<string, Peripheral>> GetPeripherals(CancellationToken ct) => Method(this, "peripherals", Deserialize<Dictionary<string, Peripheral>>(), ct);
[CommandHandler("rs", HelpText = "Provides some commands for interacting with the Refined Storage system.")]
public Task<ResponseType> RefinedStorageHandler(SocketUserMessage message, string[] parameters, CancellationToken ct)
=> RefinedStorage.HandleCommand(message, parameters, ct);
[CommandHandler("peripherals", HelpText = "Gets a list of peripherals that are attached.")]
public async Task<ResponseType> HandleGetPeripherals(SocketUserMessage message, string[] parameters, CancellationToken ct)
=> ResponseType.AsString(string.Join("\n", (await GetPeripherals(ct)).Values.Select(i => $"On side {i.Side}: {i.Type}")));
[CommandHandler("pd", HelpText = "Provides some commands for interacting with the Player Detector.")]
public Task<ResponseType> PlayerDetectorHandler(SocketUserMessage message, string[] parameters, CancellationToken ct)
=> Players.HandleCommand(message, parameters, ct);