Skip to content

Commit

Permalink
Merge pull request #270 from hariedo/feature/karma-usernames
Browse files Browse the repository at this point in the history
Karma messages have minor formatting changes and use GetUserPreferredName()
  • Loading branch information
Pierre-Demessence authored Nov 22, 2023
2 parents 1117803 + 8e81ab9 commit 1b56c9b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions DiscordBot/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -463,7 +463,7 @@ await messageParam.Channel.SendMessageAsync(
$"{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)")
"(In the future, if you are trying to thank multiple people, include all their names in the thanks message.)")
.DeleteAfterTime(defaultDelTime);
return;
}
Expand All @@ -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)
Expand All @@ -494,15 +494,16 @@ 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);
Expand Down Expand Up @@ -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.Mention} are you sharing C# scripts? Remember to use codeblocks to help readability!\n{CodeReminderFormattingExample}")
.DeleteAfterSeconds(seconds: 60);
if (content.Length > _maxCodeBlockLengthWarning)
{
Expand Down Expand Up @@ -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.Mention}!\n" +
"If you are asking a question, people will help you when they have time.")
.DeleteAfterTime(minutes: 2);
}
}
Expand Down

0 comments on commit 1b56c9b

Please sign in to comment.