about summary refs log tree commit diff
path: root/Utilities/LibMatrix.DevTestBot/Bot
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-02-09 16:33:14 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-02-09 16:33:14 +0100
commit163e2a94f600ffe0f982e3f605264ff2f2fe312b (patch)
treeaf8fb4c8c468dde726a4773b1304aa22c59186ac /Utilities/LibMatrix.DevTestBot/Bot
parentApply syntax style to LibMatrix (diff)
downloadLibMatrix-163e2a94f600ffe0f982e3f605264ff2f2fe312b.tar.xz
Apply syntax style to LibMatrix side projects
Diffstat (limited to 'Utilities/LibMatrix.DevTestBot/Bot')
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Commands/CmdCommand.cs8
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Commands/DbgAniRainbowTest.cs14
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Commands/HelpCommand.cs6
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Commands/PingCommand.cs6
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/DevTestBot.cs28
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/DevTestBotConfiguration.cs6
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/FileStorageProvider.cs6
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Interfaces/CommandContext.cs2
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/Interfaces/ICommand.cs6
-rw-r--r--Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs14
10 files changed, 36 insertions, 60 deletions
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Commands/CmdCommand.cs b/Utilities/LibMatrix.DevTestBot/Bot/Commands/CmdCommand.cs
index e690890..89a9033 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Commands/CmdCommand.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Commands/CmdCommand.cs
@@ -8,9 +8,7 @@ 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 Task<bool> CanInvoke(CommandContext ctx) => 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 + " ");
@@ -27,7 +25,7 @@ public class CmdCommand : ICommand {
         // .Split("\n").ToList();
 
         var msg = "";
-        EventIdResponse? msgId = await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent {
+        var msgId = await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent {
             FormattedBody = $"Waiting for command output...",
             Body = msg.RemoveAnsi(),
             Format = "m.notice"
@@ -69,4 +67,4 @@ public class CmdCommand : ICommand {
         //     }
         // }
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Commands/DbgAniRainbowTest.cs b/Utilities/LibMatrix.DevTestBot/Bot/Commands/DbgAniRainbowTest.cs
index c526847..f75c863 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Commands/DbgAniRainbowTest.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Commands/DbgAniRainbowTest.cs
@@ -11,26 +11,22 @@ public class DbgAniRainbowTest(IServiceProvider services, HomeserverProviderServ
     public string Name { get; } = "ani-rainbow";
     public string Description { get; } = "[Debug] animated rainbow :)";
 
-    public async Task<bool> CanInvoke(CommandContext ctx) {
-        return ctx.Room.RoomId == "!hLEefBaYvNfJwcTjmt:rory.gay";
-    }
+    public async Task<bool> CanInvoke(CommandContext ctx) => ctx.Room.RoomId == "!hLEefBaYvNfJwcTjmt:rory.gay";
 
     public async Task Invoke(CommandContext ctx) {
         //255 long string
         // var rainbow = "🟥🟧🟨🟩🟦🟪";
         var rainbow = "M";
         var chars = rainbow;
-        for (var i = 0; i < 76; i++) {
-            chars += rainbow[i % rainbow.Length];
-        }
+        for (var i = 0; i < 76; i++) chars += rainbow[i % rainbow.Length];
 
         Task.Run(async () => {
-            int i = 0;
-            var msg = new MessageBuilder(msgType: "m.notice").WithRainbowString(chars).Build();
+            var i = 0;
+            var msg = new MessageBuilder("m.notice").WithRainbowString(chars).Build();
             var msgEvent = await ctx.Room.SendMessageEventAsync(msg);
 
             while (true) {
-                msg = new MessageBuilder(msgType: "m.notice").WithRainbowString(chars, offset: i * 5).Build();
+                msg = new MessageBuilder("m.notice").WithRainbowString(chars, offset: i * 5).Build();
                 if (i % 50 == 0) {
                     msg.NewContent = null;
                     msg.RelatesTo = null;
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Commands/HelpCommand.cs b/Utilities/LibMatrix.DevTestBot/Bot/Commands/HelpCommand.cs
index 23c4fe2..7ecbeb3 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Commands/HelpCommand.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Commands/HelpCommand.cs
@@ -13,10 +13,8 @@ public class HelpCommand(IServiceProvider services) : ICommand {
         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}");
-        }
+        foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}");
 
         await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: sb.ToString()));
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.DevTestBot/Bot/Commands/PingCommand.cs
index ba242fe..85c86a3 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Commands/PingCommand.cs
@@ -7,7 +7,5 @@ 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!"));
-    }
-}
+    public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!"));
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/DevTestBot.cs b/Utilities/LibMatrix.DevTestBot/Bot/DevTestBot.cs
index 678df27..fa80bfd 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/DevTestBot.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/DevTestBot.cs
@@ -20,7 +20,7 @@ public class DevTestBot : IHostedService {
 
     public DevTestBot(HomeserverProviderService homeserverProviderService, ILogger<DevTestBot> logger,
         DevTestBotConfiguration configuration, IServiceProvider services) {
-        logger.LogInformation("{} instantiated!", this.GetType().Name);
+        logger.LogInformation("{} instantiated!", GetType().Name);
         _homeserverProviderService = homeserverProviderService;
         _logger = logger;
         _configuration = configuration;
@@ -49,7 +49,7 @@ public class DevTestBot : IHostedService {
 
         var syncHelper = new SyncHelper(hs);
 
-        await (hs.GetRoom("!DoHEdFablOLjddKWIp:rory.gay")).JoinAsync();
+        await hs.GetRoom("!DoHEdFablOLjddKWIp:rory.gay").JoinAsync();
 
         // foreach (var room in await hs.GetJoinedRooms()) {
         //     if(room.RoomId is "!OGEhHVWSdvArJzumhm:matrix.org") continue;
@@ -65,29 +65,28 @@ public class DevTestBot : IHostedService {
                     x.Type == "m.room.member" && x.StateKey == hs.UserId);
             _logger.LogInformation(
                 $"Got invite to {args.Key} by {inviteEvent.Sender} with reason: {(inviteEvent.TypedContent as RoomMemberEventContent).Reason}");
-            if (inviteEvent.Sender.EndsWith(":rory.gay") || inviteEvent.Sender == "@mxidupwitch:the-apothecary.club") {
+            if (inviteEvent.Sender.EndsWith(":rory.gay") || inviteEvent.Sender == "@mxidupwitch:the-apothecary.club")
                 try {
                     var senderProfile = await hs.GetProfileAsync(inviteEvent.Sender);
-                    await (hs.GetRoom(args.Key)).JoinAsync(reason: $"I was invited by {senderProfile.DisplayName ?? inviteEvent.Sender}!");
+                    await hs.GetRoom(args.Key).JoinAsync(reason: $"I was invited by {senderProfile.DisplayName ?? inviteEvent.Sender}!");
                 }
                 catch (Exception e) {
                     _logger.LogError("{}", e.ToString());
-                    await (hs.GetRoom(args.Key)).LeaveAsync(reason: "I was unable to join the room: " + e);
+                    await hs.GetRoom(args.Key).LeaveAsync("I was unable to join the room: " + e);
                 }
-            }
         });
         syncHelper.TimelineEventHandlers.Add(async @event => {
             _logger.LogInformation(
-                "Got timeline event in {}: {}", @event.RoomId, @event.ToJson(indent: false, ignoreNull: true));
+                "Got timeline event in {}: {}", @event.RoomId, @event.ToJson(false, true));
 
             var room = hs.GetRoom(@event.RoomId);
             // _logger.LogInformation(eventResponse.ToJson(indent: false));
-            if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message }) {
+            if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message })
                 if (message is { MessageType: "m.text" } && message.Body.StartsWith(_configuration.Prefix)) {
                     var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]);
                     if (command == null) {
                         await room.SendMessageEventAsync(
-                            new RoomMessageEventContent(messageType: "m.text", body: "Command not found!"));
+                            new RoomMessageEventContent("m.text", "Command not found!"));
                         return;
                     }
 
@@ -95,15 +94,12 @@ public class DevTestBot : IHostedService {
                         Room = room,
                         MessageEvent = @event
                     };
-                    if (await command.CanInvoke(ctx)) {
+                    if (await command.CanInvoke(ctx))
                         await command.Invoke(ctx);
-                    }
-                    else {
+                    else
                         await room.SendMessageEventAsync(
-                            new RoomMessageEventContent(messageType: "m.text", body: "You do not have permission to run this command!"));
-                    }
+                            new RoomMessageEventContent("m.text", "You do not have permission to run this command!"));
                 }
