public async Task ResetLeaderboard(SocketGuildUser user) { if (user.Hierarchy >= (Context.User as SocketGuildUser).Hierarchy) { if (user.Id != Context.User.Id) { await ReplyAsync("You cannot reset the level of a user with higher permissions than you."); return; } } var levelUser = LevelService.GetLevelUser(Context.Guild.Id, user.Id); if (levelUser.Item1 != null) { var profile = levelUser.Item1; profile.UserLevel = 0; profile.UserXP = 0; LevelService.Database.Store(profile, LevelUser.DocumentName(profile.UserId, profile.GuildId)); await ReplyAsync("User has been reset."); } else { await ReplyAsync("User does not exist in the level database."); } }
public async Task Mine(int amount = 1) { if (amount >= 0 && amount <= 10) { EmbedBuilder embed = new EmbedBuilder { Color = Color.Green }; LevelUser user = new LevelUser(); user.Load(Context.User.Id); Random rand = new Random(); string path = Program.levelpath + Context.User.Id + ".xml"; user.GainXpMine(embed, Context.User); user.Save(Context.User.Id); await ReplyAsync("", false, Ranking.Miner(embed, path, Context.User.Id.ToString(), amount, Program.mineinv).Build()); if (File.Exists($"./{Context.User.Id}.png")) { File.Delete($"./{Context.User.Id}.png"); } } else { await ReplyAsync("Sorry but I can't pick that much stuf"); } }
public async Task Roll(int max, int guess, double bid, int times = 1) { LevelUser user = new LevelUser(); user.Load(Context.User.Id); if (times > 10) { await ReplyAsync("I can't handle that many times"); } else if (max <= 1) { await ReplyAsync("I won't allowe you to do that"); } else if (guess < 1 || guess > max) { await ReplyAsync($"the number you guessed isn't even betwean 1-{max}"); } else if (user.Credits < bid * double.Parse(times.ToString())) { await ReplyAsync("you don't even have that much credits"); } else { await ReplyAsync("", false, Gamble.Roll(Context.User, max, guess, bid, times).Build()); } }
public static EmbedBuilder Roll(IUser id, int max, int guess, double bid, int times) { EmbedBuilder builder = new EmbedBuilder { Color = Color.Teal }; LevelUser user = new LevelUser(); user.Load(id.Id); Random rand = new Random(); //var list = new List<int>(); for (int i = 0; i < times; i++) { int number = rand.Next(1, max + 1); //list.Add(number); if (number == guess) { double bonus = (1.0 + (double.Parse(max.ToString()) - 1.0) / 10.0); user.Credits += (double.Parse(bid.ToString()) * bonus * user.CreditMultiplier); builder.AddField("You win", $"You were right is was {guess}\n" + $"here you have your �{double.Parse(bid.ToString()) * bonus * user.CreditMultiplier} credits *I added a little bonus for you*"); } else { user.Credits -= bid; builder.AddField("You lose", $"The number was {number} not {guess} dummy"); } } user.Save(id.Id); return(builder); }
public async Task Prestige() { LevelUser user = new LevelUser(); user.Load(Context.User.Id); await ReplyAsync(user.PrestigeUser()); }
public async Task Daily() { LevelUser user = new LevelUser(); user.Load(Context.User.Id); await ReplyAsync(user.Daily()); user.Save(Context.User.Id); }
public async Task LevelUpUser() { LevelUser user = new LevelUser(); user.Load(Context.User.Id); user.LevelUpUser(Context.User); user.Save(Context.User.Id); await ReplyAsync("succes!"); }
public async Task UpgradeUser(string type = "") { LevelUser user = new LevelUser(); user.Load(Context.User.Id); await ReplyAsync("", false, BattleSystem.Upgrade(type, user).Build()); user.Save(Context.User.Id); }
public async Task Join(double bid, int racer) { LevelUser user = new LevelUser(); user.Load(Context.User.Id); if (user.Credits < bid) { await ReplyAsync("you don't even have that much credits"); } else { await ReplyAsync(Races.JoinRace(Context.Guild.Id.ToString(), Context.User.Id.ToString(), bid, racer)); } }
public async Task Slot(double amount) { LevelUser user = new LevelUser(); user.Load(Context.User.Id); if (user.Credits < amount) { await ReplyAsync("you don't even have that many credits"); } else { await ReplyAsync("", false, Gamble.Slot(user, amount)); user.Save(Context.User.Id); } }
public async Task LevelUpUser(IUser getuser = null) { if (getuser == null) { LevelUser user = new LevelUser(); user.Load(Context.User.Id); user.GainXpUser(Context, (user.NeedXp - user.CurrentXp)); user.Save(Context.User.Id); await ReplyAsync("succes!"); } else { LevelUser user = new LevelUser(); user.Load(getuser.Id); user.GainXpUser(Context, getuser, (user.NeedXp - user.CurrentXp)); user.Save(getuser.Id); await ReplyAsync("succes!"); } }
public async Task Pick(int amount = 1) { if (amount >= 1 && amount <= 100) { EmbedBuilder embed = new EmbedBuilder { Color = Color.Green }; LevelUser user = new LevelUser(); user.Load(Context.User.Id); Random rand = new Random(); string path = Program.levelpath + Context.User.Id + ".xml"; user.GainXpPick(embed, Context.User); user.Save(Context.User.Id); await ReplyAsync("", false, Ranking.Picker(embed, path, Context.User.Id.ToString(), amount, Program.baginv).Build()); } else { await ReplyAsync("Sorry but I can't pick that much stuf"); } }
public async Task ResetLeaderboard(string confirm = null) { if (confirm == null) { await ReplyAsync("Run this command again with the confirmation code `cop432ih`\n" + "This will remove all earned xp from users and **CANNOT** be undone\n" + "NOTE: It will not remove earned roles from users."); return; } else if (!confirm.Equals("cop432ih")) { await ReplyAsync("Invalid confirmation code."); return; } var users = LevelService.Database.Query <LevelUser>().Where(x => x.GuildId == Context.Guild.Id).ToList(); LevelService.Database.RemoveMany <LevelUser>(users.Select(x => LevelUser.DocumentName(x.UserId, x.GuildId)).ToList()); await ReplyAsync("Leaderboard has been reset."); }
public Tuple <LevelUser, LevelConfig> GetLevelUser(ulong guildId, ulong userId) { var config = TryGetLevelConfig(guildId); if (config == null) { return(null); } if (config.Enabled) { var user = Database.Load <LevelUser>(LevelUser.DocumentName(userId, guildId)); if (user == null) { user = new LevelUser(userId, guildId); Database.Store(user, LevelUser.DocumentName(userId, guildId)); } return(new Tuple <LevelUser, LevelConfig>(user, config)); } return(null); }
public async Task Give(IUser user, double amount) { if (Context.User == user) { await ReplyAsync("You have it already"); } else { LevelUser user1 = new LevelUser(); LevelUser user2 = new LevelUser(); user1.Load(Context.User.Id); user2.Load(user.Id); var UserList = new List <IUser> { await Context.Client.GetUserAsync(user1.DcUserId), await Context.Client.GetUserAsync(user2.DcUserId) }; await ReplyAsync("", false, user1.Give(user2, amount, UserList).Build()); user1.Save(user1.DcUserId); user2.Save(user2.DcUserId); } }
public async Task LevelEvent(SocketMessage msg) { if (!(msg is SocketUserMessage message)) { return; } if (message.Author.IsBot || message.Author.IsWebhook) { return; } if (!(message.Channel is SocketTextChannel tChannel)) { return; } if (tChannel.Guild == null) { return; } if (!LocalManagementService.LastConfig.IsAcceptable(tChannel.Guild.Id)) { return; } if (UsersUpdated.TryGetValue(tChannel.Guild.Id, out var userList)) { if (userList.Contains(message.Author.Id)) { return; } else { userList.Add(message.Author.Id); } } else { UsersUpdated.TryAdd(tChannel.Guild.Id, new List <ulong> { message.Author.Id }); } var _ = Task.Run(async() => { try { var config = GetLevelUser(tChannel.Guild.Id, message.Author.Id); if (config == null) { return; } var user = config.Item1; var guild = config.Item2; if (guild.RestrictionMode != LevelConfig.LevelRestrictionType.None) { //Ensure that there are restricted channels enabled if (guild.RestrictedChannels.Any()) { if (guild.RestrictionMode == LevelConfig.LevelRestrictionType.Blacklist) { if (guild.RestrictedChannels.Contains(tChannel.Id)) { return; } } else if (guild.RestrictionMode == LevelConfig.LevelRestrictionType.Whitelist) { if (guild.RestrictedChannels.Contains(tChannel.Id)) { return; } } } } user.UserXP += 10; var requiredXP = RequiredExp(user.UserLevel); if (user.UserXP >= requiredXP) { user.UserLevel++; Database.Store(user, LevelUser.DocumentName(user.UserId, user.GuildId)); if (guild.RewardRoles.Any()) { var roles = GetRoles(user.UserLevel, guild, tChannel.Guild); var gUser = tChannel.Guild.GetUser(message.Author.Id); if (config.Item2.MultiRole) { await gUser?.AddRolesAsync(roles.Select(x => x.Item2).ToArray()); } else { var maxRole = roles.MaxBy(x => x.Item1.LevelRequirement).First(); await gUser?.RemoveRolesAsync(roles.Where(x => x.Item1.RoleId != maxRole.Item1.RoleId).Select(x => x.Item2).ToArray()); await gUser?.AddRoleAsync(maxRole.Item2); } } var messageContent = $"**{message.Author.Mention} is now level {user.UserLevel}** XP: {user.UserXP} Next Level At {RequiredExp(user.UserLevel)} XP"; if (guild.ReplyLevelUps) { await tChannel.SendMessageAsync(messageContent); } if (guild.LogChannelId != 0) { var logChannel = tChannel.Guild.GetTextChannel(guild.LogChannelId); if (logChannel != null) { await logChannel.SendMessageAsync(messageContent); } } } else { Database.Store(user, LevelUser.DocumentName(user.UserId, user.GuildId)); } } catch { // } }); }
public async Task UserJoinedAsync(SocketGuildUser user) { var _ = Task.Run(async() => { if (!user.Guild.CurrentUser.GuildPermissions.ManageGuild) { return; } var levelConfig = LevelService.TryGetLevelConfig(user.Guild.Id); if (levelConfig == null || !levelConfig.Enabled) { return; } var guildObj = LevelService.Database.Load <LevelInviteTracker>(LevelInviteTracker.DocumentName(user.Guild.Id)); if (guildObj == null || !guildObj.Enabled) { return; } var trackedMatches = new List <TrackedInvite>(); foreach (var invite in await Context.Guild.GetInvitesAsync()) { //Ensure the invite is being tracked if (!guildObj.TrackedInvites.TryGetValue(invite.Code, out var trackedInvite)) { trackedInvite = new TrackedInvite { InviteCode = invite.Code, JoinCount = invite.Uses ?? 0, CreatorId = invite.Inviter.Id }; guildObj.TrackedInvites.Add(invite.Code, trackedInvite); } //Ensure invite uses is specified //Ensure user has not joined the server under any other tracked invite. if (invite.Uses.HasValue && trackedInvite.JoinCount < invite.Uses.Value && !guildObj.TrackedInvites.Any(x => x.Value.TrackedUsers.Contains(user.Id))) { trackedInvite.JoinCount = invite.Uses.Value; trackedInvite.TrackedUsers.Add(user.Id); trackedMatches.Add(trackedInvite); guildObj.TrackedInvites[trackedInvite.InviteCode] = trackedInvite; } } if (trackedMatches.Count > 1 || trackedMatches.Count == 0) { return; } var match = trackedMatches.First(); var inviter = user.Guild.GetUser(match.CreatorId); if (inviter == null) { return; } var levelUser = LevelService.GetLevelUser(user.Guild.Id, match.CreatorId); levelUser.Item1.UserXP += 100; LevelService.Database.Store(levelUser.Item1, LevelUser.DocumentName(levelUser.Item1.UserId, levelUser.Item1.GuildId)); LevelService.Database.Store(guildObj, LevelInviteTracker.DocumentName(user.Guild.Id)); }); }
public static EmbedBuilder Slot(LevelUser user, double amount) { EmbedBuilder builder = new EmbedBuilder(); Random rand = new Random(); int[] y1 = { rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7) }; int[] y2 = { rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7) }; int[] y3 = { rand.Next(1, 7), rand.Next(1, 7), rand.Next(1, 7) }; int[][] array = { y1, y2, y3 }; builder.AddField("Result", "{" + array[0][0] + "} {" + array[0][1] + "} {" + array[0][2] + "}\n" + "{" + array[1][0] + "} {" + array[1][1] + "} {" + array[1][2] + "}\n" + "{" + array[2][0] + "} {" + array[2][1] + "} {" + array[2][2] + "}"); bool win = false; var list = new List <string>(); double total = 0.0; if (array[0][0] == array[0][1] && array[0][0] == array[0][2]) { win = true; double multi = 1.0 + ((double)array[0][0] / 2.0); total += amount * multi * user.CreditMultiplier; list.Add($"You have gained �{amount * multi * user.CreditMultiplier}"); } if (array[1][0] == array[1][1] && array[1][0] == array[1][2]) { win = true; double multi = 1.0 + ((double)array[1][0] / 2.0); total += amount * multi * user.CreditMultiplier; list.Add($"You have gained �{amount * multi * user.CreditMultiplier}"); } if (array[2][0] == array[2][1] && array[2][0] == array[2][2]) { win = true; double multi = 1.0 + ((double)array[2][0] / 2.0); total += amount * multi * user.CreditMultiplier; list.Add($"You have gained �{amount * multi * user.CreditMultiplier}"); } if (array[0][0] == array[1][1] && array[0][0] == array[2][2]) { win = true; double multi = 1.0 + ((double)array[0][0] / 2.0); total += amount * multi * user.CreditMultiplier; list.Add($"You have gained �{amount * multi * user.CreditMultiplier}"); } if (array[2][0] == array[1][1] && array[2][0] == array[0][2]) { win = true; double multi = 1.0 + ((double)array[0][0] / 2.0); total += amount * multi * user.CreditMultiplier; list.Add($"You have gained �{amount * multi * user.CreditMultiplier}"); } if (win) { builder.AddField("Wins", string.Join("\n", list)); builder.AddField("Credits", $"you have gained a total of �{total}"); user.Credits += total; } else { user.Credits -= amount; builder.AddField("Lost", $"You now have �{user.Credits}"); } return(builder); }
private async Task HandleCommandAsync(SocketMessage arg) { string userpath = levelpath + arg.Author.Id + ".xml"; var msg = arg as SocketUserMessage; if (msg == null) { return; } if (msg.Author.Id == _client.CurrentUser.Id || msg.Author.IsBot) { return; } int pos = 0; LevelUser user = new LevelUser(); if (!File.Exists(userpath)) { Console.WriteLine(user.AddNewUserRank(arg.Author.Id.ToString())); } Ranking.CheckUser(userpath, arg.Author.Id.ToString(), mineinv, baginv, craftlist); UserInfo info = new UserInfo(arg.Author.Id); info.AddMessage(); if (msg.HasStringPrefix("%", ref pos) || msg.HasMentionPrefix(_client.CurrentUser, ref pos)) { var context = new SocketCommandContext(_client, msg); GuildChannel guild = new GuildChannel(context.Guild.Id); if (!guild.On || guild.Channels.Contains(arg.Channel.Id) == false || msg.Content == "%disable") { var result = await _commands.ExecuteAsync(context, pos, _services); if (!result.IsSuccess) { Utils.CustomErrors(msg, result, context); } else if (result.IsSuccess) { info.AddCommand(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{DateTime.Now,-19} [{msg.Channel.Name}] [{msg.Author.Id}] Used {msg.ToString()}"); Console.ForegroundColor = ConsoleColor.White; CommandUsed.CommandAdd(); } } else { var message = await context.Channel.GetMessageAsync(msg.Id); await message.DeleteAsync(); CommandUsed.ClearAdd(1); //await msg.Channel.SendMessageAsync("commands can't be used in this channel"); } } if (arg.Author.IsBot && arg.Author.Id != 372615866652557312) { return; } else { try { CommandUsed.GainedMessagesAdd(); Random rand = new Random(); user.Load(arg.Author.Id); int xp = rand.Next(1, 5); CommandUsed.TotalXpAdd(xp); user.GainXpUser(arg, xp); if (File.Exists($"./userimg.png")) { File.Delete($"./userimg.png"); } } catch (Exception ex) { Console.WriteLine($"User:{arg.Author.Id}" + ex.ToString()); } } }
private async Task HandleCommandAsync(SocketMessage arg) { try { if (!(arg is SocketUserMessage msg)) { return; } if (msg.Author.Id == Client.CurrentUser.Id || msg.Author.IsBot) { return; } string prefix = "&"; int pos = prefix.Length - 1; UserInfo info = new UserInfo(arg.Author.Id); info.AddMessage(); var context = new ShardedCommandContext(Client, msg); GuildChannel guild = new GuildChannel(context.Guild); if (msg.HasStringPrefix(prefix, ref pos) || msg.HasMentionPrefix(Client.CurrentUser, ref pos)) { if (!guild.CommandsOn || guild.DisChannelsList.Contains(arg.Channel.Id) == false || msg.Content == $"{prefix}disable") { var result = await Commands.ExecuteAsync(context, pos, Services); if (!result.IsSuccess) { var cmdresult = await CustomCommands.ExecuteCommands(context, pos); if (!cmdresult) { Utils.CustomErrors(msg, result, context); } } else if (result.IsSuccess) { info.AddCommand(); CommandUsed.CommandAdd(); } } else { var message = await context.Channel.GetMessageAsync(msg.Id); await message.DeleteAsync(); CommandUsed.ClearAdd(1); } } if (arg.Author.IsBot && arg.Author.Id != 372615866652557312 || !guild.GainXp) { return; } else { try { LevelUser user = new LevelUser(); CommandUsed.GainedMessagesAdd(); user.Load(arg.Author.Id); int xp = new Random().Next(1, 5); CommandUsed.TotalXpAdd(xp); user.GainXpUser(arg, guild, xp); if (File.Exists($"./userimg.png")) { File.Delete($"./userimg.png"); } } catch (Exception ex) { Console.WriteLine($"User:{arg.Author.Id}" + ex.ToString()); } } try { Games.GetInput(msg.Content.ToLower(), context); } catch (Exception ex) { Console.WriteLine($"User:{arg.Author.Id}: = " + ex.ToString()); } } catch (Exception) { } }
public static EmbedBuilder Upgrade(string type, LevelUser user) { EmbedBuilder builder = new EmbedBuilder(); if (type == "") { builder.AddField("These are the things you can upgrade", "**Damage multi:** damage\n" + "**Health multi:** health\n" + "**Credits multi:** credits"); } else if (type.ToLower() == "damage") { double upnum = 0; if (user.Damagemultiplier == 1.0) { upnum = 0; } else { upnum = (user.Damagemultiplier - 1.0) / 0.05; } if (upnum == 20) { builder.AddField("Can't upgrade that", "You have the highest upgrade available"); } else if (user.Credits < 10000.0 * (upnum + 1.0)) { builder.AddField("You don't have enough credits", $"You need {10000.0 * (upnum + 1.0)} too upgrade this"); } else { user.Credits -= 10000.0 * (upnum + 1.0); user.Damagemultiplier += 0.05; builder.AddField("Upgrade complete", $"You now have a {user.Damagemultiplier}x"); } } else if (type.ToLower() == "health") { double upnum = 0; if (user.Damagemultiplier == 1.0) { upnum = 0; } else { upnum = (user.HealtMultiplier - 1.0) / 0.05; } if (upnum == 20) { builder.AddField("Can't upgrade that", "You have the highest upgrade available"); } else if (user.Credits < 10000.0 * (upnum + 1.0)) { builder.AddField("You don't have enough credits", $"You need {10000.0 * (upnum + 1.0)} too upgrade this"); } else { user.Credits -= 10000.0 * (upnum + 1.0); user.HealtMultiplier += 0.05; builder.AddField("Upgrade complete", $"You now have a {user.HealtMultiplier}x"); } } else if (type.ToLower() == "credits") { double upnum = 0; if (user.Damagemultiplier == 1.0) { upnum = 0; } else { upnum = (user.CreditMultiplier - 1.0) / 0.05; } if (upnum == 20) { builder.AddField("Can't upgrade that", "You have the highest upgrade available"); } else if (user.Credits < 10000.0 * (upnum + 1.0)) { builder.AddField("You don't have enough credits", $"You need {10000.0 * (upnum + 1.0)} too upgrade this"); } else { user.Credits -= 10000.0 * (upnum + 1.0); user.CreditMultiplier += 0.05; builder.AddField("Upgrade complete", $"You now have a {user.CreditMultiplier}x"); } } else { builder.AddField("I have this problem", $"I can't find {type.ToLower()}"); } return(builder); }