diff --git a/ChaosBot/Discord/Modules/User/Level.cs b/ChaosBot/Discord/Modules/User/Level.cs new file mode 100644 index 0000000..cd9c59f --- /dev/null +++ b/ChaosBot/Discord/Modules/User/Level.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using ChaosBot.Discord.PreConditions; +using ChaosBot.Models; +using ChaosBot.Repositories; +using Discord; +using Discord.Commands; +using Microsoft.Extensions.Configuration; +using NLog; + +namespace ChaosBot.Discord.Modules.User +{ + public class Level : ModuleBase + { + private static readonly ILogger Logger = Program.Logger; + + [Command("level")] + [Alias("xp", "exp", "experience", "lvl")] + [CheckCommandPerm("User")] + public async Task XpShowInfo() + { + try + { + var sb = new StringBuilder(); + var embed = new EmbedBuilder(); + + embed.WithColor(new Color(255, 255, 0)); + embed.Title = $"Current Level Statistics"; + sb.AppendLine(); + + using (ChaosbotContext dbContext = new ChaosbotContext()) + { + IQueryable ctxUser = dbContext.ExperiencePoints; + IQueryable usrXp = ctxUser + .Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)) + .Where(p => p.DiscordUserId.Equals(Context.User.Id)); + + if (usrXp.Any()) + { + ulong nextLevelXP = 6 * (usrXp.First().Level / 2) + 48 * usrXp.First().Level + 123; + sb.AppendLine($"Name: {Context.User.Mention}"); + sb.AppendLine($"\tLevel: {usrXp.First().Level}"); + sb.AppendLine($"\tExperience: {usrXp.First().Amount}"); + sb.AppendLine($"\tNeeded to Level: {nextLevelXP}"); + } + } + + + /* + * Add the string to the Embed + */ + embed.Description = sb.ToString(); + + /* + * Reply with the Embed created above + */ + await ReplyAsync(null, false, embed.Build()); + } + catch(Exception ex) + { + Logger.Error( + $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); + } + } + } +} \ No newline at end of file