Added peripheral list
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user