From 63c86959459a6e6abcec755dcba406b7bcacfccc Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:03:00 -0600 Subject: [PATCH 1/2] Update messages to use preferred usernames Use .GetUserPreferredName() instead of .Mention / .Username. Also, very minor grammar and formatting changes to messages. --- DiscordBot/Services/UserService.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index bec0d61b..81c052fb 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -271,7 +271,7 @@ private async Task LevelUp(SocketMessage messageParam, ulong userId) if (level <= 3) return; - await messageParam.Channel.SendMessageAsync($"**{messageParam.Author}** has leveled up !").DeleteAfterTime(60); + await messageParam.Channel.SendMessageAsync($"**{messageParam.Author.GetUserPreferredName()}** has leveled up!").DeleteAfterTime(60); //TODO Add level up card } @@ -411,7 +411,7 @@ public Embed WelcomeMessage(SocketGuildUser user) string icon = user.GetAvatarUrl(); icon = string.IsNullOrEmpty(icon) ? "https://cdn.discordapp.com/embed/avatars/0.png" : icon; - string welcomeString = $"Welcome to Unity Developer Community {user.GetPreferredAndUsername()}!"; + string welcomeString = $"Welcome to Unity Developer Community, {user.GetPreferredAndUsername()}!"; var builder = new EmbedBuilder() .WithDescription(welcomeString) .WithColor(_welcomeColour) @@ -460,10 +460,10 @@ public async Task Thanks(SocketMessage messageParam) if (_thanksCooldown.HasUser(userId)) { await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.Mention} you must wait " + + $"{messageParam.Author.GetUserPreferredName()}, you must wait " + $"{DateTime.Now - _thanksCooldown[userId]:ss} " + "seconds before giving another karma point." + Environment.NewLine + - "(In the future, if you are trying to thank multiple people, include all their names in the thanks message)") + "(In the future, if you are trying to thank multiple people, include all their names in the thanks message.)") .DeleteAfterTime(defaultDelTime); return; } @@ -478,7 +478,7 @@ await messageParam.Channel.SendMessageAsync( var mentionedSelf = false; var mentionedBot = false; var sb = new StringBuilder(); - sb.Append("**").Append(messageParam.Author.Username).Append("** gave karma to **"); + sb.Append("**").Append(messageParam.Author.GetUserPreferredName()).Append("** gave karma to **"); foreach (var user in mentions) { if (user.IsBot) @@ -494,18 +494,19 @@ await messageParam.Channel.SendMessageAsync( } await _databaseService.Query().IncrementKarma(user.Id.ToString()); - sb.Append(user.Username).Append(" , "); + sb.Append(user.GetUserPreferredName()).Append("**, **"); } // Even if a user gives multiple karma in one message, we only add one. 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 without convoluted tracking - sb.Append("**"); + sb.Length -= 4; //Removes last instance of appended comma/startbold without convoluted tracking + //sb.Append("**"); // Already appended an endbold + sb.Append("."); if (mentionedSelf) await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); + $"{messageParam.Author.GetUserPreferredName()}, you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); _canEditThanks.Remove(messageParam.Id); @@ -550,7 +551,7 @@ public async Task CodeCheck(SocketMessage messageParam) { // A ``` codeblock was found, but no CS, let 'em know await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.Mention} when using code blocks remember to use the ***syntax highlights*** to improve readability.\n{CodeReminderFormattingExample}") + $"{messageParam.Author.GetUserPreferredName()}, when using code blocks remember to use the ***syntax highlights*** to improve readability.\n{CodeReminderFormattingExample}") .DeleteAfterSeconds(seconds: 60); return; } @@ -569,7 +570,7 @@ await messageParam.Channel.SendMessageAsync( { //! CodeReminderCooldown.AddCooldown(userId, _codeReminderCooldownTime); await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.Mention} are you sharing c# scripts? Remember to use codeblocks to help readability!\n{CodeReminderFormattingExample}") + $"{messageParam.Author.GetUserPreferredName()}, are you sharing C# scripts? Remember to use codeblocks to help readability!\n{CodeReminderFormattingExample}") .DeleteAfterSeconds(seconds: 60); if (content.Length > _maxCodeBlockLengthWarning) { @@ -605,7 +606,8 @@ private async Task ScoldForAtEveryoneUsage(SocketMessage messageParam) DateTime.Now.AddSeconds(_settings.EveryoneScoldPeriodSeconds); await messageParam.Channel.SendMessageAsync( - $"Please don't try to alert **everyone** on the server {messageParam.Author.Mention}!\nIf you are asking a question, people will help you when they have time.") + $"Please don't try to alert **everyone** on the server, {messageParam.Author.GetUserPreferredName()}!\n" + + "If you are asking a question, people will help you when they have time.") .DeleteAfterTime(minutes: 2); } } From 8e81ab9808c307d963f282421f9d17e95374986e Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:15:32 -0600 Subject: [PATCH 2/2] Revert some messages using Mention instead of GetUserPreferredName() Revert some messages to use @username (.Mention) again. --- DiscordBot/Services/UserService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 81c052fb..3d513292 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -460,7 +460,7 @@ public async Task Thanks(SocketMessage messageParam) if (_thanksCooldown.HasUser(userId)) { await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.GetUserPreferredName()}, you must wait " + + $"{messageParam.Author.Mention} you must wait " + $"{DateTime.Now - _thanksCooldown[userId]:ss} " + "seconds before giving another karma point." + Environment.NewLine + "(In the future, if you are trying to thank multiple people, include all their names in the thanks message.)") @@ -506,7 +506,7 @@ await messageParam.Channel.SendMessageAsync( sb.Append("."); if (mentionedSelf) await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.GetUserPreferredName()}, you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); + $"{messageParam.Author.Mention} you can't give karma to yourself.").DeleteAfterTime(defaultDelTime); _canEditThanks.Remove(messageParam.Id); @@ -551,7 +551,7 @@ public async Task CodeCheck(SocketMessage messageParam) { // A ``` codeblock was found, but no CS, let 'em know await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.GetUserPreferredName()}, when using code blocks remember to use the ***syntax highlights*** to improve readability.\n{CodeReminderFormattingExample}") + $"{messageParam.Author.Mention} when using code blocks remember to use the ***syntax highlights*** to improve readability.\n{CodeReminderFormattingExample}") .DeleteAfterSeconds(seconds: 60); return; } @@ -570,7 +570,7 @@ await messageParam.Channel.SendMessageAsync( { //! CodeReminderCooldown.AddCooldown(userId, _codeReminderCooldownTime); await messageParam.Channel.SendMessageAsync( - $"{messageParam.Author.GetUserPreferredName()}, are you sharing C# scripts? Remember to use codeblocks to help readability!\n{CodeReminderFormattingExample}") + $"{messageParam.Author.Mention} are you sharing C# scripts? Remember to use codeblocks to help readability!\n{CodeReminderFormattingExample}") .DeleteAfterSeconds(seconds: 60); if (content.Length > _maxCodeBlockLengthWarning) { @@ -606,7 +606,7 @@ private async Task ScoldForAtEveryoneUsage(SocketMessage messageParam) DateTime.Now.AddSeconds(_settings.EveryoneScoldPeriodSeconds); await messageParam.Channel.SendMessageAsync( - $"Please don't try to alert **everyone** on the server, {messageParam.Author.GetUserPreferredName()}!\n" + + $"Please don't try to alert **everyone** on the server, {messageParam.Author.Mention}!\n" + "If you are asking a question, people will help you when they have time.") .DeleteAfterTime(minutes: 2); }