// Message was edited private async Task OnMessageUpated(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channelArg) { var message = after as SocketUserMessage; if (message == null || after.Author.Username == _client.CurrentUser.Username && after.Author.Discriminator == _client.CurrentUser.Discriminator) { return; } var channel = channelArg as SocketGuildChannel; if (channel != null) // Not a DM { var server = await _servers.GetServer(channel.Guild); await ServerHelper.CheckForServerInvites(after as SocketUserMessage, server); if (server != null && server.ProfanityFilterMode != ProfanityFilterMode.FilterOff) { await ProfanityHelper.HandleProfanity(message, server, _apiService); } } }
// Message was received private async Task OnMessageReceived(SocketMessage messageParam) { if (messageParam.Author.Username == _client.CurrentUser.Username && messageParam.Author.Discriminator == _client.CurrentUser.Discriminator) { return; } var message = messageParam as SocketUserMessage; if (message == null) { _logger.LogDebug("message was null"); return; } var channel = message.Channel as SocketGuildChannel; var prefix = String.Empty; if (channel != null) // Not a DM { prefix = await _servers.GetGuildPrefix(channel.Guild.Id); if (prefix == null) { prefix = _settings.DefaultPrefix; } var server = await _servers.GetServer(channel.Guild); await ServerHelper.CheckForServerInvites(message, server); if (server != null && server.ProfanityFilterMode != ProfanityFilterMode.FilterOff) { await ProfanityHelper.HandleProfanity(message, server, _apiService); } } var context = new SocketCommandContext(_client, message); int position = 0; if (message.HasStringPrefix(prefix, ref position) || message.HasMentionPrefix(_client.CurrentUser, ref position)) { if (message.Content.StartsWith("!d ")) { // Ignore Disboard bumps return; } _logger.LogInformation("Command received: {command}", message.Content); if (message.Author.IsBot) { _logger.LogDebug("Command ({command}) was sent by another bot, ignoring", message.Content); return; } await _commands.ExecuteAsync(context, position, _serviceProvider); } }
// The remainder attribute parses until the end of a command public async Task Echo([Remainder][Summary("The text to echo")] string message) { await Context.Channel.TriggerTypingAsync(); _logger.LogInformation("{username}#{discriminator} executed echo {message} on {server}/{channel}", Context.User.Username, Context.User.Discriminator, message, Context.Guild?.Name ?? "DM", Context.Channel.Name); var server = await _servers.GetServer(Context.Guild); var checkString = message.Replace(".", String.Empty).Replace('!', 'i').Replace("-", String.Empty).Replace("*", String.Empty); var filter = ProfanityHelper.GetProfanityFilterForServer(server); var badWords = await ProfanityHelper.GetProfanity(server, checkString); if (badWords.Count > 0) { await ReplyAsync("I'm not going to say that!"); return; } await ReplyAsync($"`{message}`"); }