From cf0d28f37f748d2b10cbff64bd93cc946eb28ae6 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 12:45:21 -0500 Subject: [PATCH 01/21] Refactor UserService.cs Formats message differently, avoids a karma farming exploit. May refactor again to just use the string extension ToCommaList, and simplify the disallowed mentions logic. --- DiscordBot/Services/UserService.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index a5b90277..3dab6c41 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -435,6 +435,11 @@ public async Task ThanksEdited(Cacheable cachedMessage, SocketM if (_canEditThanks.Contains(messageParam.Id)) await Thanks(messageParam); } + private string Bold(string text) + { + return $"**{text}**"; + } + public async Task Thanks(SocketMessage messageParam) { //Get guild id @@ -476,7 +481,8 @@ await messageParam.Channel.SendMessageAsync( var mentionedSelf = false; var mentionedBot = false; var sb = new StringBuilder(); - sb.Append("**").Append(messageParam.Author.GetUserPreferredName()).Append("** gave karma to **"); + sb.Append(Bold(messageParam.Author.GetUserPreferredName()); + sb.Append(" gave karma to "); foreach (var user in mentions) { if (user.IsBot) @@ -492,27 +498,27 @@ await messageParam.Channel.SendMessageAsync( } await _databaseService.Query.IncrementKarma(user.Id.ToString()); - sb.Append(user.GetUserPreferredName()).Append("**, **"); + sb.Append(Bold(user.GetUserPreferredName()).Append(", "); } - // Even if a user gives multiple karma in one message, we only add one. + //Don't give karma cooldown or credit if user only mentioned himself or the bot or both + if ((mentionedSelf || mentionedBot) && mentions.Count == 1 || + mentionedBot && mentionedSelf && mentions.Count == 2) + return; + + // Even if a user gives multiple karma in one message, we only give one credit. var authorKarmaGiven = await _databaseService.Query.GetKarmaGiven(messageParam.Author.Id.ToString()); await _databaseService.Query.UpdateKarmaGiven(messageParam.Author.Id.ToString(), authorKarmaGiven + 1); - sb.Length -= 4; //Removes last instance of appended comma/startbold without convoluted tracking - //sb.Append("**"); // Already appended an endbold + sb.Length -= 2; //Removes last instance of appended comma sb.Append("."); if (mentionedSelf) await messageParam.Channel.SendMessageAsync( $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); _canEditThanks.Remove(messageParam.Id); - - //Don't give karma cooldown if user only mentioned himself or the bot or both - if ((mentionedSelf || mentionedBot) && mentions.Count == 1 || - mentionedBot && mentionedSelf && mentions.Count == 2) - return; _thanksCooldown.AddCooldown(userId, _thanksCooldownTime); + await messageParam.Channel.SendMessageAsync(sb.ToString()); await _loggingService.LogChannelAndFile(sb + " in channel " + messageParam.Channel.Name); } From 1c8b39bb867ebc27f96161d9fd78ed027fc668a8 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 18:28:22 -0500 Subject: [PATCH 02/21] Add Tips RoleIDs to Settings.cs --- DiscordBot/Settings/Deserialized/Settings.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DiscordBot/Settings/Deserialized/Settings.cs b/DiscordBot/Settings/Deserialized/Settings.cs index e188c1c0..f4868bff 100644 --- a/DiscordBot/Settings/Deserialized/Settings.cs +++ b/DiscordBot/Settings/Deserialized/Settings.cs @@ -106,6 +106,8 @@ public class BotSettings public ulong SubsNewsRoleId { get; set; } public ulong PublisherRoleId { get; set; } public ulong ModeratorRoleId { get; set; } + public ulong TipsUserRoleId { get; set; } // e.g., Helpers + public ulong TipsAuthorRoleId { get; set; } // e.g., Moderators #endregion // User Roles From 12b9d55c1e777f86290cc09a9dc7871c93bca0b0 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:34:54 -0500 Subject: [PATCH 03/21] Refactor Thanks in UserService.cs --- DiscordBot/Services/UserService.cs | 39 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 3dab6c41..2e2c2e45 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -43,6 +43,7 @@ public class UserService private readonly int _thanksMinJoinTime; private readonly string _thanksRegex; + private readonly string _noThanksRegex; private readonly UpdateService _updateService; private readonly Dictionary _xpCooldown; @@ -96,12 +97,14 @@ Init thanks */ var sbThanks = new StringBuilder(); var thx = userSettings.Thanks; - sbThanks.Append("(?i)\\b("); - foreach (var t in thx) sbThanks.Append(t).Append("|"); - + sbThanks.Append(@"(?i)\b("); + foreach (var t in thx) + sbThanks.Append(t).Append("|"); sbThanks.Length--; //Efficiently remove the final pipe that gets added in final loop, simplifying loop - sbThanks.Append(")\\b"); + sbThanks.Append(@")\b"); + _thanksRegex = sbThanks.ToString(); + _noThanksRegex = @"(? who.IsBot || who.Id == userId); + const int defaultDelTime = 120; if (mentions.Count > 0) { @@ -478,12 +488,14 @@ await messageParam.Channel.SendMessageAsync( return; } - var mentionedSelf = false; - var mentionedBot = false; + //var mentionedSelf = false; + //var mentionedBot = false; var sb = new StringBuilder(); sb.Append(Bold(messageParam.Author.GetUserPreferredName()); sb.Append(" gave karma to "); - foreach (var user in mentions) + sb.Append(mentions.ToArray().ToCommaList()); + + /*foreach (var user in mentions) { if (user.IsBot) { @@ -505,6 +517,7 @@ await messageParam.Channel.SendMessageAsync( if ((mentionedSelf || mentionedBot) && mentions.Count == 1 || mentionedBot && mentionedSelf && mentions.Count == 2) return; + */ // Even if a user gives multiple karma in one message, we only give one credit. var authorKarmaGiven = await _databaseService.Query.GetKarmaGiven(messageParam.Author.Id.ToString()); @@ -512,9 +525,9 @@ await messageParam.Channel.SendMessageAsync( sb.Length -= 2; //Removes last instance of appended comma sb.Append("."); - if (mentionedSelf) - await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); + //if (mentionedSelf) + // await messageParam.Channel.SendMessageAsync( + // $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); _canEditThanks.Remove(messageParam.Id); _thanksCooldown.AddCooldown(userId, _thanksCooldownTime); From 2a9fae50d93f13c221cbee481e607868106ffe82 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:41:10 -0500 Subject: [PATCH 04/21] Typo UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 2e2c2e45..d6d42461 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -491,7 +491,7 @@ await messageParam.Channel.SendMessageAsync( //var mentionedSelf = false; //var mentionedBot = false; var sb = new StringBuilder(); - sb.Append(Bold(messageParam.Author.GetUserPreferredName()); + sb.Append(Bold(messageParam.Author.GetUserPreferredName())); sb.Append(" gave karma to "); sb.Append(mentions.ToArray().ToCommaList()); From 73255ae86f71a0a9334b78ce1e06853e570d77ae Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:44:32 -0500 Subject: [PATCH 05/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index d6d42461..ee14c6f1 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -464,8 +464,7 @@ public async Task Thanks(SocketMessage messageParam) var userId = messageParam.Author.Id; var mentions = messageParam.MentionedUsers; - mentions = mentions.Distinct().ToList(); - mentions.RemoveAll(who => who.IsBot || who.Id == userId); + mentions = mentioned.Distinct().Where(who => !who.IsBot && who.Id != userId)).ToList(); const int defaultDelTime = 120; if (mentions.Count > 0) From f67dbb60c628eaacfbc7290d541988192587b656 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:45:33 -0500 Subject: [PATCH 06/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index ee14c6f1..bbbba28c 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -464,7 +464,7 @@ public async Task Thanks(SocketMessage messageParam) var userId = messageParam.Author.Id; var mentions = messageParam.MentionedUsers; - mentions = mentioned.Distinct().Where(who => !who.IsBot && who.Id != userId)).ToList(); + mentions = mentioned.Distinct().Where(who => !who.IsBot && who.Id != userId).ToList(); const int defaultDelTime = 120; if (mentions.Count > 0) From 21550b38daa7b513e8685e3cff8047224040c4b0 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:46:49 -0500 Subject: [PATCH 07/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index bbbba28c..c1ee6db0 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -464,7 +464,7 @@ public async Task Thanks(SocketMessage messageParam) var userId = messageParam.Author.Id; var mentions = messageParam.MentionedUsers; - mentions = mentioned.Distinct().Where(who => !who.IsBot && who.Id != userId).ToList(); + mentions = mentions.Distinct().Where(who => !who.IsBot && who.Id != userId).ToList(); const int defaultDelTime = 120; if (mentions.Count > 0) From 9f79898e6fe45c4cd8aebb874441ba89fd1581f0 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:49:19 -0500 Subject: [PATCH 08/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index c1ee6db0..d37fcb79 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -492,7 +492,7 @@ await messageParam.Channel.SendMessageAsync( var sb = new StringBuilder(); sb.Append(Bold(messageParam.Author.GetUserPreferredName())); sb.Append(" gave karma to "); - sb.Append(mentions.ToArray().ToCommaList()); + sb.Append(mentions.ToMentionArray().ToCommaList()); /*foreach (var user in mentions) { From 11019df84104471d513f367fe89c9be7904cf337 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 20:50:42 -0500 Subject: [PATCH 09/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index d37fcb79..4ee66e4b 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -492,7 +492,7 @@ await messageParam.Channel.SendMessageAsync( var sb = new StringBuilder(); sb.Append(Bold(messageParam.Author.GetUserPreferredName())); sb.Append(" gave karma to "); - sb.Append(mentions.ToMentionArray().ToCommaList()); + sb.Append(mentions.ToArray().ToMentionArray().ToCommaList()); /*foreach (var user in mentions) { From 1265ee1df137282f063aa41971c6e2b2ddd770c6 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:00:41 -0500 Subject: [PATCH 10/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 4ee66e4b..5c3be19f 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -43,7 +43,6 @@ public class UserService private readonly int _thanksMinJoinTime; private readonly string _thanksRegex; - private readonly string _noThanksRegex; private readonly UpdateService _updateService; private readonly Dictionary _xpCooldown; @@ -97,14 +96,13 @@ Init thanks */ var sbThanks = new StringBuilder(); var thx = userSettings.Thanks; - sbThanks.Append(@"(?i)\b("); + sbThanks.Append(@"(?i)(? Date: Thu, 12 Jun 2025 21:12:42 -0500 Subject: [PATCH 11/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 5c3be19f..dff07937 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -517,7 +517,7 @@ await messageParam.Channel.SendMessageAsync( var authorKarmaGiven = await _databaseService.Query.GetKarmaGiven(messageParam.Author.Id.ToString()); await _databaseService.Query.UpdateKarmaGiven(messageParam.Author.Id.ToString(), authorKarmaGiven + 1); - sb.Length -= 2; //Removes last instance of appended comma + //sb.Length -= 2; //Removes last instance of appended comma sb.Append("."); //if (mentionedSelf) // await messageParam.Channel.SendMessageAsync( From db8c2055be7fd6722b0040d8199550e510a495a4 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:16:22 -0500 Subject: [PATCH 12/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index dff07937..b4a2363e 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -442,6 +442,14 @@ private string Bold(string text) return $"**{text}**"; } + private string[] ToBoldArray(string[] texts) + { + var bolds = new string[texts.Length]; + for (int i = 0; i < texts.Length; i++) + bolds[i] = Bold(texts[i]); + return bolds; + } + public async Task Thanks(SocketMessage messageParam) { //Get guild id @@ -487,7 +495,7 @@ await messageParam.Channel.SendMessageAsync( var sb = new StringBuilder(); sb.Append(Bold(messageParam.Author.GetUserPreferredName())); sb.Append(" gave karma to "); - sb.Append(mentions.ToArray().ToMentionArray().ToCommaList()); + sb.Append(mentions.ToArray().ToUserPreferredNameArray().ToBoldArray().ToCommaList()); /*foreach (var user in mentions) { From 5d0f1818b692b604e643910a9ce9a0cc9efec2f5 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:25:41 -0500 Subject: [PATCH 13/21] ToBold and ToBoldArray StringExtensions.cs --- DiscordBot/Extensions/StringExtensions.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/DiscordBot/Extensions/StringExtensions.cs b/DiscordBot/Extensions/StringExtensions.cs index 6f2153b4..96ffa81a 100644 --- a/DiscordBot/Extensions/StringExtensions.cs +++ b/DiscordBot/Extensions/StringExtensions.cs @@ -161,4 +161,18 @@ public static string ToCommaList(this string[] nouns, string conj=null) } return sb.ToString(); } + + public static string ToBold(this string text) + { + return $"**{text}**"; + } + + private static string[] ToBoldArray(this string[] texts) + { + var bolds = new string[texts.Length]; + for (int i = 0; i < texts.Length; i++) + bolds[i] = texts[i].ToBold(); + return bolds; + } + } From 237695507fd7fd590cbfd7fd565196891608d106 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:25:47 -0500 Subject: [PATCH 14/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index b4a2363e..b254df80 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -275,7 +275,7 @@ private async Task LevelUp(SocketMessage messageParam, ulong userId) if (level <= 3) return; - var msg = Bold(messageParam.Author.GetUserPreferredName()) + " has leveled up!"; + var msg = messageParam.Author.GetUserPreferredName().ToBold() + " has leveled up!"; await messageParam.Channel.SendMessageAsync(msg).DeleteAfterTime(60); //TODO Add level up card } @@ -436,19 +436,6 @@ public async Task ThanksEdited(Cacheable cachedMessage, SocketM { if (_canEditThanks.Contains(messageParam.Id)) await Thanks(messageParam); } - - private string Bold(string text) - { - return $"**{text}**"; - } - - private string[] ToBoldArray(string[] texts) - { - var bolds = new string[texts.Length]; - for (int i = 0; i < texts.Length; i++) - bolds[i] = Bold(texts[i]); - return bolds; - } public async Task Thanks(SocketMessage messageParam) { @@ -493,7 +480,7 @@ await messageParam.Channel.SendMessageAsync( //var mentionedSelf = false; //var mentionedBot = false; var sb = new StringBuilder(); - sb.Append(Bold(messageParam.Author.GetUserPreferredName())); + sb.Append(messageParam.Author.GetUserPreferredName().ToBold()); sb.Append(" gave karma to "); sb.Append(mentions.ToArray().ToUserPreferredNameArray().ToBoldArray().ToCommaList()); @@ -512,7 +499,7 @@ await messageParam.Channel.SendMessageAsync( } await _databaseService.Query.IncrementKarma(user.Id.ToString()); - sb.Append(Bold(user.GetUserPreferredName()).Append(", "); + sb.Append(user.GetUserPreferredName().ToBold().Append(", "); } //Don't give karma cooldown or credit if user only mentioned himself or the bot or both From 4595fd857f3a6c8105467448e128486007e4d930 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:28:18 -0500 Subject: [PATCH 15/21] Update StringExtensions.cs --- DiscordBot/Extensions/StringExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Extensions/StringExtensions.cs b/DiscordBot/Extensions/StringExtensions.cs index 96ffa81a..1f0ef267 100644 --- a/DiscordBot/Extensions/StringExtensions.cs +++ b/DiscordBot/Extensions/StringExtensions.cs @@ -167,7 +167,7 @@ public static string ToBold(this string text) return $"**{text}**"; } - private static string[] ToBoldArray(this string[] texts) + public static string[] ToBoldArray(this string[] texts) { var bolds = new string[texts.Length]; for (int i = 0; i < texts.Length; i++) From 0b95aa750f511002adcee83d6d970ec1bc8a47a7 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:36:38 -0500 Subject: [PATCH 16/21] Cleanup UserService.cs --- DiscordBot/Services/UserService.cs | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index b254df80..14683a1b 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -477,46 +477,16 @@ await messageParam.Channel.SendMessageAsync( return; } - //var mentionedSelf = false; - //var mentionedBot = false; var sb = new StringBuilder(); sb.Append(messageParam.Author.GetUserPreferredName().ToBold()); sb.Append(" gave karma to "); sb.Append(mentions.ToArray().ToUserPreferredNameArray().ToBoldArray().ToCommaList()); - /*foreach (var user in mentions) - { - if (user.IsBot) - { - mentionedBot = true; - continue; - } - - if (user.Id == userId) - { - mentionedSelf = true; - continue; - } - - await _databaseService.Query.IncrementKarma(user.Id.ToString()); - sb.Append(user.GetUserPreferredName().ToBold().Append(", "); - } - - //Don't give karma cooldown or credit if user only mentioned himself or the bot or both - if ((mentionedSelf || mentionedBot) && mentions.Count == 1 || - mentionedBot && mentionedSelf && mentions.Count == 2) - return; - */ - // Even if a user gives multiple karma in one message, we only give one credit. var authorKarmaGiven = await _databaseService.Query.GetKarmaGiven(messageParam.Author.Id.ToString()); await _databaseService.Query.UpdateKarmaGiven(messageParam.Author.Id.ToString(), authorKarmaGiven + 1); - //sb.Length -= 2; //Removes last instance of appended comma sb.Append("."); - //if (mentionedSelf) - // await messageParam.Channel.SendMessageAsync( - // $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); _canEditThanks.Remove(messageParam.Id); _thanksCooldown.AddCooldown(userId, _thanksCooldownTime); From f491bf348892247f0729d180531dd1098ddab3ff Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:47:08 -0500 Subject: [PATCH 17/21] Clean up lint in ModerationModule.cs --- DiscordBot/Modules/ModerationModule.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DiscordBot/Modules/ModerationModule.cs b/DiscordBot/Modules/ModerationModule.cs index aecfb26e..48de2952 100644 --- a/DiscordBot/Modules/ModerationModule.cs +++ b/DiscordBot/Modules/ModerationModule.cs @@ -125,7 +125,8 @@ await botCommandChannel.SendMessageAsync( await UserService.MutedUsers.AwaitCooldown(u.Id); await UnmuteUser(user, true); - reply?.DeleteAsync(); + if (reply != null) + await reply.DeleteAsync(); } [Command("Unmute")] @@ -493,7 +494,7 @@ public async Task ChannelTags(ulong channelId) .WithColor(Color.Blue) .Build(); - Context.Message.DeleteAsync(); + await Context.Message.DeleteAsync(); await ReplyAsync(embed: embed).DeleteAfterSeconds(seconds: 60); } @@ -511,4 +512,4 @@ public async Task ModerationHelp() } } #endregion -} \ No newline at end of file +} From ee669e8f719aa9c0588926676e3933eca38915b4 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:48:12 -0500 Subject: [PATCH 18/21] Clean up lint in WebUtil.cs --- DiscordBot/Utils/WebUtil.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DiscordBot/Utils/WebUtil.cs b/DiscordBot/Utils/WebUtil.cs index b521eb86..0f9bace5 100644 --- a/DiscordBot/Utils/WebUtil.cs +++ b/DiscordBot/Utils/WebUtil.cs @@ -38,7 +38,7 @@ public static async Task GetHtmlDocument(string url) doc.LoadHtml(html); return doc; } - catch (Exception e) + catch (Exception _) { return null; } @@ -55,7 +55,7 @@ public static async Task GetHtmlNode(string url, string xpath) var doc = await GetHtmlDocument(url); return doc.DocumentNode.SelectSingleNode(xpath); } - catch (Exception e) + catch (Exception _) { return null; } @@ -71,7 +71,7 @@ public static async Task GetHtmlNodes(string url, string xpa var doc = await GetHtmlDocument(url); return doc.DocumentNode.SelectNodes(xpath); } - catch (Exception e) + catch (Exception _) { return null; } @@ -87,7 +87,7 @@ public static async Task GetHtmlNodeInnerText(string url, string xpath) var node = await GetHtmlNode(url, xpath); return WebUtility.HtmlDecode(node?.InnerText); } - catch (Exception e) + catch (Exception _) { return string.Empty; } @@ -147,4 +147,4 @@ public static async Task GetObjectFromJson(string url) return (false, default); } } -} \ No newline at end of file +} From c7c85ce9f3b26e242ebd440a18df40d45f1ccd71 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:50:59 -0500 Subject: [PATCH 19/21] Update WebUtil.cs --- DiscordBot/Utils/WebUtil.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DiscordBot/Utils/WebUtil.cs b/DiscordBot/Utils/WebUtil.cs index 0f9bace5..80cd6591 100644 --- a/DiscordBot/Utils/WebUtil.cs +++ b/DiscordBot/Utils/WebUtil.cs @@ -38,7 +38,7 @@ public static async Task GetHtmlDocument(string url) doc.LoadHtml(html); return doc; } - catch (Exception _) + catch (Exception) { return null; } @@ -55,7 +55,7 @@ public static async Task GetHtmlNode(string url, string xpath) var doc = await GetHtmlDocument(url); return doc.DocumentNode.SelectSingleNode(xpath); } - catch (Exception _) + catch (Exception) { return null; } @@ -71,7 +71,7 @@ public static async Task GetHtmlNodes(string url, string xpa var doc = await GetHtmlDocument(url); return doc.DocumentNode.SelectNodes(xpath); } - catch (Exception _) + catch (Exception) { return null; } @@ -87,7 +87,7 @@ public static async Task GetHtmlNodeInnerText(string url, string xpath) var node = await GetHtmlNode(url, xpath); return WebUtility.HtmlDecode(node?.InnerText); } - catch (Exception _) + catch (Exception) { return string.Empty; } From 591dc426a4ac3d670dd1f66a44e2802588e72b86 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:58:00 -0500 Subject: [PATCH 20/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 14683a1b..b50f558c 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -98,7 +98,7 @@ Init thanks var thx = userSettings.Thanks; sbThanks.Append(@"(?i)(? Date: Fri, 13 Jun 2025 16:15:21 -0500 Subject: [PATCH 21/21] Update UserService.cs --- DiscordBot/Services/UserService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index b50f558c..2d5ccea6 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -481,6 +481,8 @@ await messageParam.Channel.SendMessageAsync( sb.Append(messageParam.Author.GetUserPreferredName().ToBold()); sb.Append(" gave karma to "); sb.Append(mentions.ToArray().ToUserPreferredNameArray().ToBoldArray().ToCommaList()); + foreach (var mention in mentions) + await _databaseService.Query.IncrementKarma(mention.Id.ToString()); // Even if a user gives multiple karma in one message, we only give one credit. var authorKarmaGiven = await _databaseService.Query.GetKarmaGiven(messageParam.Author.Id.ToString());