internal static async Task UserWonBattle(UserAccount userAccount, List <Rewardable> rewards, BattleStats battleStats, ITextChannel lobbyChannel, ITextChannel battleChannel) { uint oldLevel = userAccount.LevelNumber; userAccount.BattleStats += battleStats; var bs = userAccount.BattleStats; _ = UnlockBattleClasses(userAccount, lobbyChannel); var awardStrings = rewards.Select(f => f.Award(userAccount)).Where(s => !s.IsNullOrEmpty()).ToList(); if (awardStrings.Count() > 0) { _ = WriteAndDeleteRewards(awardStrings, battleChannel); } userAccount.ServerStats.ColossoWins++; userAccount.ServerStats.ColossoStreak++; userAccount.ServerStats.ColossoHighestStreak = Math.Max(userAccount.ServerStats.ColossoHighestStreak, userAccount.ServerStats.ColossoStreak); UserAccounts.SaveAccounts(); uint newLevel = userAccount.LevelNumber; if (oldLevel != newLevel) { var user = (SocketGuildUser)await lobbyChannel.GetUserAsync(userAccount.ID); // Where(s => s. == userAccount.ID).First(); Leveling.LevelUp(userAccount, user, (SocketTextChannel)lobbyChannel); } await Task.CompletedTask; }
public async Task <bool> LoadNames(ITextChannel chan) { _currTurn = 0; List <ulong> newPlayers = new List <ulong>(); while (_players.Count > 0) { int randomPlayer = Program.p.rand.Next(0, _players.Count); newPlayers.Add(_players[randomPlayer]); _players.RemoveAt(randomPlayer); } _players = newPlayers; foreach (ulong id in _players) { IGuildUser user = await chan.GetUserAsync(id); if (user == null) { return(false); } _names.Add(user.Nickname ?? user.Username); _fullNames.Add(user.ToString()); } _allNames = new List <string>(_names).ToArray(); return(true); }
async Task reactBlockChannel(ITextChannel channel, Cacheable <IUserMessage, ulong> cacheMsg, SocketReaction reaction) { var message = await cacheMsg.GetOrDownloadAsync(); var user = await channel.GetUserAsync(reaction.UserId); await message.RemoveReactionAsync(reaction.Emote, user); if (user.GuildPermissions.Administrator == false) { await user.SendMessageAsync("You do not have permission to block content for this guild"); return; } SocketGuildUser author = message.Author as SocketGuildUser; int count = ChannelMuteEscalations.GetValueOrDefault(author.Id, 0); int minutes = (int)Math.Pow(5, count); ChannelMuteEscalations[author.Id] = count + 1; var ts = TimeSpan.FromMinutes(minutes); var p = await AddChannelMute(channel, user as SocketGuildUser, author, "Via emoji, none given", ts); await message.DeleteAndTrackAsync($"Channel muted {p.Id}"); await user.SendMessageAsync($"Remove message and denied user permission to talk in {channel.Mention}"); }
internal static async Task UserLostBattle(UserAccount userAccount, ITextChannel battleChannel) { uint oldLevel = userAccount.LevelNumber; userAccount.AddXp((uint)(new Random()).Next(1, 10)); uint newLevel = userAccount.LevelNumber; userAccount.ServerStats.ColossoStreak = 0; UserAccounts.SaveAccounts(); if (oldLevel != newLevel) { var user = (SocketGuildUser)await battleChannel.GetUserAsync(userAccount.ID); // Where(s => s. == userAccount.ID).First(); Leveling.LevelUp(userAccount, user, (SocketTextChannel)battleChannel); } await Task.CompletedTask; }
internal static async Task UserLostBattle(UserAccount userAccount, ITextChannel battleChannel) { var oldLevel = userAccount.LevelNumber; userAccount.AddXp((uint)Global.RandomNumber(1, 10)); var newLevel = userAccount.LevelNumber; userAccount.ServerStats.ColossoStreak = 0; UserAccountProvider.StoreUser(userAccount); if (oldLevel != newLevel) { var user = (SocketGuildUser)await battleChannel.GetUserAsync(userAccount.Id); // Where(s => s. == userAccount.ID).First(); Leveling.LevelUp(userAccount, user, (SocketTextChannel)battleChannel); } await Task.CompletedTask; }
async Task reactBlockImage(ITextChannel channel, Cacheable <IUserMessage, ulong> cacheMessage, SocketReaction reaction) { var message = await cacheMessage.GetOrDownloadAsync(); var user = await channel.GetUserAsync(reaction.UserId); await message.RemoveReactionAsync(reaction.Emote, user); if (user.GuildPermissions.Administrator == false) { await user.SendMessageAsync("You do not have permission to block content for this guild"); return; } if (message.Attachments.Count == 0) { await user.SendMessageAsync("To block text content, you must use a topic block via command."); return; } var attachment = message.Attachments.First(); var path = Path.Combine(Path.GetTempPath(), $"{message.Id}_{attachment.Filename}"); if (File.Exists(path) == false) { using var wc = new WebClient(); wc.DownloadFile(attachment.Url, path); } using var fstream = new FileStream(path, FileMode.Open); var algo = new DifferenceHash(); var hash = algo.Hash(fstream); var p = await AddImageBlock(user as SocketGuildUser, null, "Via emoji, none given", null, hash, guildwide : true); await message.DeleteAndTrackAsync($"Violated image block {p.Id}"); await user.SendMessageAsync($"Added indefinite image block for hash {hash}; id of penalty: {p.Id}"); }
internal static async Task UserWonBattle(UserAccount userAccount, List <Rewardable> rewards, BattleStats battleStats, ITextChannel lobbyChannel, ITextChannel battleChannel, int winsInARow = 1, string nameOfTeamMates = "") { uint oldLevel = userAccount.LevelNumber; userAccount.BattleStats += battleStats; var bs = userAccount.BattleStats; _ = UnlockClasses(userAccount, lobbyChannel); var awardStrings = rewards.Select(f => f.Award(userAccount)).Where(s => s != null).ToList(); if (awardStrings.Count() > 0) { _ = WriteAndDeleteRewards(awardStrings, battleChannel); } userAccount.ServerStats.ColossoWins++; userAccount.ServerStats.ColossoStreak++; userAccount.ServerStats.ColossoHighestStreak = Math.Max(userAccount.ServerStats.ColossoHighestStreak, userAccount.ServerStats.ColossoStreak); switch (battleStats.TotalTeamMates) { case 0: userAccount.ServerStats.ColossoHighestRoundEndlessSolo = Math.Max(userAccount.ServerStats.ColossoHighestRoundEndlessSolo, winsInARow); break; case 1: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessDuo) { userAccount.ServerStats.ColossoHighestRoundEndlessDuo = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessDuoNames = nameOfTeamMates; } break; case 2: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessTrio) { userAccount.ServerStats.ColossoHighestRoundEndlessTrio = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessTrioNames = nameOfTeamMates; } break; case 3: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessQuad) { userAccount.ServerStats.ColossoHighestRoundEndlessQuad = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessQuadNames = nameOfTeamMates; } break; } UserAccounts.SaveAccounts(); uint newLevel = userAccount.LevelNumber; if (oldLevel != newLevel) { var user = (SocketGuildUser)await lobbyChannel.GetUserAsync(userAccount.ID); // Where(s => s. == userAccount.ID).First(); Leveling.LevelUp(userAccount, user, (SocketTextChannel)lobbyChannel); } await Task.CompletedTask; }
internal static async Task UserWonBattle(UserAccount userAccount, int winsInARow, int LureCaps, BattleStats battleStats, BattleDifficulty diff, ITextChannel lobbyChannel, IEnumerable <ColossoFighter> winners, bool wasMimic) { uint oldLevel = userAccount.LevelNumber; var baseXP = 20 + 5 * LureCaps + winsInARow / 4; var xpawarded = (uint)new Random().Next(baseXP, baseXP * 2) * Math.Max(3, (uint)Math.Pow((int)diff + 1, 2)); userAccount.XP += xpawarded; userAccount.Inv.AddBalance(xpawarded / 2); uint newLevel = userAccount.LevelNumber; userAccount.ServerStats.ColossoWins++; userAccount.ServerStats.ColossoStreak++; userAccount.ServerStats.ColossoHighestStreak = Math.Max(userAccount.ServerStats.ColossoHighestStreak, userAccount.ServerStats.ColossoStreak); switch (battleStats.TotalTeamMates) { case 0: userAccount.ServerStats.ColossoHighestRoundEndlessSolo = Math.Max(userAccount.ServerStats.ColossoHighestRoundEndlessSolo, winsInARow); break; case 1: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessDuo) { userAccount.ServerStats.ColossoHighestRoundEndlessDuo = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessDuoNames = string.Join(", ", winners.Select(p => p.Name)); } break; case 2: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessTrio) { userAccount.ServerStats.ColossoHighestRoundEndlessTrio = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessTrioNames = string.Join(", ", winners.Select(p => p.Name)); } break; case 3: if (winsInARow > userAccount.ServerStats.ColossoHighestRoundEndlessQuad) { userAccount.ServerStats.ColossoHighestRoundEndlessQuad = winsInARow; userAccount.ServerStats.ColossoHighestRoundEndlessQuadNames = string.Join(", ", winners.Select(p => p.Name)); } break; } userAccount.BattleStats += battleStats; _ = UnlockClasses(userAccount, lobbyChannel); if (wasMimic || Global.Random.Next(0, 100) <= 7 + battleStats.TotalTeamMates * 2 + 4 * LureCaps + winsInARow / 10 - 1) { ChestQuality awardedChest = GetRandomChest(diff); userAccount.Inv.AwardChest(awardedChest); var embed = new EmbedBuilder(); embed.WithColor(Colors.Get("Iodem")); embed.WithDescription($"{((SocketTextChannel)lobbyChannel).Users.Where(u => u.Id == userAccount.ID).FirstOrDefault().Mention} found a {Inventory.ChestIcons[awardedChest]} {awardedChest} Chest!"); await lobbyChannel.SendMessageAsync("", false, embed.Build()); } UserAccounts.SaveAccounts(); if (oldLevel != newLevel) { var user = (SocketGuildUser)await lobbyChannel.GetUserAsync(userAccount.ID); // Where(s => s. == userAccount.ID).First(); Leveling.LevelUp(userAccount, user, (SocketTextChannel)lobbyChannel); } await Task.CompletedTask; }
public static async void ReminderHandler(IDiscordClient client) { while (true) { List <string> reminders = new List <string>(); int f = 1; do { try { reminders = File.ReadLines(Path.GetFullPath(Resources.reminders, Extensions.config_values.root_path)).ToList(); } catch { f = 0; continue; } } while (f == 0); StringBuilder sb = new StringBuilder(); ITextChannel channel = null; IGuildUser u = null; foreach (var r in reminders) { string[] separators = { ";" }; string[] temp = r.Split(separators, StringSplitOptions.RemoveEmptyEntries); DateTime rd = DateTime.FromBinary(long.Parse(temp[0])); TimeSpan dif = rd - DateTime.Now; TimeSpan check = new TimeSpan(0, 1, 0); try { if (dif <= check) { channel = (ITextChannel)await client.GetChannelAsync(ulong.Parse(temp[3])); ulong uid = ulong.Parse(temp[2]); u = await channel.GetUserAsync(uid); await channel.SendMessageAsync(u.Mention + " " + temp[1]); TimeSpan check2 = new TimeSpan(0, 0, 0); if (dif < check2) { await channel.SendMessageAsync("``Apologies, sir, but this reminder was late by " + TimeToString(dif) + ".``"); } } else { sb.Append(r); sb.AppendLine(); } } catch { continue; } } f = 1; do { try { File.WriteAllText(Path.GetFullPath(Resources.reminders, Extensions.config_values.root_path), sb.ToString()); } catch { f = 0; continue; } } while (f == 0); await Task.Delay(58000); } }