From 2977ae61f1e62aebf6e7ac33b2b2f7eeab1e431b Mon Sep 17 00:00:00 2001 From: Noi Date: Sun, 28 Apr 2024 01:51:58 -0700 Subject: [PATCH] Whitespace and style fixes --- ApplicationCommands/BirthdayOverrideModule.cs | 10 +++++----- ApplicationCommands/ConfigModule.cs | 12 ++++++------ BackgroundServices/AutoUserDownload.cs | 11 +++++------ BackgroundServices/BirthdayRoleUpdate.cs | 2 +- BackgroundServices/DataRetention.cs | 7 +++---- Common.cs | 4 ++-- Configuration.cs | 2 +- Data/Extensions.cs | 2 +- Data/GuildConfig.cs | 2 +- ShardManager.cs | 2 +- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ApplicationCommands/BirthdayOverrideModule.cs b/ApplicationCommands/BirthdayOverrideModule.cs index 38c199d..efe7327 100644 --- a/ApplicationCommands/BirthdayOverrideModule.cs +++ b/ApplicationCommands/BirthdayOverrideModule.cs @@ -14,8 +14,8 @@ public class BirthdayOverrideModule : BotModuleBase { // TODO possible to use a common base class for shared functionality instead? [SlashCommand("set-birthday", "Set a user's birthday on their behalf.")] - public async Task OvSetBirthday([Summary(description: HelpOptOvTarget)]SocketGuildUser target, - [Summary(description: HelpOptDate)]string date) { + public async Task OvSetBirthday([Summary(description: HelpOptOvTarget)] SocketGuildUser target, + [Summary(description: HelpOptDate)] string date) { int inmonth, inday; try { (inmonth, inday) = ParseDate(date); @@ -43,8 +43,8 @@ public class BirthdayOverrideModule : BotModuleBase { } [SlashCommand("set-timezone", "Set a user's time zone on their behalf.")] - public async Task OvSetTimezone([Summary(description: HelpOptOvTarget)]SocketGuildUser target, - [Summary(description: HelpOptZone)]string zone) { + public async Task OvSetTimezone([Summary(description: HelpOptOvTarget)] SocketGuildUser target, + [Summary(description: HelpOptZone)] string zone) { using var db = new BotDatabaseContext(); var user = target.GetUserEntryOrNew(db); @@ -68,7 +68,7 @@ public class BirthdayOverrideModule : BotModuleBase { } [SlashCommand("remove-birthday", "Remove a user's birthday information on their behalf.")] - public async Task OvRemove([Summary(description: HelpOptOvTarget)]SocketGuildUser target) { + public async Task OvRemove([Summary(description: HelpOptOvTarget)] SocketGuildUser target) { using var db = new BotDatabaseContext(); var user = target.GetUserEntryOrNew(db); if (!user.IsNew) { diff --git a/ApplicationCommands/ConfigModule.cs b/ApplicationCommands/ConfigModule.cs index 2ce338a..0be612b 100644 --- a/ApplicationCommands/ConfigModule.cs +++ b/ApplicationCommands/ConfigModule.cs @@ -112,7 +112,7 @@ public class ConfigModule : BotModuleBase { } [SlashCommand("set-ping", HelpSubCmdPing)] - public async Task CmdSetPing([Summary(description: "Set True to ping users, False to display them normally.")]bool option) { + public async Task CmdSetPing([Summary(description: "Set True to ping users, False to display them normally.")] bool option) { await DoDatabaseUpdate(Context, s => s.AnnouncePing = option); await RespondAsync($":white_check_mark: Announcement pings are now **{(option ? "on" : "off")}**.").ConfigureAwait(false); } @@ -131,8 +131,8 @@ public class ConfigModule : BotModuleBase { [SlashCommand("check", HelpCmdCheck)] public async Task CmdCheck() { static string DoTestFor(string label, Func test) - => $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }"; - + => $"{label}: {(test() ? ":white_check_mark: Yes" : ":x: No")}"; + var guild = Context.Guild; using var db = new BotDatabaseContext(); var guildconf = guild.GetConfigOrNew(db); @@ -141,8 +141,8 @@ public class ConfigModule : BotModuleBase { var result = new StringBuilder(); result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{Shard.ShardId:00}`"); - result.AppendLine($"Number of registered birthdays: `{ guildconf.UserEntries.Count }`"); - result.AppendLine($"Server time zone: `{ guildconf.GuildTimeZone ?? "Not set - using UTC" }`"); + result.AppendLine($"Number of registered birthdays: `{guildconf.UserEntries.Count}`"); + result.AppendLine($"Server time zone: `{guildconf.GuildTimeZone ?? "Not set - using UTC"}`"); result.AppendLine(); var hasMembers = Common.HasMostMembersDownloaded(guild); @@ -180,7 +180,7 @@ public class ConfigModule : BotModuleBase { return announcech != null; })); var disp = announcech == null ? "announcement channel" : $"<#{announcech.Id}>"; - result.AppendLine(DoTestFor($"(Optional) Bot can send messages into { disp }", delegate { + result.AppendLine(DoTestFor($"(Optional) Bot can send messages into {disp}", delegate { if (announcech == null) return false; return guild.CurrentUser.GetPermissions(announcech).SendMessages; })); diff --git a/BackgroundServices/AutoUserDownload.cs b/BackgroundServices/AutoUserDownload.cs index a9f8e15..67dd10b 100644 --- a/BackgroundServices/AutoUserDownload.cs +++ b/BackgroundServices/AutoUserDownload.cs @@ -26,21 +26,20 @@ class AutoUserDownload : BackgroundService { .Select(g => g.Id) .ToHashSet(); // ...and if the guild contains any user data - IEnumerable mustFetch; + HashSet mustFetch; try { await ConcurrentSemaphore.WaitAsync(token); using var db = new BotDatabaseContext(); - mustFetch = db.UserEntries.AsNoTracking() + mustFetch = [.. db.UserEntries.AsNoTracking() .Where(e => incompleteCaches.Contains(e.GuildId)) .Select(e => e.GuildId) - .Where(e => !_skippedGuilds.Contains(e)) - .ToHashSet(); + .Where(e => !_skippedGuilds.Contains(e))]; } finally { try { ConcurrentSemaphore.Release(); } catch (ObjectDisposedException) { } } - + var processed = 0; var processStartTime = DateTimeOffset.UtcNow; foreach (var item in mustFetch) { @@ -67,7 +66,7 @@ class AutoUserDownload : BackgroundService { break; } else if (!dl.IsCompletedSuccessfully) { Log($"Task unresponsive, will skip (ID {guild.Id}, with {guild.MemberCount} members)."); - _skippedGuilds.Add(guild.Id); + _skippedGuilds.Add(guild.Id); continue; } } diff --git a/BackgroundServices/BirthdayRoleUpdate.cs b/BackgroundServices/BirthdayRoleUpdate.cs index ec11c1a..d1008f8 100644 --- a/BackgroundServices/BirthdayRoleUpdate.cs +++ b/BackgroundServices/BirthdayRoleUpdate.cs @@ -94,7 +94,7 @@ class BirthdayRoleUpdate : BackgroundService { // Special case: If user's birthday is 29-Feb and it's currently not a leap year, check against 1-Mar if (!DateTime.IsLeapYear(checkNow.Year) && record.BirthMonth == 2 && record.BirthDay == 29) { if (checkNow.Month == 3 && checkNow.Day == 1) birthdayUsers.Add(record.UserId); - } else if (record.BirthMonth == checkNow.Month && record.BirthDay== checkNow.Day) { + } else if (record.BirthMonth == checkNow.Month && record.BirthDay == checkNow.Day) { birthdayUsers.Add(record.UserId); } } diff --git a/BackgroundServices/DataRetention.cs b/BackgroundServices/DataRetention.cs index 76b1b83..76f4ace 100644 --- a/BackgroundServices/DataRetention.cs +++ b/BackgroundServices/DataRetention.cs @@ -13,9 +13,8 @@ class DataRetention : BackgroundService { const int StaleGuildThreshold = 180; const int StaleUserThreashold = 360; - public DataRetention(ShardInstance instance) : base(instance) { - ProcessInterval = 21600 / Shard.Config.BackgroundInterval; // Process about once per six hours - } + public DataRetention(ShardInstance instance) : base(instance) + => ProcessInterval = 21600 / Shard.Config.BackgroundInterval; // Process about once per six hours public override async Task OnTick(int tickCount, CancellationToken token) { // Run only a subset of shards each time, each running every ProcessInterval ticks. @@ -60,7 +59,7 @@ class DataRetention : BackgroundService { .Where(gu => localGuilds.Contains(gu.GuildId)) .Where(gu => now - TimeSpan.FromDays(StaleUserThreashold) > gu.LastSeen) .ExecuteDeleteAsync(); - + // Build report var resultText = new StringBuilder(); resultText.Append($"Updated {updatedGuilds} guilds, {updatedUsers} users."); diff --git a/Common.cs b/Common.cs index 9096c98..3b10f22 100644 --- a/Common.cs +++ b/Common.cs @@ -21,8 +21,8 @@ static class Common { if (member.DiscriminatorValue == 0) { var username = escapeFormattingCharacters(member.GlobalName ?? member.Username); - if (member.Nickname != null) { - return $"{escapeFormattingCharacters(member.Nickname)} ({username})"; + if (member.Nickname != null) { + return $"{escapeFormattingCharacters(member.Nickname)} ({username})"; } return username; } else { diff --git a/Configuration.cs b/Configuration.cs index ac1f04b..a633ccd 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -18,7 +18,7 @@ class Configuration { public int ShardStart { get; } public int ShardAmount { get; } public int ShardTotal { get; } - + public string? SqlHost { get; } public string? SqlDatabase { get; } public string SqlUsername { get; } diff --git a/Data/Extensions.cs b/Data/Extensions.cs index 01ad926..8693014 100644 --- a/Data/Extensions.cs +++ b/Data/Extensions.cs @@ -5,7 +5,7 @@ internal static class Extensions { /// If it doesn't exist in the database, returns true. /// public static GuildConfig GetConfigOrNew(this SocketGuild guild, BotDatabaseContext db) - => db.GuildConfigurations.Where(g => g.GuildId == guild.Id).FirstOrDefault() + => db.GuildConfigurations.Where(g => g.GuildId == guild.Id).FirstOrDefault() ?? new GuildConfig() { IsNew = true, GuildId = guild.Id }; /// diff --git a/Data/GuildConfig.cs b/Data/GuildConfig.cs index a4cfb1d..09569cd 100644 --- a/Data/GuildConfig.cs +++ b/Data/GuildConfig.cs @@ -21,7 +21,7 @@ public class GuildConfig { public string? AnnounceMessagePl { get; set; } public bool AnnouncePing { get; set; } - + public DateTimeOffset LastSeen { get; set; } [InverseProperty(nameof(UserEntry.Guild))] diff --git a/ShardManager.cs b/ShardManager.cs index 5cf4612..8e08b10 100644 --- a/ShardManager.cs +++ b/ShardManager.cs @@ -128,7 +128,7 @@ class ShardManager : IDisposable { } else { shardStatuses.Append('.'); } - + shardStatuses.AppendLine(); if (lastRun > DeadShardThreshold) {