Adding !level command.
This commit is contained in:
parent
7169bafb1a
commit
f14c956495
69
ChaosBot/Discord/Modules/User/Level.cs
Normal file
69
ChaosBot/Discord/Modules/User/Level.cs
Normal file
@ -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<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||
IQueryable<Experience> 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}]>.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user