Whitespace and style fixes

This commit is contained in:
Noi 2024-04-28 01:51:58 -07:00
parent 81da14a6a8
commit 2977ae61f1
10 changed files with 26 additions and 28 deletions

View file

@ -14,8 +14,8 @@ public class BirthdayOverrideModule : BotModuleBase {
// TODO possible to use a common base class for shared functionality instead? // TODO possible to use a common base class for shared functionality instead?
[SlashCommand("set-birthday", "Set a user's birthday on their behalf.")] [SlashCommand("set-birthday", "Set a user's birthday on their behalf.")]
public async Task OvSetBirthday([Summary(description: HelpOptOvTarget)]SocketGuildUser target, public async Task OvSetBirthday([Summary(description: HelpOptOvTarget)] SocketGuildUser target,
[Summary(description: HelpOptDate)]string date) { [Summary(description: HelpOptDate)] string date) {
int inmonth, inday; int inmonth, inday;
try { try {
(inmonth, inday) = ParseDate(date); (inmonth, inday) = ParseDate(date);
@ -43,8 +43,8 @@ public class BirthdayOverrideModule : BotModuleBase {
} }
[SlashCommand("set-timezone", "Set a user's time zone on their behalf.")] [SlashCommand("set-timezone", "Set a user's time zone on their behalf.")]
public async Task OvSetTimezone([Summary(description: HelpOptOvTarget)]SocketGuildUser target, public async Task OvSetTimezone([Summary(description: HelpOptOvTarget)] SocketGuildUser target,
[Summary(description: HelpOptZone)]string zone) { [Summary(description: HelpOptZone)] string zone) {
using var db = new BotDatabaseContext(); using var db = new BotDatabaseContext();
var user = target.GetUserEntryOrNew(db); 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.")] [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(); using var db = new BotDatabaseContext();
var user = target.GetUserEntryOrNew(db); var user = target.GetUserEntryOrNew(db);
if (!user.IsNew) { if (!user.IsNew) {

View file

@ -112,7 +112,7 @@ public class ConfigModule : BotModuleBase {
} }
[SlashCommand("set-ping", HelpSubCmdPing)] [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 DoDatabaseUpdate(Context, s => s.AnnouncePing = option);
await RespondAsync($":white_check_mark: Announcement pings are now **{(option ? "on" : "off")}**.").ConfigureAwait(false); 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)] [SlashCommand("check", HelpCmdCheck)]
public async Task CmdCheck() { public async Task CmdCheck() {
static string DoTestFor(string label, Func<bool> test) static string DoTestFor(string label, Func<bool> test)
=> $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }"; => $"{label}: {(test() ? ":white_check_mark: Yes" : ":x: No")}";
var guild = Context.Guild; var guild = Context.Guild;
using var db = new BotDatabaseContext(); using var db = new BotDatabaseContext();
var guildconf = guild.GetConfigOrNew(db); var guildconf = guild.GetConfigOrNew(db);
@ -141,8 +141,8 @@ public class ConfigModule : BotModuleBase {
var result = new StringBuilder(); var result = new StringBuilder();
result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{Shard.ShardId:00}`"); result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{Shard.ShardId:00}`");
result.AppendLine($"Number of registered birthdays: `{ guildconf.UserEntries.Count }`"); result.AppendLine($"Number of registered birthdays: `{guildconf.UserEntries.Count}`");
result.AppendLine($"Server time zone: `{ guildconf.GuildTimeZone ?? "Not set - using UTC" }`"); result.AppendLine($"Server time zone: `{guildconf.GuildTimeZone ?? "Not set - using UTC"}`");
result.AppendLine(); result.AppendLine();
var hasMembers = Common.HasMostMembersDownloaded(guild); var hasMembers = Common.HasMostMembersDownloaded(guild);
@ -180,7 +180,7 @@ public class ConfigModule : BotModuleBase {
return announcech != null; return announcech != null;
})); }));
var disp = announcech == null ? "announcement channel" : $"<#{announcech.Id}>"; 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; if (announcech == null) return false;
return guild.CurrentUser.GetPermissions(announcech).SendMessages; return guild.CurrentUser.GetPermissions(announcech).SendMessages;
})); }));

View file

