/// <summary> /// /// </summary> /// <param name="cookieWinner"></param> public async void CookiePickedUp(CookieUser cookieWinner) { cookieDropped = false; try { await channel.SendMessageAsync("@" + cookieWinner.userName + " just got a cookie!"); } catch { Console.WriteLine("COULD NOT SEND MESSAGE"); } cookieWinner.cookies++; await Task.Delay(5000); foreach (SocketMessage msg in userResponses) { if (msg.Content.ToLower() == "pick" || msg.Content.ToLower() == commandPrefix + "stats") { try { await msg.DeleteAsync(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } else { return; } } foreach (SocketMessage msg in botMessages) { // We check to see if this is a cookie message. WE don't want to delete stat related ones. if (msg.Content.Contains(" just got a cookie!")) { try { await msg.DeleteAsync(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } }
private void Update(Object source, ElapsedEventArgs e) { foreach (SocketGuild guild in _client.Guilds) { foreach (SocketUser user in guild.Users) { UserData.CookieUser cookieUser = FindCookieUser(user.Username + "#" + user.Discriminator); if (user.Game.HasValue) { if (user.Game.Value.Name == "Spotify") { cookieUser.spotifyTime++; return; } UserData.GameTime targetGameTime = null; try { targetGameTime = cookieUser.allGames.FirstOrDefault(game => game.applicationName == user.Game.Value.Name); } catch (Exception exception) { Console.WriteLine(exception); } // If we found the game, we can make the change we want to, if not we create a if (targetGameTime != null) { targetGameTime.timeSpentInSeconds++; } else { cookieUser.allGames.Add(new UserData.GameTime { applicationName = user.Game.Value.Name, timeSpentInSeconds = 1 }); } } } } }
private UserData.CookieUser FindCookieUser(string userReference) { if (cookieMonsterData.users.Count > 0) { foreach (UserData.CookieUser userInList in cookieMonsterData.users) { if (userInList.userName == userReference) { return(userInList); } } } UserData.CookieUser newUser = new UserData.CookieUser { userName = userReference, cookies = 0 }; cookieMonsterData.users.Add(newUser); return(newUser); }
/// <summary> /// If we recieve a message in any chat, this task is called. /// </summary> /// <param name="message"> Message sent, along with other critical information </param> /// <returns> null </returns> private async Task MessageReceived(SocketMessage message) { UserData.CookieUser activeUser = FindCookieUser(message.Author.Username + "#" + message.Author.Discriminator); UserData.CookieChannel activeChannel = FindCookieChannel(message.Channel); #region Cookie Logic // First we make sure we ignore bots, as we don't want them triggering the code. No cookies for the cookie monster! if (!message.Author.IsBot) { string lowercaseMessage = message.Content.ToLower(); // We check if we should attempt a cookie drop if (!activeChannel.cookieDropped == true && lowercaseMessage != "pick") { activeChannel.CookieDropCheck(); } // Here we check for commands! switch (lowercaseMessage) { case "pick": if (activeChannel.cookieDropped) { // We add the message to our 'to delete' messages for this channel. activeChannel.userResponses.Add(message); activeChannel.CookiePickedUp(activeUser); } break; case "-stats": EmbedBuilder stats = new EmbedBuilder(); stats.WithTitle(activeUser.userName); stats.WithThumbnailUrl(message.Author.GetAvatarUrl()); stats.WithDescription(":cookie: Cookies: " + activeUser.cookies + " \n:musical_note: Spotify Time: " + UserData.Utility.SecondsToString(activeUser.spotifyTime)); stats.WithColor(accentColor); // We order our games first, so they display in the correct order. List <UserData.GameTime> games = activeUser.allGames; games = games.OrderByDescending(g => g.timeSpentInSeconds).ToList(); // We check to see if we need to display all of the games in this persons storage. if (games.Count > 0) { int gameCount = games.Count; if (gameCount > config.totalGamesToDisplay) { gameCount = config.totalGamesToDisplay; } if (config.displayAllGames) { foreach (UserData.GameTime game in games) { stats.AddInlineField(game.applicationName, UserData.Utility.SecondsToString(game.timeSpentInSeconds)); } } else { for (int i = 0; i < gameCount; i++) { UserData.GameTime game = games[i]; stats.AddInlineField(game.applicationName, UserData.Utility.SecondsToString(game.timeSpentInSeconds)); } } } stats.WithFooter("Cookie Monster", config.botPictureURL); stats.WithCurrentTimestamp(); await message.Channel.SendMessageAsync("", false, stats); break; } } else { // We search through each of our active cookie channels... foreach (UserData.CookieChannel channelToCheck in cookieMonsterData.activeChannels) { // First we check to see if this channel has been created as a cookie channel. if (channelToCheck.channel == message.Channel) { // If it has, then we need to check if the bot is the correct one. if (message.Author.Id == config.botID) { channelToCheck.botMessages.Add(message); } } } } #endregion }