Jump to content

User:LuisBot01

From Wikipedia, the free encyclopedia

This bot was formerly designed to remove {{Sockpuppeteer}} templates after 5 minutes with no sockpuppet investigation created, but has never edited and is inactive.

Source code

[edit]
using System;
using DotNetWikiBot;

namespace LuisBot01
{
    // This bot removes sockpuppeteers with no sockpuppet investigations casepage.
    public class MyBot : Bot
    {
        public static void Main()
        {
            Console.Write("Password: ");
            Site enWiki = new Site("http://wiki.riteme.site", "LuisBot01", Console.ReadLine());
            PageList pl = new PageList(enWiki);
            PageList usernames = new PageList(enWiki), usernames2 = new PageList(enWiki);
            int cycleNumber = 0;
            while (true)
            {
                pl.FillFromCategory("Category:Wikipedia sockpuppeteers");
                pl.FilterNamespaces(new int[] { 2, 3 });
                usernames2 = new PageList(enWiki);
                foreach (Page p in pl)
                {
                    usernames2.Add(p);
                }
                foreach (Page p in usernames)
                {
                    string s = p.title.Remove(0, p.GetNamespace() == 3 ? 10 : 5);
                    Page spi = new Page(enWiki, "Wikipedia:Sockpuppet investigations/" + s);
                    spi.Load();
                    if (!spi.Exists())
                    {
                        // In the case of an edit conflict, i increments and we retry to save up to 5 times.
                        for (int i = 0; i < 5; i++)
                        {
                            try
                            {
                                p.Load();
                                p.RemoveTemplate("Sockpuppeteer");
                                p.RemoveFromCategory("Category:Wikipedia sockpuppeteers");
                                p.Save(string.Format("Removing {0} from user with no [[Wikipedia:Sockpuppet investigations/{1}|SPI]] (DotNetWikiBot 3.15)", "{{[[Template:Sockpuppeteer|Sockpuppeteer]]}}", s));
                            }
                            catch (InsufficientRightsException e)
                            {
                                // Ignore InsufficientRightsException.
                                Console.WriteLine("Caught exception when trying to edit, and stopped: ");
                                Console.WriteLine(e.ToString());
                                break;
                            }
                            catch (BotDisallowedException e)
                            {
                                // Ignore BotDisallowedException.
                                Console.WriteLine("Caught exception when trying to edit, and stopped: ");
                                Console.WriteLine(e.ToString());
                                break;
                            }
                            catch (WikiBotException e)
                            {
                                if (e is EditConflictException)
                                {
                                    if (i != 4)
                                    {
                                        // Let's retry.
                                        Console.WriteLine("Edit conflict. Retry #" + (i + 1));
                                    }
                                    continue;
                                }
                                // Ignore WikiBotException.
                                Console.WriteLine("Caught exception when trying to edit, and stopped: ");
                                Console.WriteLine(e.ToString());
                                break;
                            }
                        }
                    }
                }
                // New cycle. Wait 5 minutes.
                usernames = usernames2;
                Console.WriteLine("Cycle {0} done.", cycleNumber++);
                Bot.Wait(300);
            }
        }
    }
}