private UserData.CookieChannel FindCookieChannel(ISocketMessageChannel channelReference) { if (cookieMonsterData.activeChannels.Count > 0) { foreach (UserData.CookieChannel channelInList in cookieMonsterData.activeChannels) { if (channelInList.channel == channelReference) { return(channelInList); } } } UserData.CookieChannel newChannel = new UserData.CookieChannel { channel = channelReference, cookieSpawnChance = config.cookieDropChance, commandPrefix = config.commandPrefix }; cookieMonsterData.activeChannels.Add(newChannel); return(newChannel); }
/// <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 }