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 RemooveWarnAsync(SocketUser user, int index)
        {
            ModerationFunctions.CheckDirectories(Context.Guild);
            if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id))
            {
                List <Infraction> infractions = ModerationFunctions.LoadInfractions(Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id);

                if (infractions.Count < index || index <= 0)
                {
                    await ReplyAsync("invalid infraction number");
                }
                else if (infractions.Count == 1)
                {
                    await ReplyAsync("removed " + user.Username + "'s warning for " + infractions[index - 1].reason);

                    File.Delete("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id);
                }
                else
                {
                    string reason = infractions[index - 1].reason;
                    infractions.RemoveAt(index - 1);

                    ModerationFunctions.SaveInfractions(Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id, infractions);

                    await ReplyAsync("removed " + user.Mention + "'s warning for " + reason);
                }
            }
            else
            {
                await ReplyAsync(user.Username + " has no warns");
            }
        }
Esempio n. 3
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. 4
0
        public async Task WarnUserSmallSizeAsync(SocketUser user, [Remainder] string reason)
        {
            ModerationFunctions.CheckDirectories(Context.Guild);
            ModerationFunctions.WarnUser(user, 1, reason, Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id);

            await ReplyAsync(user.Username + " has been warned for " + reason);
        }
Esempio n. 5
0
        public async Task ToggleInviteWarn()
        {
            if (!((SocketGuildUser)Context.User).HasAdmin())
            {
                await ReplyAsync("You do have administrator permissions");

                return;
            }

            Console.WriteLine(DateTime.Now.ToShortTimeString() + " Toggling invite warn");

            IUserMessage message = await ReplyAsync("Trying to toggle");

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

            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Include;
            try {
                StreamReader   sr     = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.txt");
                JsonTextReader reader = new JsonTextReader(sr);
                settings = serializer.Deserialize <ModerationSettings>(reader);
            } catch (Exception error) {
                await message.ModifyAsync(msg => msg.Content = "an error has occurred loading settings " + error.Message);

                Console.WriteLine(DateTime.Now.ToShortTimeString() + "an error has occurred loading settings " + error.Message);
            }


            if (settings == null)
            {
                settings = new ModerationSettings();
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " Creating new mod settings");
            }
            settings.invitesAllowed = !settings.invitesAllowed;
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " setting invites to " + settings.invitesAllowed);

            /*using (StreamWriter file = File.CreateText(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.text")) {
             *  JsonSerializer newserializer = new JsonSerializer();
             *  newserializer.Serialize(file, settings);
             * }*/

            using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings.txt"))
                using (JsonTextWriter writer = new JsonTextWriter(sw)) {
                    serializer.Serialize(sw, settings);
                }

            if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/moderationSettings"))
            {
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " mod settings saved");
            }
            else
            {
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " mod settings not found after creation?!");
            }

            await message.ModifyAsync(msg => msg.Content = "set invites allowed to " + settings.invitesAllowed.ToString().ToLower());
        }
