79 lines
2.8 KiB
C#
79 lines
2.8 KiB
C#
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")]
|
|
[CheckModuleEnabled("Experience")]
|
|
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 = 1 * usrXp.First().Level * (2 * usrXp.First().Level * usrXp.First().Level + 27 * usrXp.First().Level + 91);
|
|
ulong curLevel = usrXp.First().Level;
|
|
ulong nextLevelXP = 5 * curLevel * curLevel * curLevel + 95 * curLevel;
|
|
sb.AppendLine($"Name: {Context.User.Mention}");
|
|
sb.AppendLine($"\tLevel: {usrXp.First().Level}");
|
|
sb.AppendLine($"\tExperience: {usrXp.First().Amount}");
|
|
sb.AppendLine($"\tNeeded to Level: {nextLevelXP}");
|
|
}
|
|
else
|
|
{
|
|
sb.AppendLine($"Name: {Context.User.Mention}");
|
|
sb.AppendLine($"\tLevel: 1");
|
|
sb.AppendLine($"\tExperience: 0");
|
|
sb.AppendLine($"\tNeeded to Level: 120");
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* 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}]>.");
|
|
}
|
|
}
|
|
}
|
|
} |