Jump to content

User:MilHistBot/AutoCheck.cs

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hawkeye7 (talk | contribs) at 22:35, 11 October 2020 (Updated). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using NDesk.Options;

public class AutoCheck
{
    private Bot bot;

    private int unchanged;
    private int upgrade;
    private int newgrade;
    private int downgrade;

    private int  max     = 1;
    private bool debugs  = false;
    private bool force   = false;
    private bool help    = false;
    private bool verbose = false;
    private Dictionary<string, int> classes;

    private bool compareClass (string oldClass, string botClass)
    {
        if (null == classes)
        {
            classes = new Dictionary<string, int>()
            {
                { "Stub",  0 },
                { "Start", 1 },
                { "List",  1 },
                { "C",     2 },
                { "CL",    2 },
                { "B",     3 },
                { "BL",    3 },
            };
        }

        if (oldClass.Equals (""))
        {
            newgrade++;
            return true;
        }

        if (! classes.ContainsKey (oldClass))
        {
            throw new ApplicationException ("unknown class: '" + oldClass + "'");
        }

        int diff = classes[botClass] - classes[oldClass];
        if (0 > diff)
        {
            downgrade++;
        }
        else if (0 == diff)
        {
            unchanged++;
            return false;
        }
        else if (0 < diff)
        {
            upgrade++;
        }
        return true;
    }

    private void report ()
    {
        bot.Cred.Showtime (String.Format("{0} articles newly rated, {1} downgraded, {2} upgraded, {3} unchanged - total {4}",
                            newgrade, downgrade, upgrade, unchanged, newgrade + downgrade + upgrade + unchanged));
    }

    private void autoCheck (Page article, Page talk)
    {
        try
        {
            bot.Cred.Showtime (article.Title);
            article.Load ();
            talk.Load ();
            var template = talk.MilHist.ProjectTemplate;
            var oldClass = template.Class;
            var rating   = template.Rating;
            var botClass = rating.Class;

            Debug.WriteLine  ("\tOriginal: <code><nowiki>" + template.Text + "</code>");
            template.RemoveAll ("^class$