// Remove a user from all user pools public static Task RemoveUserAsync(SocketUser User, ulong ChannelId) { // 0 = all channels if (ChannelId == 0) { foreach (KeyValuePair <ulong, List <ulong> > Entry in UserPools) { if (Entry.Value.Contains(User.Id)) { Entry.Value.Remove(User.Id); } } } // Specific channel pool else if (UserPools.ContainsKey(ChannelId)) { if (UserPools[ChannelId].Contains(User.Id)) { UserPools[ChannelId].Remove(User.Id); } } return(Task.CompletedTask); }
// Message received private async Task MessageReceivedAsync(SocketMessage arg) { // Get message and create a context var message = arg as SocketUserMessage; if (message == null) { return; } var context = new SocketCommandContext(_client, message); // Check if channel is a tippable channel if (UserPools.ContainsKey(message.Channel.Id) && !message.Author.IsBot) { // Check for spam await CheckForSpamAsync(message, out bool IsSpam); if (!IsSpam && !UserPools[message.Channel.Id].Contains(message.Author.Id)) { // Add user to tip pool if (logLevel >= 1) { Console.WriteLine("{0} {1} Adding {2} ({3}) to user pool on channel #{4}", DateTime.Now.ToString("HH:mm:ss"), "Tipper", message.Author.Username, message.Author.Id, message.Channel); } UserPools[message.Channel.Id].Add(message.Author.Id); } // Remove users from pool if pool exceeds the threshold if (UserPools[message.Channel.Id].Count > userMax) { UserPools[message.Channel.Id].RemoveAt(0); } } // Check if message is a commmand int argPos = 0; if (message.HasStringPrefix(Constants.BotPrefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) { // Execute command and log errors to console var result = await _commands.ExecuteAsync(context, argPos, _services); if (!result.IsSuccess) { Console.WriteLine(result.ErrorReason); } } }
// Message received private async Task MessageReceivedAsync(SocketMessage arg) { // Get message and create a context var message = arg as SocketUserMessage; if (message == null) { return; } var context = new SocketCommandContext(_client, message); // Check if message is a commmand int argPos = 0; if (message.HasStringPrefix(botPrefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) { // Execute command and log errors to console var result = await _commands.ExecuteAsync(context, argPos, _services); if (!result.IsSuccess) { Log(1, "Error", "Error executing \"{0}\" command sent by {1} ({2}): {3}", message.Content, message.Author, message.Author.Id, result.ErrorReason); } } // Check if channel is a tippable channel else if (UserPools.ContainsKey(message.Channel.Id) && !message.Author.IsBot) { // Check for spam await CheckForSpamAsync(message, out bool IsSpam); if (!IsSpam && !UserPools[message.Channel.Id].Contains(message.Author.Id)) { // Add user to tip pool UserPools[message.Channel.Id].Add(message.Author.Id, timeoutPeriod, delegate(object sender, EventArgs e) { Log(1, "Tipping", "Removed {0} ({1}) from user pool on channel #{2}", message.Author.Username, message.Author.Id, message.Channel); }); Log(1, "Tipping", "Adding {0} ({1}) to user pool on channel #{2}", message.Author.Username, message.Author.Id, message.Channel); } // Remove users from pool if pool exceeds the threshold if (UserPools[message.Channel.Id].Count > userMax) { UserPools[message.Channel.Id].RemoveAt(0); } } }