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
diff --git a/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj b/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
index c0be661..6518c67 100644
--- a/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
+++ b/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
@@ -1,33 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>net8.0</TargetFramework>
- <LangVersion>preview</LangVersion>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- <PublishAot>false</PublishAot>
- <InvariantGlobalization>true</InvariantGlobalization>
- <RootNamespace>LibMatrix.ExampleBot</RootNamespace>
-<!-- <PublishTrimmed>true</PublishTrimmed>-->
-<!-- <PublishReadyToRun>true</PublishReadyToRun>-->
-<!-- <PublishSingleFile>true</PublishSingleFile>-->
-<!-- <PublishReadyToRunShowWarnings>true</PublishReadyToRunShowWarnings>-->
-<!-- <PublishTrimmedShowLinkerSizeComparison>true</PublishTrimmedShowLinkerSizeComparison>-->
-<!-- <PublishTrimmedShowLinkerSizeComparisonWarnings>true</PublishTrimmedShowLinkerSizeComparisonWarnings>-->
- </PropertyGroup>
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net8.0</TargetFramework>
+ <LangVersion>preview</LangVersion>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <PublishAot>false</PublishAot>
+ <InvariantGlobalization>true</InvariantGlobalization>
+ <RootNamespace>LibMatrix.ExampleBot</RootNamespace>
+ <!-- <PublishTrimmed>true</PublishTrimmed>-->
+ <!-- <PublishReadyToRun>true</PublishReadyToRun>-->
+ <!-- <PublishSingleFile>true</PublishSingleFile>-->
+ <!-- <PublishReadyToRunShowWarnings>true</PublishReadyToRunShowWarnings>-->
+ <!-- <PublishTrimmedShowLinkerSizeComparison>true</PublishTrimmedShowLinkerSizeComparison>-->
+ <!-- <PublishTrimmedShowLinkerSizeComparisonWarnings>true</PublishTrimmedShowLinkerSizeComparisonWarnings>-->
+ </PropertyGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj" />
- </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/>
+ </ItemGroup>
- <ItemGroup>
- <PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.0-preview7205256004.28c0e5a" />
- <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
- </ItemGroup>
- <ItemGroup>
- <Content Include="appsettings*.json">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- </ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.0-preview7205256004.28c0e5a"/>
+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="appsettings*.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
</Project>
diff --git a/Utilities/LibMatrix.DevTestBot/Program.cs b/Utilities/LibMatrix.DevTestBot/Program.cs
index b53bbfb..eb5ad76 100644
--- a/Utilities/LibMatrix.DevTestBot/Program.cs
+++ b/Utilities/LibMatrix.DevTestBot/Program.cs
@@ -11,10 +11,10 @@ Console.WriteLine("Hello, World!");
var host = Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => {
// services.AddScoped<TieredStorageService>(x =>
- // new TieredStorageService(
- // cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
- // dataStorageProvider: new FileStorageProvider("bot_data/data/")
- // )
+ // new TieredStorageService(
+ // cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
+ // dataStorageProvider: new FileStorageProvider("bot_data/data/")
+ // )
// );
services.AddScoped<DevTestBotConfiguration>();
services.AddRoryLibMatrixServices();
@@ -27,4 +27,4 @@ var host = Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => {
services.AddHostedService<DevTestBot>();
}).UseConsoleLifetime().Build();
-await host.RunAsync();
+await host.RunAsync();
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/Properties/launchSettings.json b/Utilities/LibMatrix.DevTestBot/Properties/launchSettings.json
index 997e294..6c504ff 100644
--- a/Utilities/LibMatrix.DevTestBot/Properties/launchSettings.json
+++ b/Utilities/LibMatrix.DevTestBot/Properties/launchSettings.json
@@ -5,7 +5,6 @@
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
-
}
},
"Development": {
diff --git a/Utilities/LibMatrix.DevTestBot/appsettings.Development.json b/Utilities/LibMatrix.DevTestBot/appsettings.Development.json
index 27bbd50..f999bc2 100644
--- a/Utilities/LibMatrix.DevTestBot/appsettings.Development.json
+++ b/Utilities/LibMatrix.DevTestBot/appsettings.Development.json
@@ -1,9 +1,9 @@
{
- "Logging": {
- "LogLevel": {
- "Default": "Debug",
- "System": "Information",
- "Microsoft": "Information"
- }
+ "Logging": {
+ "LogLevel": {
+ "Default": "Debug",
+ "System": "Information",
+ "Microsoft": "Information"
}
+ }
}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.DevTestBot/appsettings.json b/Utilities/LibMatrix.DevTestBot/appsettings.json
index 6613979..db64c22 100644
--- a/Utilities/LibMatrix.DevTestBot/appsettings.json
+++ b/Utilities/LibMatrix.DevTestBot/appsettings.json
@@ -1,14 +1,14 @@
{
- "Logging": {
- "LogLevel": {
- "Default": "Debug",
- "System": "Information",
- "Microsoft": "Information"
- }
- },
- "Bot": {
- "Homeserver": "rory.gay",
- "AccessToken": "syt_xxxxxxxxxxxxxxxxx",
- "Prefix": "!"
+ "Logging": {
+ "LogLevel": {
+ "Default": "Debug",
+ "System": "Information",
+ "Microsoft": "Information"
}
+ },
+ "Bot": {
+ "Homeserver": "rory.gay",
+ "AccessToken": "syt_xxxxxxxxxxxxxxxxx",
+ "Prefix": "!"
+ }
}
\ No newline at end of file
|