@ -26,21 +26,20 @@ class AutoUserDownload : BackgroundService {
.Select(g => g.Id) .Select(g => g.Id)
.ToHashSet(); .ToHashSet();
// ...and if the guild contains any user data // ...and if the guild contains any user data
IEnumerable<ulong> mustFetch; HashSet<ulong> mustFetch;
try { try {
await ConcurrentSemaphore.WaitAsync(token); await ConcurrentSemaphore.WaitAsync(token);
using var db = new BotDatabaseContext(); using var db = new BotDatabaseContext();
mustFetch = db.UserEntries.AsNoTracking() mustFetch = [.. db.UserEntries.AsNoTracking()
.Where(e => incompleteCaches.Contains(e.GuildId)) .Where(e => incompleteCaches.Contains(e.GuildId))
.Select(e => e.GuildId) .Select(e => e.GuildId)
.Where(e => !_skippedGuilds.Contains(e)) .Where(e => !_skippedGuilds.Contains(e))];
.ToHashSet();
} finally { } finally {
try { try {
ConcurrentSemaphore.Release(); ConcurrentSemaphore.Release();
} catch (ObjectDisposedException) { } } catch (ObjectDisposedException) { }
} }
var processed = 0; var processed = 0;
var processStartTime = DateTimeOffset.UtcNow; var processStartTime = DateTimeOffset.UtcNow;
foreach (var item in mustFetch) { foreach (var item in mustFetch) {
@ -67,7 +66,7 @@ class AutoUserDownload : BackgroundService {
break; break;
} else if (!dl.IsCompletedSuccessfully) { } else if (!dl.IsCompletedSuccessfully) {
Log($"Task unresponsive, will skip (ID {guild.Id}, with {guild.MemberCount} members)."); Log($"Task unresponsive, will skip (ID {guild.Id}, with {guild.MemberCount} members).");
_skippedGuilds.Add(guild.Id); _skippedGuilds.Add(guild.Id);
continue; continue;
} }
} }

View file

@ -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 // 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 (!DateTime.IsLeapYear(checkNow.Year) && record.BirthMonth == 2 && record.BirthDay == 29) {
if (checkNow.Month == 3 && checkNow.Day == 1) birthdayUsers.Add(record.UserId); 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); birthdayUsers.Add(record.UserId);
} }
} }

View file

@ -13,9 +13,8 @@ class DataRetention : BackgroundService {
const int StaleGuildThreshold = 180; const int StaleGuildThreshold = 180;
const int StaleUserThreashold = 360; const int StaleUserThreashold = 360;
public DataRetention(ShardInstance instance) : base(instance) { public DataRetention(ShardInstance instance) : base(instance)
ProcessInterval = 21600 / Shard.Config.BackgroundInterval; // Process about once per six hours => ProcessInterval = 21600 / Shard.Config.BackgroundInterval; // Process about once per six hours
}
public override async Task OnTick(int tickCount, CancellationToken token) { public override async Task OnTick(int tickCount, CancellationToken token) {
// Run only a subset of shards each time, each running every ProcessInterval ticks. // 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 => localGuilds.Contains(gu.GuildId))
.Where(gu => now - TimeSpan.FromDays(StaleUserThreashold) > gu.LastSeen) .Where(gu => now - TimeSpan.FromDays(StaleUserThreashold) > gu.LastSeen)
.ExecuteDeleteAsync(); .ExecuteDeleteAsync();
// Build report // Build report
var resultText = new StringBuilder(); var resultText = new StringBuilder();
resultText.Append($"Updated {updatedGuilds} guilds, {updatedUsers} users."); resultText.Append($"Updated {updatedGuilds} guilds, {updatedUsers} users.");

View file

@ -21,8 +21,8 @@ static class Common {
if (member.DiscriminatorValue == 0) { if (member.DiscriminatorValue == 0) {
var username = escapeFormattingCharacters(member.GlobalName ?? member.Username); var username = escapeFormattingCharacters(member.GlobalName ?? member.Username);
if (member.Nickname != null) { if (member.Nickname != null) {
return $"{escapeFormattingCharacters(member.Nickname)} ({username})"; return $"{escapeFormattingCharacters(member.Nickname)} ({username})";
} }
return username; return username;
} else { } else {

View file

@ -18,7 +18,7 @@ class Configuration {
public int ShardStart { get; } public int ShardStart { get; }
public int ShardAmount { get; } public int ShardAmount { get; }
public int ShardTotal { get; } public int ShardTotal { get; }
public string? SqlHost { get; } public string? SqlHost { get; }
public string? SqlDatabase { get; } public string? SqlDatabase { get; }
public string SqlUsername { get; } public string SqlUsername { get; }

View file

@ -5,7 +5,7 @@ internal static class Extensions {
/// If it doesn't exist in the database, <see cref="GuildConfig.IsNew"/> returns true. /// If it doesn't exist in the database, <see cref="GuildConfig.IsNew"/> returns true.
/// </summary> /// </summary>
public static GuildConfig GetConfigOrNew(this SocketGuild guild, BotDatabaseContext db) 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 }; ?? new GuildConfig() { IsNew = true, GuildId = guild.Id };
/// <summary> /// <summary>

View file

@ -21,7 +21,7 @@ public class GuildConfig {
public string? AnnounceMessagePl { get; set; } public string? AnnounceMessagePl { get; set; }
public bool AnnouncePing { get; set; } public bool AnnouncePing { get; set; }
public DateTimeOffset LastSeen { get; set; } public DateTimeOffset LastSeen { get; set; }
[InverseProperty(nameof(UserEntry.Guild))] [InverseProperty(nameof(UserEntry.Guild))]

View file

@ -128,7 +128,7 @@ class ShardManager : IDisposable {
} else { } else {
shardStatuses.Append('.'); shardStatuses.Append('.');
} }
shardStatuses.AppendLine(); shardStatuses.AppendLine();
if (lastRun > DeadShardThreshold) { if (lastRun > DeadShardThreshold) {