public static async Task HandleEditedCommand(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
        {
            if (!arg1.HasValue || arg1.Value.Content == arg2.Content)
            {
                return;
            }

            if (Core.GlobalConfig.DefaultExecuteEdits)
            {
                MessageEventHandler.MessageRecieved(arg2, edited: true);
            }

            var guildConfig = Core.GetGuildConfig(arg2.GetGuild().Id);

            if (guildConfig.LoggingChannelId != 0 && !guildConfig.MessageLoggingIgnoreChannels.Contains(arg2.Channel.Id) &&
                arg1.HasValue)
            {
                EmbedBuilder log = new EmbedBuilder()
                                   .WithTitle("Message Edited")
                                   .WithColor(243, 110, 33)
                                   .WithCurrentTimestamp();

                if (string.IsNullOrEmpty(arg2.Author.GetAvatarUrl()))
                {
                    log = log.WithAuthor(new EmbedAuthorBuilder().WithName($"{arg2.Author} ({arg2.Author.Id})"));
                }
                else
                {
                    log = log.WithAuthor(new EmbedAuthorBuilder().WithName($"{arg2.Author} ({arg2.Author.Id})")
                                         .WithIconUrl(arg2.Author.GetAvatarUrl() + " "));
                }

                log.AddField(new EmbedFieldBuilder().WithName("Channel").WithValue("#" + arg2.Channel.Name).WithIsInline(true));
                log.AddField(new EmbedFieldBuilder().WithName("Sent At").WithValue(arg1.Value.Timestamp.ToString(@"yyyy-MM-dd HH:mm.ss") + "GMT").WithIsInline(true));

                log.AddField(new EmbedFieldBuilder().WithName("Before").WithValue(arg1.Value.Content.SafeSubstring(1016)));
                log.AddField(new EmbedFieldBuilder().WithName("After").WithValue(arg2.Content.SafeSubstring(1016)));

                await arg2.GetGuild().GetTextChannel(guildConfig.LoggingChannelId).SendMessageAsync("", embed: log.Build());
            }
            if (guildConfig.WordBlacklistEnabled)
            {
                //delete messages edited with blacklisted words (after logging the edit)
                try
                {
                    var wordBlacklist = Core.GetWordBlacklist(arg2.GetGuild().Id);
                    //remove non-alphanumeric characters and convert to lowercase before filtering
                    var messageWords = Regex.Replace(arg2.Content.ToLower(), "[^\\w\\s\\-]", "").Trim().Split();
                    foreach (BlacklistedWord word in wordBlacklist)
                    {
                        if (messageWords.Contains(word.Word))
                        {
                            arg2.DeleteAsync();
                            return;
                        }
                    }
                }
                catch { }
            }
        }
Example #2
0
        private async Task HandleEditedCommand(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
        {
            if (arg1.Value.Content == arg2.Content)
            {
                return;
            }

            if (GenericBot.GlobalConfiguration.DefaultExecuteEdits)
            {
                await MessageEventHandler.MessageRecieved(arg2, edited : true);
            }

            var guildConfig = GenericBot.GuildConfigs[arg2.GetGuild().Id];

            if (guildConfig.UserLogChannelId == 0 || guildConfig.MessageLoggingIgnoreChannels.Contains(arg2.Channel.Id) ||
                !arg1.HasValue)
            {
                return;
            }

            EmbedBuilder log = new EmbedBuilder()
                               .WithTitle("Message Edited")
                               .WithColor(243, 110, 33)
                               .WithCurrentTimestamp();

            if (string.IsNullOrEmpty(arg2.Author.GetAvatarUrl()))
            {
                log = log.WithAuthor(new EmbedAuthorBuilder().WithName($"{arg2.Author} ({arg2.Author.Id})"));
            }
            else
            {
                log = log.WithAuthor(new EmbedAuthorBuilder().WithName($"{arg2.Author} ({arg2.Author.Id})")
                                     .WithIconUrl(arg2.Author.GetAvatarUrl() + " "));
            }

            log.AddField(new EmbedFieldBuilder().WithName("Channel").WithValue("#" + arg2.Channel.Name).WithIsInline(true));
            log.AddField(new EmbedFieldBuilder().WithName("Sent At").WithValue(arg1.Value.Timestamp.ToString(@"yyyy-MM-dd HH:mm.ss") + "GMT").WithIsInline(true));

            log.AddField(new EmbedFieldBuilder().WithName("Before").WithValue(arg1.Value.Content.SafeSubstring(1016)));
            log.AddField(new EmbedFieldBuilder().WithName("After").WithValue(arg2.Content.SafeSubstring(1016)));

            await arg2.GetGuild().GetTextChannel(guildConfig.UserLogChannelId).SendMessageAsync("", embed: log.Build());
        }
Example #3
0
 public static async Task MessageRecieved(SocketMessage arg)
 {
     MessageEventHandler.MessageRecieved(arg, false);
 }
Example #4
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        public static async Task MessageRecieved(SocketMessage msg)
        {
            Task.Run(() => MessageEventHandler.MessageRecieved(msg));
        }