Пример #1
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);
            }
        }
Пример #2
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);
        }