Merge branch 'develop' into 'master'
Develop See merge request discord-bots/chaosbot!8
This commit is contained in:
commit
0a0ac8f1ab
76
ChaosBot/Discord/Modules/User/Level.cs
Normal file
76
ChaosBot/Discord/Modules/User/Level.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
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}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.AppendLine($"Name: {Context.User.Mention}");
|
||||||
|
sb.AppendLine($"\tLevel: 0");
|
||||||
|
sb.AppendLine($"\tExperience: 0");
|
||||||
|
sb.AppendLine($"\tNeeded to Level: 123");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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