Esempio n. 6
0
        public async Task RemoveBadWord(string word)
        {
            if (!((SocketGuildUser)Context.User).HasAdmin())
            {
                await ReplyAsync("You do have administrator permissions");

                return;
            }

            ModerationFunctions.CheckDirectories(Context.Guild);
            List <BadWord> badWords;

            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;

            if (!File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"))
            {
                await ReplyAsync("No bad words file found");

                return;
            }

            using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"))
                using (JsonTextReader reader = new JsonTextReader(sr)) {
                    badWords = serializer.Deserialize <List <BadWord> >(reader);
                }

            if (badWords == null)
            {
                await ReplyAsync("Bad words is null");

                return;
            }
            BadWord badToRemove = null;

            foreach (BadWord badWord in badWords)
            {
                if (badWord.word == word)
                {
                    badToRemove = badWord;
                }
            }
            if (badToRemove != null)
            {
                badWords.Remove(badToRemove);
                using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"))
                    using (JsonTextWriter writer = new JsonTextWriter(sw)) {
                        serializer.Serialize(sw, badWords);
                    }

                await ReplyAsync("removed " + word + " from bad word list");
            }
            else
            {
                await ReplyAsync("Bad word list doesn't contain " + word);
            }
        }
Esempio n. 7
0
        public async Task WarnUserSmallSizeAsync(SocketUser user, [Remainder] string reason)
        {
            if (!((SocketGuildUser)Context.User).CanWarn())
            {
                await ReplyAsync("You do not have permission to use this command");

                return;
            }
            ModerationFunctions.CheckDirectories(Context.Guild);
            ModerationFunctions.WarnUser(user, 1, reason, Context.Guild.OwnerId + "/Infractions/Games/" + user.Id);

            await ReplyAsync(user.Username + " has been warned for " + reason);
        }
Esempio n. 8
0
        public async Task AddBadWord(string word, string euphemism = null, float size = 0.5f)
        {
            if (!((SocketGuildUser)Context.User).HasAdmin())
            {
                await ReplyAsync("You do have administrator permissions");

                return;
            }
            ModerationFunctions.CheckDirectories(Context.Guild);
            BadWord badWord = new BadWord();

            badWord.word      = word;
            badWord.euphemism = euphemism;
            badWord.size      = size;
            List <BadWord> badWords;

            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;

            /*if (!File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json")) {
             *  File.Create("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json");
             * }*/

            using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"))
                using (JsonTextReader reader = new JsonTextReader(sr)) {
                    badWords = serializer.Deserialize <List <BadWord> >(reader);
                }

            if (badWords == null)
            {
                badWords = new List <BadWord>();
            }
            badWords.Add(badWord);

            using (StreamWriter sw = new StreamWriter(@"/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/badwords.json"))
                using (JsonTextWriter writer = new JsonTextWriter(sw)) {
                    serializer.Serialize(sw, badWords);
                }

            if (euphemism != null)
            {
                await ReplyAsync("added " + badWord.word + " also known as " + euphemism + " to bad word list");
            }
            else
            {
                await ReplyAsync("added " + badWord.word + " to bad word list");
            }
        }
Esempio n. 9
0
        public static async Task CheckMessage(SocketMessage message)
        {
            var chnl  = message.Channel as SocketGuildChannel;
            var Guild = chnl.Guild;

            if (Guild != null && Directory.Exists("/home/bob_the_daniel/Data/" + Guild.OwnerId) && !Utilities.HasAdmin(message.Author as SocketGuildUser))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.NullValueHandling = NullValueHandling.Ignore;
                List <BadWord> badWords;

                using (StreamReader sr = new StreamReader(@"/home/bob_the_daniel/Data/" + Guild.OwnerId + "/badwords.json"))
                    using (JsonTextReader reader = new JsonTextReader(sr)) {
                        badWords = serializer.Deserialize <List <BadWord> >(reader);
                    }

                if (message.Content.Contains("discord.gg/"))
                {
                    if (!SettingFunctions.LoadModSettings(Guild).invitesAllowed)
                    {
                        ModerationFunctions.WarnUser(message.Author, 0.5f, "Posted Invite", Guild.OwnerId + "/Infractions/Discord/" + message.Author.Id);
                        await message.Channel.SendMessageAsync("warned " + message.Author.Mention + " for posting a discord invite");

                        Logging.LogDeleted("Bad word removed", message, Guild);
                        await message.DeleteAsync();

                        return;
                    }
                }

                //Guild.OwnerId
                if (File.Exists("/home/bob_the_daniel/Data/" + Guild.OwnerId + "/badwords.json"))
                {
                    foreach (BadWord badWord in badWords)
                    {
                        if (message.Content.Contains(badWord.word))
                        {
                            ModerationFunctions.WarnUser(message.Author, 0.5f, "Bad word", Guild.OwnerId + "/Infractions/Discord/" + message.Author.Id);
                            await message.Channel.SendMessageAsync("warned " + message.Author.Mention + " for bad word");

                            Logging.LogDeleted("Bad word removed", message, Guild);
                            await message.DeleteAsync();

                            return;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 public async Task CheckUserWarnsAsync(SocketUser user = null)
 {
     ModerationFunctions.CheckDirectories(Context.Guild);
     if (user == null)
     {
         user = Context.Message.Author;
     }
     if (File.Exists("/home/bob_the_daniel/Data/" + Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id))
     {
         await ReplyAsync(embed : ModerationFunctions.CheckInfractions(user, Context.Guild.OwnerId + "/Infractions/Discord/" + user.Id));
     }
     else
     {
         await ReplyAsync(user.Username + " has no warns");
     }
 }
Esempio n. 11
0
        public async Task WarnUserAsync(SocketUser user, float size, [Remainder] string reason)
        {
            if (!((SocketGuildUser)Context.User).CanWarn())
            {
                await ReplyAsync("You do not have permission to use this command");

                return;
            }
            if (size > 999 || size < 0.01)
            {
                await ReplyAsync("Why would you need to warn someone with that size?");

                return;
            }

            ModerationFunctions.CheckDirectories(Context.Guild);
            ModerationFunctions.WarnUser(user, size, reason, Context.Guild.OwnerId + "/Infractions/Games/" + user.Id);

            await ReplyAsync(user.Username + " has been warned for " + reason);
        }