Esempio n. 1
0
        public async Task ToggleLoggingDeleted()
        {
            if (!Utilities.HasAdmin(Context.Message.Author as SocketGuildUser))
            {
                await ReplyAsync("You do not have administrator access");

                return;
            }
            IUserMessage message = await ReplyAsync("Setting...");

            ModerationFunctions.CheckDirectories(Context.Guild);
            LogSettings settings = null;

            settings = SettingFunctions.LoadLogSettings(Context.Guild, true);

            settings.logDeletes = !settings.logDeletes;

            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Include;

            settings.SaveLogSettings(Context.Guild);
            if (settings.logDeletes)
            {
                await message.ModifyAsync(msg => msg.Content = "Deleted messages will now be logged in the logging channel");
            }
            else
            {
                await message.ModifyAsync(msg => msg.Content = "Deleted messages won't be logged now");
            }
        }
Esempio n. 2
0
        public async Task SetLogChannel()
        {
            if (!((SocketGuildUser)Context.User).HasAdmin())
            {
                await ReplyAsync("You do not have administrator access");

                return;
            }
            IUserMessage message = await ReplyAsync("Setting...");

            ModerationFunctions.CheckDirectories(Context.Guild);
            LogSettings settings = null;

            settings = SettingFunctions.LoadLogSettings(Context.Guild, true);

            if (Context.Client.GetChannel(settings.logChannel) == Context.Channel)
            {
                await ReplyAsync("This channel already is the logging channel");

                return;
            }
            else
            {
                settings.logChannel = Context.Channel.Id;
            }

            settings.SaveLogSettings(Context.Guild);
            await message.ModifyAsync(msg => msg.Content = "Set log channel");
        }
Esempio n. 3
0
        public static void LogDeleted(string reason, IMessage message, SocketGuild guild = null)
        {
            try {
                if (deletedMessagesCache == null)
                {
                    deletedMessagesCache = new List <ulong>();
                }
                if (deletedMessagesCache.Contains(message.Id))
                {
                    return;
                }
                if (deletedMessagesCache.Count == 5)
                {
                    deletedMessagesCache.RemoveAt(4);
                }
                deletedMessagesCache.Insert(0, message.Id);

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

                LogSettings       settings   = SettingFunctions.LoadLogSettings(guild);
                SocketTextChannel logChannel = guild.GetChannel(settings.logChannel) as SocketTextChannel;
                if (settings == null || logChannel == null || !settings.logDeletes)
                {
                    return;
                }

                var embed = new EmbedBuilder();
                SocketTextChannel channel = message.Channel as SocketTextChannel;
                if (message.Embeds.Count == 0)
                {
                    embed.AddField(reason + " in #" + message.Channel.Name,
                                   message.Content, true);
                }
                else
                {
                    embed.AddField(reason + " in #" + channel.Name,
                                   "`Embed cannot be displayed`", true);
                }

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

                _ = logChannel.SendMessageAsync(embed: embed.Build());
            } catch (Exception exception) {
                Console.WriteLine(new LogMessage(LogSeverity.Error, "Logging", "Error: ", exception));
            }
        }
Esempio n. 4
0
        public async Task DebugLogSettings()
        {
            LogSettings settings = SettingFunctions.LoadLogSettings(Context.Guild, false);

            var embed = new EmbedBuilder();

            SocketTextChannel logChannel = Context.Guild.GetTextChannel(settings.logChannel);

            if (logChannel == null)
            {
                _ = ReplyAsync("Logging channel is null");
                return;
            }

            embed.AddField("Log channel", logChannel, true);
            embed.AddField("Log deleted messages", settings.logDeletes, true);
            await ReplyAsync(embed : embed.Build());
        }