-            }
         });
         await syncHelper.RunSyncLoopAsync(cancellationToken: cancellationToken);
     }
@@ -114,4 +110,4 @@ public class DevTestBot : IHostedService {
         _logger.LogInformation("Shutting down bot!");
         return Task.CompletedTask;
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/DevTestBotConfiguration.cs b/Utilities/LibMatrix.DevTestBot/Bot/DevTestBotConfiguration.cs
index ef203cd..dcbc670 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/DevTestBotConfiguration.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/DevTestBotConfiguration.cs
@@ -3,10 +3,8 @@ using Microsoft.Extensions.Configuration;
 namespace LibMatrix.ExampleBot.Bot;
 
 public class DevTestBotConfiguration {
-    public DevTestBotConfiguration(IConfiguration config) {
-        config.GetRequiredSection("Bot").Bind(this);
-    }
+    public DevTestBotConfiguration(IConfiguration config) => config.GetRequiredSection("Bot").Bind(this);
     public string Homeserver { get; set; } = "";
     public string AccessToken { get; set; } = "";
     public string Prefix { get; set; }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/FileStorageProvider.cs b/Utilities/LibMatrix.DevTestBot/Bot/FileStorageProvider.cs
index 2c014de..cc866e6 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/FileStorageProvider.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/FileStorageProvider.cs
@@ -18,9 +18,7 @@ public class FileStorageProvider : IStorageProvider {
         new Logger<FileStorageProvider>(new LoggerFactory()).LogInformation("test");
         Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}");
         TargetPath = targetPath;
-        if (!Directory.Exists(targetPath)) {
-            Directory.CreateDirectory(targetPath);
-        }
+        if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
     }
 
     public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson());
