From cc32d534dc3cb1c7fb72b82bfac65f0acea00a6b Mon Sep 17 00:00:00 2001 From: Noi Date: Thu, 9 May 2024 23:22:51 -0700 Subject: [PATCH] Implement code style suggestions --- Commands/UserCommands.cs | 12 ++++++------ Data/BotDatabaseContext.cs | 2 +- Data/Migrations/.editorconfig | 4 ++++ WorldTime.cs | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 Data/Migrations/.editorconfig diff --git a/Commands/UserCommands.cs b/Commands/UserCommands.cs index d967000..f0f4fa3 100644 --- a/Commands/UserCommands.cs +++ b/Commands/UserCommands.cs @@ -76,9 +76,9 @@ public class UserCommands : CommandsBase { // Generate time and zone names to be displayed, group with associated user IDs var sortedlist = new SortedDictionary>(); var ampm = db.GuildSettings.Where(s => s.GuildId == Context.Guild.Id).SingleOrDefault()?.Use12HourTime ?? false; - foreach ((string area, List users) in userlist.OrderByDescending(o => o.Value.Count)) { + foreach ((var area, List users) in userlist.OrderByDescending(o => o.Value.Count)) { var areaprint = TzPrint(area, ampm); - if (!sortedlist.ContainsKey(areaprint)) sortedlist.Add(areaprint, new List()); + if (!sortedlist.ContainsKey(areaprint)) sortedlist[areaprint] = []; sortedlist[areaprint].AddRange(users); } @@ -87,10 +87,10 @@ public class UserCommands : CommandsBase { // Build zone listings with users var outputlines = new List(); - foreach ((string area, List users) in sortedlist) { + foreach ((var area, List users) in sortedlist) { var buffer = new StringBuilder(); buffer.Append(area[6..] + ": "); - bool empty = true; + var empty = true; foreach (var userid in users) { var userinstance = Context.Guild.GetUser(userid); if (userinstance == null) continue; @@ -107,7 +107,7 @@ public class UserCommands : CommandsBase { // Prepare for output - send buffers out if they become too large outputlines.Sort(); - bool hasOutputOneLine = false; + var hasOutputOneLine = false; // First output is shown as an interaction response, followed then as regular channel messages async Task doOutput(Embed msg) { if (!hasOutputOneLine) { @@ -137,7 +137,7 @@ public class UserCommands : CommandsBase { using var db = DbContext; var result = db.GetUserZone(parameter); if (result == null) { - bool isself = Context.User.Id == parameter.Id; + var isself = Context.User.Id == parameter.Id; if (isself) await RespondAsync(":x: You do not have a time zone. Set it with `tz.set`.", ephemeral: true); else await RespondAsync(":x: The given user does not have a time zone set.", ephemeral: true); return; diff --git a/Data/BotDatabaseContext.cs b/Data/BotDatabaseContext.cs index a3fab44..51af9e8 100644 --- a/Data/BotDatabaseContext.cs +++ b/Data/BotDatabaseContext.cs @@ -102,7 +102,7 @@ public class BotDatabaseContext : DbContext { select Tuple.Create(entry.TimeZone, (ulong)entry.UserId); var resultSet = new Dictionary>(); foreach (var (tz, user) in query) { - if (!resultSet.ContainsKey(tz)) resultSet.Add(tz, new List()); + if (!resultSet.ContainsKey(tz)) resultSet[tz] = []; resultSet[tz].Add(user); } return resultSet; diff --git a/Data/Migrations/.editorconfig b/Data/Migrations/.editorconfig new file mode 100644 index 0000000..5def5b3 --- /dev/null +++ b/Data/Migrations/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] +generated_code = true +dotnet_analyzer_diagnostic.category-CodeQuality.severity = none +dotnet_diagnostic.CS1591.severity = none \ No newline at end of file diff --git a/WorldTime.cs b/WorldTime.cs index 2b8906f..bf9e681 100644 --- a/WorldTime.cs +++ b/WorldTime.cs @@ -104,7 +104,7 @@ internal class WorldTime : IDisposable { // Discord Bots if (!string.IsNullOrEmpty(Config.DBotsToken)) { try { - string dBotsApiUrl = $"https://discord.bots.gg/api/v1/bots/{ botId }/stats"; + var dBotsApiUrl = $"https://discord.bots.gg/api/v1/bots/{ botId }/stats"; var body = $"{{ \"guildCount\": {guildCount} }}"; var uri = new Uri(string.Format(dBotsApiUrl));