diff --git a/ChaosBot/Discord/Services/ExperienceHandler.cs b/ChaosBot/Discord/Services/ExperienceHandler.cs index fe21709..99a5c82 100644 --- a/ChaosBot/Discord/Services/ExperienceHandler.cs +++ b/ChaosBot/Discord/Services/ExperienceHandler.cs @@ -5,6 +5,7 @@ using System.Threading.Channels; using System.Threading.Tasks; using ChaosBot.Models; using ChaosBot.Repositories; +using Discord; using Discord.Commands; using Discord.WebSocket; using Microsoft.EntityFrameworkCore; @@ -64,15 +65,26 @@ namespace ChaosBot.Discord.Services .On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); string ConfigSet = ConfigurationRepository.GetValue("LevelUp:Channel", context.Guild.Id, "false"); + + string mentionString = $"<@{context.User.Id}>"; + if (!ConfigurationRepository.GetValue("LevelUp:MentionUser", context.Guild.Id, true)) + { + mentionString = context.User.Username; + if (context.User is IGuildUser guildUser) + { + mentionString = guildUser.Nickname ?? mentionString; + } + } if (ConfigSet != "false") { + ulong channelId = Convert.ToUInt64(ConfigSet.Substring(2, ConfigSet.Length - 3)); await context.Guild.GetTextChannel(channelId).SendMessageAsync( - $"Grats <@{context.User.Id}>! You have reached level 1 <:wot:740387232514572310>"); + $"Grats {mentionString}! You have reached level 1 <:wot:740387232514572310>"); } else - await context.Channel.SendMessageAsync($"Grats <@{context.User.Id}>! You have reached level 1! <:wot:740387232514572310>"); + await context.Channel.SendMessageAsync($"Grats {mentionString}! You have reached level 1! <:wot:740387232514572310>"); } } } @@ -97,14 +109,25 @@ namespace ChaosBot.Discord.Services { curLevel = usrExperience.Level + 1; string ConfigSet = ConfigurationRepository.GetValue("LevelUp:Channel", usrExperience.DiscordGuildId, "false"); + + string mentionString = $"<@{context.User.Id}>"; + if (!ConfigurationRepository.GetValue("LevelUp:MentionUser", context.Guild.Id, true)) + { + mentionString = context.User.Username; + if (context.User is IGuildUser guildUser) + { + mentionString = guildUser.Nickname ?? mentionString; + } + } + if (ConfigSet != "false") { ulong channelId = Convert.ToUInt64(ConfigSet.Substring(2, ConfigSet.Length - 3)); await context.Guild.GetTextChannel(channelId).SendMessageAsync( - $"Grats <@{usrExperience.DiscordUserId}>! You have reached level {curLevel} <:wot:740387232514572310>"); + $"Grats {mentionString}! You have reached level {curLevel} <:wot:740387232514572310>"); } else - await context.Channel.SendMessageAsync($"Grats <@{usrExperience.DiscordUserId}>! You have reached level {curLevel} <:wot:740387232514572310>"); + await context.Channel.SendMessageAsync($"Grats {mentionString}! You have reached level {curLevel} <:wot:740387232514572310>"); } } catch (Exception ex)