Exemplo n.º 1
0
        public static async void PruneNonmembers(SocketGuildUser moderator, ITextChannel channel, IReadOnlyCollection <IGuildUser> users)
        {
            int usersPruned = 0;

            foreach (IGuildUser user in users)
            {
                if (user.RoleIds.Count <= 1)
                {
                    Processing.LogConsoleText($"Nonmember found: {user.Username}", channel.Guild.Id);
                    await user.KickAsync("Inactivity");

                    usersPruned++;
                }
            }

            var embed = Embeds.PruneNonmembers(usersPruned);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the prune in the bot-logs channel
            embed = Embeds.LogPruneNonmembers(moderator, usersPruned);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(channel.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public static async void Unlock(SocketGuildUser moderator, ITextChannel channel)
        {
            //Unlock the channel
            var guild = channel.Guild;

            //Don't mess with channel permissions if nonmembers can't speak there anyway
            if (IsPublicChannel((SocketGuildChannel)channel))
            {
                try
                {
                    await channel.RemovePermissionOverwriteAsync(guild.EveryoneRole, RequestOptions.Default);
                }
                catch
                {
                    Processing.LogConsoleText($"Failed to unlock {guild.Name}#{channel.Name.ToString()}", guild.Id);
                }
            }

            //Announce the unlock
            var embed = Embeds.Unlock(channel);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the lock in the bot-logs channel
            embed = Embeds.LogUnlock(moderator, channel);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(channel.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        public static async void Unmute(string moderator, ITextChannel channel, SocketGuildUser user)
        {
            foreach (SocketTextChannel chan in user.Guild.TextChannels)
            {
                var guild = user.Guild;
                //Don't mess with channel permissions if nonmembers can't speak there anyway
                if (IsPublicChannel(chan))
                {
                    try
                    {
                        await chan.RemovePermissionOverwriteAsync(user, RequestOptions.Default);
                    }
                    catch
                    {
                        Processing.LogConsoleText($"Failed to unmute in {guild.Name}#{chan.Name.ToString()}", guild.Id);
                    }
                }
            }

            var embed = Embeds.Unmute(user);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the unmute in the bot-logs channel
            embed = Embeds.LogUnmute(moderator, channel, user);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Exemplo n.º 4
0
        public static void UpdateTSV(IGuildChannel channel)
        {
            string githubPath = UserSettings.BotOptions.GetString("AmicitiaGithubIoPath", channel.GuildId);
            string tsvPath    = Path.Combine(githubPath, "db\\mods.tsv");

            if (File.Exists(tsvPath))
            {
                foreach (var line in File.ReadAllLines("threads.txt"))
                {
                    string tsvLine = line.Split('|')[2];
                    if (tsvLine != "")
                    {
                        string modID = tsvLine.Split('\t')[0];
                        if (!File.ReadAllText(tsvPath).Contains(modID + "\t"))
                        {
                            Processing.LogConsoleText($"Adding {modID} to mods.tsv", channel.GuildId);
                            File.AppendAllText(tsvPath, line + Environment.NewLine);
                        }
                    }
                }
            }
            else
            {
                Processing.LogConsoleText("Could not find Amicitia.github.io directory specified in BotOptions.xml", channel.GuildId);
            }
        }
Exemplo n.º 5
0
        public static async void Mute(string moderator, ITextChannel channel, SocketGuildUser user)
        {
            var guild = user.Guild;

            //Mute the specified user in each text channel if it's not a bot
            if (!user.IsBot)
            {
                foreach (SocketTextChannel chan in user.Guild.TextChannels)
                {
                    //Don't mess with channel permissions if nonmembers can't speak there anyway
                    if (IsPublicChannel(chan))
                    {
                        try
                        {
                            await chan.AddPermissionOverwriteAsync(user, new OverwritePermissions(sendMessages : PermValue.Deny, addReactions : PermValue.Deny), RequestOptions.Default);
                        }
                        catch
                        {
                            Processing.LogConsoleText($"Failed to mute in {guild.Name}#{chan.Name.ToString()}", guild.Id);
                        }
                    }
                }
            }

            //Announce the mute
            var embed = Embeds.Mute(user);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the mute in the bot-logs channel
            embed = Embeds.LogMute(moderator, channel, user);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Exemplo n.º 6
0
        public static List <List <string> > DownloadForumPosts(IGuildChannel channel)
        {
            List <List <string> > threads = new List <List <string> >();

            int[] forumIDs = new int[] { 11, 12, 13, 15, 16, 18, 19, 20, 27, 29, 30 };
            for (int i = 0; i < forumIDs.Count(); i++)
            {
                Processing.LogConsoleText($"Checking threads in Forum ID {forumIDs[i]}...", channel.GuildId);
                using (var client = new WebClient())
                {
                    string page = client.DownloadString($"https://shrinefox.com/forum/viewforum.php?f={forumIDs[i]}");
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(page);

                    //Get thread list
                    HtmlNodeCollection nodeCollection = doc
                                                        .DocumentNode
                                                        .SelectNodes("//ul[@class='topiclist topics']//dt//div//a[@class='topictitle']");

                    //Return thread info
                    foreach (var node in nodeCollection)
                    {
                        //Subnodes
                        var dateNode = node.ParentNode.Descendants("div").First(x => x.Attributes["class"].Value.Contains("responsive"));

                        //Title Node
                        string threadUrl = WebUtility.HtmlDecode(node.Attributes["href"].Value.ToString()).Replace("./", "https://shrinefox.com/forum/");
                        threadUrl = threadUrl.Replace(threadUrl.Split('&')[2], "").TrimEnd('&');
                        string threadTitle = WebUtility.HtmlDecode(node.InnerText);
                        string tsvLine     = "";

                        //Ignore sample thread
                        if (threadTitle != "New Mod Submission System")
                        {
                            //Date Node
                            var    authorNode = dateNode.Descendants("a").First(x => x.Attributes["class"].Value.Contains("username"));
                            string authorUrl  = WebUtility.HtmlDecode(authorNode.Attributes["href"].Value.ToString()).Replace("./", "https://shrinefox.com/forum/");
                            string authorName = WebUtility.HtmlDecode(authorNode.InnerText);
                            string date       = WebUtility.HtmlDecode(dateNode.InnerText).Replace("\t", "").Split('\n')[1].Replace($"by {authorName} » ", "");

                            //Ignore thread if URL is already added or thread is older than last update
                            DateTime threadTime = new DateTime();
                            DateTime.TryParse(date, out threadTime);
                            DateTime fileTime = File.GetLastWriteTime("threads.txt");
                            if (!File.ReadAllText("threads.txt").Contains(threadUrl) && !File.ReadAllText("threads.txt").Contains(threadTitle) && threadTime > fileTime)
                            {
                                //Download thread and check for spoiler if link/title isn't already found in threads.txt
                                tsvLine = GetTSVLine(threadUrl, channel);
                                Processing.LogConsoleText($"Downloading Thread: {threadTitle}", channel.GuildId);
                            }
                            else
                            {
                                Processing.LogConsoleText($"Already found or outdated, skipping: {threadTitle}", channel.GuildId);
                            }

                            List <string> threadInfo = new List <string>();
                            threadInfo.Add(threadUrl);   //0
                            threadInfo.Add(threadTitle); //1
                            threadInfo.Add(tsvLine);     //2
                            threadInfo.Add(authorUrl);   //3
                            threadInfo.Add(authorName);  //4
                            threadInfo.Add(date);        //5
                            threads.Add(threadInfo);
                        }
                    }
                }
            }

            return(threads);
        }