public async Task Info([Summary("The user you want to display XP")] IGuildUser user) { try { if (!GuildConfigManager.Get(Context.Guild.Id).EnableXpSystem) { await ReplyAsync("XP System is disabled for this Guild! An Admin can use `$togglexp`!"); return; } var xp = XpManager.Get(Context.Guild, user); var builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = user.IsBot ? $"{Helper.GetName(user)}'s XP (Bot)" : $"{Helper.GetName(user)}'s XP", IconUrl = user.GetAvatarUrl() }, Color = new Color(50, 125, 0) }; builder.AddInlineField("XP", xp.Xp); builder.AddInlineField("Level", xp.Level); builder.AddInlineField("Next Level", XpManager.GetXp(xp.Level + 1) - xp.Xp); await ReplyAsync("", embed : builder.Build()); } catch { await ReplyAsync($"I couldn't look up any Info about {Helper.GetName(user)}, sorry.."); } }
public async Task Stats() { try { IUser user = Context.User; string uname = user.Username ?? "?"; string nick = (user as IGuildUser).Nickname ?? "/"; string createdAt = user.CreatedAt.ToString("d") ?? "/"; DateTimeOffset?joinedAtDate = (user as IGuildUser).JoinedAt; string joinedAt; if (joinedAtDate != null) { joinedAt = joinedAtDate?.ToString("d"); } else { joinedAt = "/"; } string status = user.Status.ToString() ?? "/"; Game? nullableGame = user.Game; string game; if (nullableGame != null) { game = nullableGame?.ToString(); } else { game = "/"; } string xp = XpManager.Get(user).Xp.ToString(); EmbedBuilder builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = user.IsBot ? $"{uname} (Bot)" : $"{uname}", IconUrl = user.GetAvatarUrl() }, Color = new Color(50, 125, 0) }; builder.AddField("Nickname", nick); builder.AddField("Created At", createdAt); builder.AddField("Joined At", joinedAt); builder.AddField("Status", status); builder.AddField("Game", game); builder.AddField("XP", xp); await ReplyAsync("", embed : builder.Build()); } catch (Exception ex) { await ReplyAsync($"Error! ({ex.Message})"); } }
public async Task Give([Summary("The user to give XP")] IGuildUser user, [Summary("The amount of XP you want to give the user")] int xp) { try { if (user.Id == Context.User.Id) { await ReplyAsync("Nice try, you can't give yourself XP!"); return; } if (xp == 0) { await ReplyAsync("Wow man. How generous. :+1:"); return; } IGuildUser guilduser = Context.User as IGuildUser; if (xp < 1 && !guilduser.GuildPermissions.Administrator) { await ReplyAsync("Nice try, you can't drain XP from Users!"); return; } int ownXp = xp / Information.OwnXp; XpManager.UserXp userxp = XpManager.Get(Context.User); if (userxp.XpReserve >= xp) { int lvlBefore = XpManager.Get(user).Level; XpManager.Update(user, xp, 0); int lvlAfter = XpManager.Get(user).Level; //Drain XP from Sender, minus own XP (you get 1/100 from donations) XpManager.Update(Context.User, ownXp, -xp); await ReplyAsync($"{Helper.GetName(Context.User)} donated {Helper.GetName(user)} {xp} XP! :money_with_wings:"); if (lvlAfter > lvlBefore) { await ReplyAsync($":tada: {Helper.GetName(user)} was promoted to level {lvlAfter}! :tada:"); } } else { await ReplyAsync($"You can't give {xp} XP to {Helper.GetName(user)}, you only have {userxp.XpReserve} XP!"); } } catch { await ReplyAsync("Whoops, I couldn't give XP to that user!"); } }
public async Task Info() { try { if (Context.User is IGuildUser user) { string uname = user.Username ?? "?"; string nick = user.Nickname ?? "/"; string createdAt = user.CreatedAt.ToString("d") ?? "/"; var joinedAtDate = user.JoinedAt; string joinedAt = joinedAtDate != null?joinedAtDate.Value.ToString("d") : "/"; string status = user.Status.ToString() ?? "/"; var nullableGame = user.Game; string game = nullableGame != null?nullableGame.Value.ToString() : "/"; string xp = GuildConfigManager.Get(Context.Guild.Id).EnableXpSystem ? XpManager.Get(Context.Guild, user).Xp.ToString() : "[disabled]"; var builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = user.IsBot ? $"{uname} (Bot)" : $"{uname}" //IconUrl = user.GetAvatarUrl() }, Color = new Color(50, 125, 0), ThumbnailUrl = user.GetAvatarUrl() }; builder.AddInlineField("Nickname", nick); builder.AddInlineField("Created At", createdAt); builder.AddInlineField("Joined At", joinedAt); builder.AddInlineField("Status", status); builder.AddInlineField("Game", game); builder.AddInlineField("XP", xp); await ReplyAsync("", embed : builder.Build()); } } catch (Exception ex) { await ReplyAsync($"Error! ({ex.Message})"); } }
public async Task Set([Summary("The user to set XP")] IGuildUser user, [Summary("The amount of XP you want to set")] int xp) { try { if (Context.User is IGuildUser setter) { if (!GuildConfigManager.Get(Context.Guild.Id).EnableXpSystem) { await ReplyAsync("XP System is disabled for this Guild! An Admin can use `$togglexp`!"); return; } if (!Helper.IsOwner(setter) && !setter.GuildPermissions.ManageMessages) { await ReplyAsync("Sorry, but you're not allowed to use that super premium command!"); return; } var userxp = XpManager.Get(Context.Guild, user); XpManager.Update(Context.Guild, user, xp - userxp.Xp); await ReplyAsync($"{Helper.GetName(user)} set {user.Mention}'s XP to {xp}!"); } else { await ReplyAsync("You can't use that command in DM!"); } ConsoleHelper.Log($"{Helper.GetName(Context.User)} set {Helper.GetName(user)}'s XP to {xp}!", LogSeverity.Info); } catch (Exception ex) { ConsoleHelper.Log($"Could not set {Helper.GetName(user)}'s XP! ({ex.Message})", LogSeverity.Error); await ReplyAsync("Whoops, I couldn't give XP to that user!"); } }
public async Task Info([Summary("The user you want to display XP")] IGuildUser user) { try { XpManager.UserXp xp = XpManager.Get(user); EmbedBuilder builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = user.IsBot ? $"{Helper.GetName(user)}'s XP (Bot)" : $"{Helper.GetName(user)}'s XP", IconUrl = user.GetAvatarUrl() }, Color = new Color(50, 125, 0) }; builder.AddField("XP", xp.Xp); builder.AddField("Reserve XP", xp.XpReserve); builder.AddField("Level", xp.Level); builder.AddField("Next Level", XpManager.GetXp(xp.Level + 1) - xp.Xp); await ReplyAsync("", embed : builder.Build()); } catch { await ReplyAsync($"I couldn't look up any Info about {Helper.GetName(user)}, sorry.."); } }
public async Task Info() { try { XpManager.UserXp xp = XpManager.Get(Context.User); EmbedBuilder builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = Context.User.IsBot ? $"{Helper.GetName(Context.User)}'s XP (Bot)" : $"{Helper.GetName(Context.User)}'s XP", IconUrl = Context.User.GetAvatarUrl() }, Color = new Color(50, 125, 0) }; builder.AddField("XP", xp.Xp); builder.AddField("Reserve XP", xp.XpReserve); builder.AddField("Level", xp.Level); builder.AddField("Next Level", XpManager.GetXp(xp.Level + 1) - xp.Xp); await ReplyAsync("", embed : builder.Build()); } catch { await ReplyAsync("I couldn't look up any Info about you, sorry.."); } }
public async Task Stats() { try { if (!GuildConfigManager.Get(Context.Guild.Id).EnableXpSystem) { await ReplyAsync("XP System is disabled for this Guild! An Admin can use `$togglexp`!"); return; } var xps = XpManager.Top10(Context.Guild); if (xps.Count < 1) { await ReplyAsync("I couldn't find any users.."); return; } var builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = $"XP Ranking for {Context.Guild.Name} 🏆" }, ThumbnailUrl = Context.Guild.IconUrl, Color = new Color(255, 163, 50), Footer = new EmbedFooterBuilder { Text = $"..out of {XpManager.Get(Context.Guild).Count} total XP users" } }; int max = xps.Count > 10 ? 10 : xps.Count; for (int i = 0; i < max; i++) { var xp = xps[i]; IUser user = await Context.Guild.GetUserAsync(xp.UserId); string place; switch (i) { case 0: place = ":first_place: 1"; break; case 1: place = ":second_place: 2"; break; case 2: place = ":third_place: 3"; break; default: place = $"{i + 1}"; break; } builder.AddField($"{place}. {Helper.GetName(user)}", $"XP: **{xp.Xp}** | Level: **{xp.Level}**"); } try { var firstXp = xps[0]; IUser firstUser = await Context.Guild.GetUserAsync(firstXp.UserId); await ReplyAsync( $"Good job **{Helper.GetName(firstUser)}** on being first place with **{firstXp.Xp}** XP!", embed : builder.Build()); } catch { await ReplyAsync("", embed : builder.Build()); } } catch { await ReplyAsync("I couldn't do a full ranking for that guild, sorry.. :confused:"); } }
public async Task Give([Summary("The user to give XP")] IGuildUser user, [Summary("The amount of XP you want to give the user")] int xp) { try { if (!GuildConfigManager.Get(Context.Guild.Id).EnableXpSystem) { await ReplyAsync("XP System is disabled for this Guild! An Admin can use `$togglexp`!"); return; } if (user.Id == Context.User.Id) { await ReplyAsync("Nice try, you can't give yourself XP!"); return; } if (xp == 0) { await ReplyAsync("Wow man. How generous. :+1:"); return; } bool canDrain = false; //Is sender Admin? bool drainOwn = true; //False if Admin is draining XP if (Context.User is IGuildUser guilduser && guilduser.GuildPermissions.Administrator) { canDrain = true; } if (xp < 1) { if (!canDrain) { await ReplyAsync("Nice try, you can't drain XP from Users!"); return; } else { drainOwn = false; } } int ownXp = xp / Information.OwnXp; var userxp = XpManager.Get(Context.Guild, Context.User); if (userxp.Xp >= xp) { int lvlBefore = XpManager.Get(Context.Guild, user).Level; XpManager.Update(Context.Guild, user, xp); int lvlAfter = XpManager.Get(Context.Guild, user).Level; //Drain XP from Sender, minus own XP (you get 1/100 from donations) if (drainOwn) { XpManager.Update(Context.Guild, Context.User, -xp + ownXp); } if (xp < 1) { await ReplyAsync( $"{Helper.GetName(Context.User)} drained {Helper.GetName(user)} {-xp} {GetNameForXp()}! :money_with_wings:"); } else { await ReplyAsync( $"{Helper.GetName(Context.User)} gave {Helper.GetName(user)} {xp} {GetNameForXp()}! :money_with_wings:"); } if (lvlAfter > lvlBefore) { await ReplyAsync($":tada: {Helper.GetName(user)} was promoted to level {lvlAfter}! :tada:"); } ConsoleHelper.Log($"{Helper.GetName(Context.User)} gave {Helper.GetName(user)} {xp}XP!", LogSeverity.Info); } else { await ReplyAsync( $"You can't give {xp} XP to {Helper.GetName(user)}, you only have {userxp.Xp} XP!"); } } catch (Exception ex) { ConsoleHelper.Log($"Could not give XP to {Helper.GetName(user)}! ({ex.Message})", LogSeverity.Error); await ReplyAsync("Whoops, I couldn't give XP to that user!"); } }