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 }); } } } } }
/// <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 }