@@ -35,4 +33,4 @@ public class FileStorageProvider : IStorageProvider {
         File.Delete(Path.Join(TargetPath, key));
         return Task.CompletedTask;
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/CommandContext.cs
index 6dbb7f9..90a95e4 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/CommandContext.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/CommandContext.cs
@@ -8,4 +8,4 @@ public class CommandContext {
     public StateEventResponse MessageEvent { get; set; }
     public string CommandName => (MessageEvent.TypedContent as RoomMessageEventContent).Body.Split(' ')[0][1..];
     public string[] Args => (MessageEvent.TypedContent as RoomMessageEventContent).Body.Split(' ')[1..];
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/ICommand.cs b/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/ICommand.cs
index 2ba5a27..a6dc8da 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/ICommand.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/Interfaces/ICommand.cs
@@ -4,9 +4,7 @@ public interface ICommand {
     public string Name { get; }
     public string Description { get; }
 
-    public Task<bool> CanInvoke(CommandContext ctx) {
-        return Task.FromResult(true);
-    }
+    public Task<bool> CanInvoke(CommandContext ctx) => Task.FromResult(true);
 
     public Task Invoke(CommandContext ctx);
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs b/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
index 0c04d27..253eb37 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
@@ -36,23 +36,19 @@ public class ServerRoomSizeCalulator : IHostedService {
             throw;
         }
 
-        await (hs.GetRoom("!DoHEdFablOLjddKWIp:rory.gay")).JoinAsync();
+        await hs.GetRoom("!DoHEdFablOLjddKWIp:rory.gay").JoinAsync();
 
         Dictionary<string, int> totalRoomSize = new();
         foreach (var room in await hs.GetJoinedRooms()) {
             var stateList = room.GetFullStateAsync().ToBlockingEnumerable().ToList();
             var roomSize = stateList.Count;
-            if (roomSize > 10000) {
-                await File.AppendAllLinesAsync("large_rooms.txt", new[] { $"{{ \"{room.RoomId}\", {roomSize} }}," }, cancellationToken);
-            }
+            if (roomSize > 10000) await File.AppendAllLinesAsync("large_rooms.txt", new[] { $"{{ \"{room.RoomId}\", {roomSize} }}," }, cancellationToken);
 
             var roomHs = room.RoomId.Split(":")[1];
-            if (totalRoomSize.ContainsKey(roomHs)) {
+            if (totalRoomSize.ContainsKey(roomHs))
                 totalRoomSize[roomHs] += roomSize;
-            }
-            else {
+            else
                 totalRoomSize.Add(roomHs, roomSize);
-            }
 
             _logger.LogInformation($"Got room state for {room.RoomId}!");
         }
@@ -66,4 +62,4 @@ public class ServerRoomSizeCalulator : IHostedService {
         _logger.LogInformation("Shutting down bot!");
         return Task.CompletedTask;
     }
-}
+}
\ No newline at end of file