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 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 static async void TimerCallback() { await ConsoleHelper.Log($"Giving away XP to everyone...", LogSeverity.Info); foreach (IGuild guild in Cirilla.Client.Guilds) { IEnumerable <IGuildUser> users = await guild.GetUsersAsync(); Random rnd = new Random(); foreach (IUser user in users.Where(u => (!u.IsBot) && (u.Status != UserStatus.Offline))) { //Update all [interval] seconds +3 XP XpManager.Update(user, 0, 3); //1 in [GiveRandomXpChance] chance to give user XP if (rnd.Next(0, Information.GiveRandomXpChance) == 0) { int freeXp = 200, freeReserve = 100; XpManager.Update(user, freeXp, freeReserve); if (await guild.GetChannelAsync(guild.DefaultChannelId) is ITextChannel channel) { await ConsoleHelper.Log($"{user} randomly got {freeXp} free XP (1 in {Information.GiveRandomXpChance} chance)", LogSeverity.Info); await channel.SendMessageAsync($"Lucky you, {user.Mention}! The gods have decided to give you {freeXp} free XP! :moneybag:"); } } } } await ConsoleHelper.Log($"{Information.XpGiveInterval / 1000} Second interval - gave XP to everyone", LogSeverity.Info); }
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!"); } }