about summary refs log tree commit diff
path: root/ExampleBots/LibMatrix.ExampleBot/Bot/Commands
diff options
context:
space:
mode:
Diffstat (limited to 'ExampleBots/LibMatrix.ExampleBot/Bot/Commands')
-rw-r--r--ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs72
-rw-r--r--ExampleBots/LibMatrix.ExampleBot/Bot/Commands/HelpCommand.cs22
-rw-r--r--ExampleBots/LibMatrix.ExampleBot/Bot/Commands/PingCommand.cs13
3 files changed, 0 insertions, 107 deletions
diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs
deleted file mode 100644
index e690890..0000000
--- a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using ArcaneLibs.StringNormalisation;
-using LibMatrix.EventTypes.Spec;
-using LibMatrix.ExampleBot.Bot.Interfaces;
-
-namespace LibMatrix.ExampleBot.Bot.Commands;
-
-public class CmdCommand : ICommand {
-    public string Name => "cmd";
-    public string Description => "Runs a command on the host system";
-
-    public Task<bool> CanInvoke(CommandContext ctx) {
-        return Task.FromResult(ctx.MessageEvent.Sender.EndsWith(":rory.gay") || ctx.MessageEvent.Sender.EndsWith(":conduit.rory.gay"));
-    }
-
-    public async Task Invoke(CommandContext ctx) {
-        var cmd = ctx.Args.Aggregate("\"", (current, arg) => current + arg + " ");
-
-        cmd = cmd.Trim();
-        cmd += "\"";
-
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: $"Command being executed: `{cmd}`"));
-
-        var output = ArcaneLibs.Util.GetCommandOutputAsync(
-            Environment.OSVersion.Platform == PlatformID.Unix ? "/bin/sh" : "cmd.exe",
-            (Environment.OSVersion.Platform == PlatformID.Unix ? "-c " : "/c ") + cmd);
-        // .Replace("`", "\\`")
-        // .Split("\n").ToList();
-
-        var msg = "";
-        EventIdResponse? msgId = await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent {
-            FormattedBody = $"Waiting for command output...",
-            Body = msg.RemoveAnsi(),
-            Format = "m.notice"
-        });
-
-        var lastSendTask = Task.CompletedTask;
-        await foreach (var @out in output) {
-            Console.WriteLine($"{@out.Length:0000} {@out}");
-            msg += @out + "\n";
-            if (lastSendTask.IsCompleted)
-                lastSendTask = ctx.Room.SendMessageEventAsync(new RoomMessageEventContent {
-                    FormattedBody = $"<pre class=\"language-csharp\">\n{msg}\n</pre>",
-                    Body = msg.RemoveAnsi(),
-                    Format = "org.matrix.custom.html"
-                });
-            if (msg.Length > 31000) {
-                await lastSendTask;
-                msgId = await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent {
-                    FormattedBody = $"Waiting for command output...",
-                    Body = msg.RemoveAnsi(),
-                    Format = "m.notice"
-                });
-                msg = "";
-            }
-        }
-
-        // while (output.Count > 0) {
-        //     Console.WriteLine("Adding: " + output[0]);
-        //     msg += output[0] + "\n";
-        //     output.RemoveAt(0);
-        //     if ((output.Count > 0 && (msg + output[0]).Length > 31500) || output.Count == 0) {
-        //         await ctx.Room.SendMessageEventAsync("m.room.message", new RoomMessageEventContent {
-        //             FormattedBody = $"<pre class=\"language-csharp\">\n{msg}\n</pre>",
-        //             // Body = Markdig.Markdown.ToHtml(msg),
-        //             Body = msg.RemoveAnsi(),
-        //             Format = "org.matrix.custom.html"
-        //         });
-        //         msg = "";
-        //     }
-        // }
-    }
-}
diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/HelpCommand.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/HelpCommand.cs
deleted file mode 100644
index 23c4fe2..0000000
--- a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/HelpCommand.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System.Text;
-using LibMatrix.EventTypes.Spec;
-using LibMatrix.ExampleBot.Bot.Interfaces;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace LibMatrix.ExampleBot.Bot.Commands;
-
-public class HelpCommand(IServiceProvider services) : ICommand {
-    public string Name { get; } = "help";
-    public string Description { get; } = "Displays this help message";
-
-    public async Task Invoke(CommandContext ctx) {
-        var sb = new StringBuilder();
-        sb.AppendLine("Available commands:");
-        var commands = services.GetServices<ICommand>().ToList();
-        foreach (var command in commands) {
-            sb.AppendLine($"- {command.Name}: {command.Description}");
-        }
-
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: sb.ToString()));
-    }
-}
diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/PingCommand.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/PingCommand.cs
deleted file mode 100644
index ba242fe..0000000
--- a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/PingCommand.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using LibMatrix.EventTypes.Spec;
-using LibMatrix.ExampleBot.Bot.Interfaces;
-
-namespace LibMatrix.ExampleBot.Bot.Commands;
-
-public class PingCommand : ICommand {
-    public string Name { get; } = "ping";
-    public string Description { get; } = "Pong!";
-
-    public async Task Invoke(CommandContext ctx) {
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!"));
-    }
-}