Esempio n. 1
0
        public async Task CheckReaction(Cacheable <IUserMessage, ulong> cachedMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try {
                if ((reaction.User.IsSpecified && reaction.User.Value.IsBot) || !(channel is SocketGuildChannel))
                {
                    return; //Makes sure it's not logging a message from a bot and that it's in a discord server
                }
                var message              = cachedMessage.GetOrDownloadAsync().Result;
                SocketGuildChannel chnl  = channel as SocketGuildChannel;
                SocketGuild        guild = chnl?.Guild;
                if (guild == null)
                {
                    return;
                }

                ModerationSettings settings = guild.LoadFromFile <ModerationSettings>(false);
                SocketGuildUser    gUser    = guild.GetUser(reaction.UserId);
                var Guild = chnl.Guild;
                if (settings?.badUEmojis.IsNullOrEmpty() ?? true || (reaction.User.Value as SocketGuildUser).CantBeWarned() || reaction.User.Value.IsBot)
                {
                    return;
                }
                if (settings.badUEmojis.Select(emoji => new Emoji(emoji)).Contains(reaction.Emote))
                {
                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    await((SocketGuildUser)reaction.User.Value).Warn(1, "Bad reaction used", channel as SocketTextChannel);
                    IUserMessage warnMessage = await channel.SendMessageAsync(
                        $"{reaction.User.Value.Mention} has been given their {(reaction.User.Value as SocketGuildUser).LoadInfractions().Count.Suffix()} infraction because of bad reaction used");
                }
            } catch (Exception e) {
                await new LogMessage(LogSeverity.Error, "Filter", "Something went wrong with the reaction filter", e).Log();
            }
        }
Esempio n. 2
0
        async Task LogEdit(Cacheable <IMessage, ulong> cachedMessage, SocketMessage newMessage, ISocketMessageChannel channel)
        {
            try {
                //Just makes sure that it's not logged when it shouldn't be
                if (!(channel is SocketGuildChannel))
                {
                    return;
                }
                SocketGuild guild      = (channel as SocketGuildChannel).Guild;
                IMessage    oldMessage = cachedMessage.GetOrDownloadAsync().Result;
                if (oldMessage.Content == newMessage.Content || newMessage.Author.IsBot || guild == null)
                {
                    return;
                }
                LogSettings settings = guild.LoadFromFile <LogSettings>();
                if (settings == null || !settings.logEdits)
                {
                    return;
                }
                SocketTextChannel logChannel = guild.GetChannel(settings.logChannel) as SocketTextChannel;
                if (logChannel == null)
                {
                    return;
                }

                var embed = new EmbedBuilder();
                if (oldMessage.Content == null || oldMessage.Content == "")
                {
                    embed.AddField($"Message was edited in #{newMessage.Channel.Name} from",
                                   "`This message had no text`");
                }
                else
                {
                    embed.AddField($"Message was edited in #{newMessage.Channel.Name} from",
                                   oldMessage.Content.Truncate(1020));
                }
                if (newMessage.Content == null || newMessage.Content == "")
                {
                    embed.AddField($"Message was edited in #{newMessage.Channel.Name} to",
                                   "`This message had no text`");
                }
                else
                {
                    embed.AddField($"Message was edited in #{newMessage.Channel.Name} to",
                                   newMessage.Content.Truncate(1020));
                }

                embed.AddField("Message Link", "[Click Here](" + newMessage.GetJumpUrl() + ")", false);

                embed.WithFooter("ID: " + newMessage.Id)
                .WithAuthor(newMessage.Author)
                .WithColor(Color.Teal)
                .WithCurrentTimestamp();

                logChannel.SendMessageAsync(embed: embed.Build()).Result.GetJumpUrl();
            } catch (Exception exception) {
                _ = new LogMessage(LogSeverity.Error, "Logging", exception.Message, exception).Log();
            }
        }
Esempio n. 3
0
        public async Task CheckReaction(Cacheable <IUserMessage, ulong> cachedMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if ((reaction.User.IsSpecified && reaction.User.Value.IsBot) || !(channel is IGuildChannel))
            {
                return; //Makes sure it's not logging a message from a bot and that it's in a discord server
            }
            SocketGuildChannel chnl  = channel as SocketGuildChannel;
            SocketGuild        guild = chnl?.Guild;

            if (guild == null)
            {
                return;
            }
            try
            {
                //Needed to do our own get instead of cachedMessage.GetOrDownloadAsync() because this can be ISystenMessage and not just IUserMessage
                IMessage message = await channel.GetMessageAsync(cachedMessage.Id);

                ReactionContext context  = new ReactionContext(client, message);
                var             settings = guild.LoadFromFile <FilterSettings>(false);
                SocketGuildUser gUser    = guild.GetUser(reaction.UserId);
                if (settings?.badUEmojis?.Count == null || settings.badUEmojis.Count == 0 || (reaction.User.Value as SocketGuildUser).HasAdmin() || reaction.User.Value.IsBot)
                {
                    return;
                }
                if (settings.badUEmojis.Contains(reaction.Emote.Name))
                {
                    await message.RemoveAllReactionsForEmoteAsync(reaction.Emote);

                    await context.FilterPunish(gUser, $"bad reaction used ({reaction.Emote.Name})", guild.LoadFromFile <ModerationSettings>(), settings, null, delete : false, warnSize : 1);
                }
            }
            catch (Exception e)
            {
                await e.LogFilterError("reaction", guild);
            }
        }
Esempio n. 4
0
        public static string LogMessage(string reason, IMessage message, SocketGuild guild = null, bool addJumpLink = false)
        {
            try {
                if (message == null)
                {
                    return(null);
                }
                if (deletedMessagesCache?.Contains(message.Id) ?? false)
                {
                    return(null);
                }

                if (guild == null)
                {
                    guild = Utilities.GetGuild(message.Channel as SocketGuildChannel);
                    if (guild == null)
                    {
                        return(null);
                    }
                }

                LogSettings        settings = guild?.LoadFromFile <LogSettings>();
                SocketGuildChannel gChannel = guild?.GetChannel(settings?.logChannel ?? 0);
                if (settings == null || gChannel == null || !settings.logDeletes)
                {
                    return(null);
                }
                SocketTextChannel logChannel = gChannel as SocketTextChannel;

                var embed = new EmbedBuilder();
                SocketTextChannel channel = message.Channel as SocketTextChannel;
                if (message.Content == null || message.Content == "")
                {
                    embed.AddField(reason + " in #" + message.Channel.Name,
                                   "`This message had no text`", true);
                }
                else
                {
                    embed.AddField(reason + " in #" + message.Channel.Name,
                                   message.Content.Truncate(1020), true);
                }

                if (addJumpLink)
                {
                    embed.AddField("Message Link", "[Click Here](" + message.GetJumpUrl() + ")", true);
                }

                string links = "";
                if (message.Attachments.NotEmpty())
                {
                    foreach (IAttachment attachment in message.Attachments)
                    {
                        links += " " + attachment.ProxyUrl;
                    }
                }

                embed.WithFooter("ID: " + message.Id)
                .WithAuthor(message.Author)
                .WithColor(Color.Blue)
                .WithCurrentTimestamp();
                string link = logChannel.SendMessageAsync(embed: embed.Build()).Result.GetJumpUrl();
                if (!links.IsNullOrEmpty())
                {
                    logChannel.SendMessageAsync("The message above had these attachments:" + links);
                }
                return(link);
            } catch (Exception exception) {
                _ = new LogMessage(LogSeverity.Error, "Logging", exception.Message, exception).Log();
            }
            return(null);
        }