Exemplo n.º 1
0
        public replace(string[] param)
        {
            Console.WriteLine("'Replace' by Miguel Peláez <*****@*****.**>");

            for(int i = 1; i < param.Length; i++)
            {
                string p = param[i];
                //Detect the start at
                if (p.Contains("-start:"))
                {
                    Start = param[i];
                    Start = Start.Replace("-start:", "");
                    break;
                }
                else if (p.Contains("-cat:"))
                {
                    Cat = param[i];
                    Cat = Cat.Replace("-cat:", "");
                    break;
                }
                /*
                else if (p.Contains("-ns:"))
                {
                    NS = param[i];
                    NS = NS.Replace("-ns:", "");
                    int ns = 0;
                    if (!int.TryParse(NS, out ns)){ NS = "0"; ns = 0; Console.WriteLine("Error: '{0}' is unknown namespace. The correct format is a number.", NS);}
                    break;
                }*/
                else if (p.Contains("-rex:"))
                {
                    string rex = param[i];
                    rex = rex.Replace("-rex:", "");
                    if (!bool.TryParse(rex, out REX)){ Console.WriteLine("Error: '{0}' is unknown regular expression bool. The correct format is a true|false echo.", rex);}
                    break;
                }
                else if (p.Contains("-page:"))
                {
                    Page = param[i];
                    Page = Page.Replace("-page:", "");
                    break;
                }
            }
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Write("Text to replace (old):");
            Console.ResetColor();
            OldText = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Write("Text for replace (new):");
            Console.ResetColor();
            NewText = Console.ReadLine();
            //Replace main
            if (!string.IsNullOrEmpty(Page))
            {
                inteliBOT.Page page = new inteliBOT.Page(Page);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Attempt to replace text order in {0}", Page);
                Console.ResetColor();
                //Console.WriteLine("Page namespace: {0}", page.GetNamespace().ToString());
                if(!REX) page.Text = page.Text.Replace(OldText, NewText);
                else page.Text = Regex.Replace(page.Text, OldText, NewText);
                Console.WriteLine(page.Save(page.Text, "BOT: Reemplazando texto de forma programada [[Usuario:inteliBOT/Errores|Me equivoqué]]"));
            }
            if (!string.IsNullOrEmpty(Cat))
            {
                string[] P = CategoryMembers(Site.wiki, Cat);
                for (int i = 0; i < P.Length; i++)
                {
                    string CatPage = P[i];
                    inteliBOT.Page page = new inteliBOT.Page(CatPage);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Attempt to replace text order in {0}", page.Tittle);
                    Console.ResetColor();
                    //Console.WriteLine("Page namespace: {0}", page.GetNamespace().ToString());
                    if(!REX) page.Text = page.Text.Replace(OldText, NewText);
                    else page.Text = Regex.Replace(page.Text, OldText, NewText);
                    Console.WriteLine(page.Save(page.Text, "BOT: Reemplazo automático programado [[Usuario:inteliBOT/Errores|Me equivoqué]]"));
                }
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Replace on cat '{0}' ready", Cat);
                Console.ResetColor();
            }
            if (!string.IsNullOrEmpty(Start))
            {
                string[] P = AllPages(Start, true);
                while (!String.IsNullOrEmpty(P[0]))
                {
                for (int i = 0; i < P.Length; i++)
                {
                    string StPage = P[i];
                    inteliBOT.Page page = new inteliBOT.Page(StPage);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Attempt to replace text order in {0}", page.Tittle);
                    Console.ResetColor();
                    //Console.WriteLine("Page namespace: {0}", page.GetNamespace().ToString());
                    if(!REX) page.Text = page.Text.Replace(OldText, NewText);
                    else page.Text = Regex.Replace(page.Text, OldText, NewText);
                    Console.WriteLine(page.Save(page.Text, "BOT: Reemplazo automático programado [[Usuario:inteliBOT/Errores|Me equivoqué]]"));
                }
                    P = AllPages();
                }
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Replace ready");
                Console.ResetColor();
            }
        }
Exemplo n.º 2
0
        public static void VoteCheck(string art)
        {
            //Defines a inteliBOT.art
            inteliBOT.Page page = new inteliBOT.Page(art);
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Attempt to check votes in {0}", art);
            Console.ResetColor();
            string[] Lines = page.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
            List<string> LinesD = new List<string>();
            //Use a loop for improve the speed
            for(int i = 0; i < Lines.Length; i++)
            {
                string Line = Lines[i];
                if (Line.StartsWith("#") && Line[1] != ':')
                {
                    string userName = String.Empty;
                    Regex regex = new Regex("[Uu]s(er|uari[ao])([ _][Dd]iscusión|[ _][Tt]alk)?:\\s*(.*?)[#\\|\\/\\]]", RegexOptions.Singleline);
                    Match match = regex.Match(Line);
                    if (match.Success)
                    {
                        userName = match.Groups[3].ToString();
                        Console.WriteLine("Checking {0}", userName);
                        if (EditCounter(userName) < 100 || ((TimeSpan)(DateTime.Now - FirstEdit(userName))).Days < 30)
                        {
                            Line = "#:<s>" + Line.Replace("#", "") + "</s> {{subst:votonulo|~~~~}}";
                        }
                    }
                    LinesD.Add(Line);
                }
                else
                {
                    LinesD.Add(Line);
                    continue;
                }

            }
            page.Text = string.Empty;
            foreach (string Line in LinesD)
            {
                if(!String.IsNullOrEmpty(page.Text))
                    page.Text = page.Text + Environment.NewLine + Line;
                else page.Text = Line;
            }
            Console.WriteLine("Page '{0}' checked whith result {1}",
                              page.Tittle, page.Save(page.Text,
                                   "BOT: Marcando a los usuarios que no cumplen los requisitos para votar [[Usuario:inteliBOT/Errores|¿Me equivoqué?]]"));
        }