public static async Task HandleHoundCIMessages(SocketUserMessage message, SocketCommandContext context, SocketGuildChannel channel) { if (null == channel || channel.Name != "github" || message.Embeds.Count <= 0) { return; } bool purgeHoundBotMsgs = AppSettingsUtil.AppSettingsBool("deleteHoundBotMsgs", false, false); if (!purgeHoundBotMsgs) { return; } // #github channel contains messages from many different sources. // check if the sender is 'houndci-bot' before deleting. foreach (Embed e in message.Embeds) { EmbedAuthor author = (EmbedAuthor)e.Author; if (author.ToString() == "houndci-bot") { //logger.InfoFormat("Deleting the houndci-bot message: {0} => {1}: {2}", // e.Url, e.Title, e.Description); await context.Message.DeleteAsync(); } } }
private async Task HandleCommandAsync(SocketMessage arg) { try { var message = arg as SocketUserMessage; // Create a Command Context. var context = new SocketCommandContext(_client, message); var channel = message.Channel as SocketGuildChannel; // Debug - Used in development only Add this to App.config under AppSettings to use it: // <add key="development" value="true" /> bool development = AppSettingsUtil.AppSettingsBool("development", false, false); if (development) { logger.Debug("Author ID: " + message.Author.Id); logger.Debug("Channel: " + channel); logger.Debug("Content: " + message.Content); foreach (Embed embed in message.Embeds) { logger.Debug("Embed item (Author): " + embed.Author); logger.Debug("Embed item (Description): " + embed.Description); logger.Debug("Embed item (Image): " + embed.Image); logger.Debug("Embed item (Title): " + embed.Title); logger.Debug("Embed item (Url): " + embed.Url); } foreach (IMentionable user in message.MentionedUsers) { logger.Debug("Mentioned user: "******"Mentioned role: " + role); } foreach (IMentionable mentionedchannel in message.MentionedChannels) { logger.Debug("Mentioned channel: " + mentionedchannel); } logger.Debug(""); // Blank line for seperation } // filter bot messages from infrastructure channels await Helper.FilterBotMessages(message, context, channel); // process subscriptions await Helper.ProcessSubscriptions(message, context, channel); // We don't want the bot to respond to itself or other bots. if (message.Author.Id == _client.CurrentUser.Id || message.Author.IsBot) { return; } // check if the user was in "away" mode. if it is, the user is no longer "away" AFKManager.TheAFKManager.RemoveAFKUserById(context.User.Id); // Block/Remove messages that contain harmful links await Helper.CheckBlockedDomains(message.Content, context); // YAML verification await Helper.ReactToYaml(message.Content, context); // JSON verification await Helper.ReactToJson(message.Content, context); // Line limit check await HandleLineCount(message, context); // handle mentioned users string mentionedUsers = await HandleMentionedUsers(message); // Create a number to track where the prefix ends and the command begins int pos = 0; if (!(message.HasCharPrefix(PREFIX_1, ref pos) || message.HasCharPrefix(PREFIX_2, ref pos) || message.HasMentionPrefix(_client.CurrentUser, ref pos))) { return; } var result = await _commands.ExecuteAsync(context, pos, _services); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { logger.Error(result.ErrorReason); return; } // if you are here, it means there is no module that could handle the message/command // lets check if we have anything in the custom commands collection string key = message.Content.Substring(1); string command = key.Split(' ')[0]; // handle custom command await HandleCustomCommand(command, context, mentionedUsers, result); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }