Esempio n. 1
0
        protected TimeMonitor()
        {
            this._targetDate = Configuration.singleton()["newYearDateMonitoringTarget"];

            this._monitorThread = new Thread(monitorThreadMethod);

            this._timezoneList = new Dictionary<DateTime, string>();

            DAL.Select q = new DAL.Select(
                "tz_places",
                "ADDDATE(ADDDATE(\"" + MySqlHelper.EscapeString(this._targetDate) +
                "\", INTERVAL -tz_offset_hours HOUR), INTERVAL -tz_offset_minutes MINUTE)"
                );
            q.setFrom("timezones");
            q.escapeSelects(false);
            q.addOrder(
                new DAL.Select.Order(
                    "ADDDATE(ADDDATE(\"" + MySqlHelper.EscapeString(this._targetDate) +
                    "\", INTERVAL -tz_offset_hours HOUR), INTERVAL -tz_offset_minutes MINUTE)", false, false));

            ArrayList al = DAL.singleton().executeSelect(q);

            foreach (object[] row in al)
            {
                this._timezoneList.Add((DateTime.Parse(new String(Encoding.UTF8.GetChars(((byte[]) (row)[1]))))),
                                 (string) (row[0]));
            }

            this.registerInstance();
            this._monitorThread.Start();
        }
Esempio n. 2
0
        public static CommandResponseHandler joinChannel(string args, uint network)
        {
            DAL.Select q = new DAL.Select("count(*)");
            q.addWhere(new DAL.WhereConds("channel_name", args));
            q.addWhere(new DAL.WhereConds("channel_network", network.ToString()));
            q.setFrom("channel");

            string count = DAL.singleton().executeScalarSelect(q);

            if (count == "1")
            {
                // entry exists

                Dictionary<string, string> vals = new Dictionary<string, string>
                                                      {
                                                          {
                                                              "channel_enabled",
                                                              "1"
                                                              }
                                                      };
                DAL.singleton().update("channel", vals, 1, new DAL.WhereConds("channel_name", args));

                Helpmebot6.irc.ircJoin(args);
            }
            else
            {
                DAL.singleton().insert("channel", "", args, "", "1", network.ToString());
                Helpmebot6.irc.ircJoin(args);
            }
            return null;
        }
Esempio n. 3
0
        private static void categoryHasItemsEvent(ArrayList items, string keyword)
        {
            ArrayList newItems = updateDatabaseTable(items, keyword);

            DAL.Select q = new DAL.Select("channel_name");
            q.addJoin("channelwatchers", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "watcher_id", "=", false, "cw_watcher"));
            q.addJoin("channel", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "channel_id", "=", false, "cw_channel"));
            q.setFrom("watcher");
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            q.addLimit(10, 0);

            ArrayList channels = DAL.singleton().executeSelect(q);

            foreach (object[] item in channels)
            {
                string channel = (string)item[0];

                string message = compileMessage(items, keyword, channel, false);
                if (Configuration.singleton()["silence", channel] == "false")
                {
                    Helpmebot6.irc.ircPrivmsg(channel, message);
                }
            }

            if (newItems.Count > 0)
            {
                var message = compileMessage(newItems, keyword, ">TWITTER<", false);

                new Twitter().updateStatus(message);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the edit count.
        /// </summary>
        /// <param name="username">The username to retrieve the edit count for.</param>
        /// <param name="channel">The channel the command was issued in. (Gets the correct base wiki)</param>
        /// <returns></returns>
        public int getEditCount(string username, string channel)
        {
            if (username == string.Empty)
            {
                throw new ArgumentNullException();
            }

            string baseWiki = Configuration.singleton()["baseWiki",channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            username = HttpUtility.UrlEncode(username);

            XPathDocument xpd =
                new XPathDocument(
                    HttpRequest.get(api + "?format=xml&action=query&list=users&usprop=editcount&format=xml&ususers=" +
                                    username));

            XPathNodeIterator xpni = xpd.CreateNavigator().Select("//user");

            if (xpni.MoveNext())
            {
                string editcount = xpni.Current.GetAttribute("editcount", "");
                if(editcount!= "") return int.Parse(editcount);

                if (xpni.Current.GetAttribute("missing", "") == "")
                    return -1;
            }

            throw new ArgumentException();
        }
Esempio n. 5
0
        public static CommandResponseHandler joinChannel(string args, uint network)
        {
            DAL.Select q = new DAL.Select("count(*)");
            q.addWhere(new DAL.WhereConds("channel_name", args));
            q.addWhere(new DAL.WhereConds("channel_network", network.ToString()));
            q.setFrom("channel");

            string count = DAL.singleton().executeScalarSelect(q);


            if (count == "1")
            {
                // entry exists

                Dictionary <string, string> vals = new Dictionary <string, string>
                {
                    {
                        "channel_enabled",
                        "1"
                    }
                };
                DAL.singleton().update("channel", vals, 1, new DAL.WhereConds("channel_name", args));

                Helpmebot6.irc.ircJoin(args);
            }
            else
            {
                DAL.singleton().insert("channel", "", args, "", "1", network.ToString());
                Helpmebot6.irc.ircJoin(args);
            }
            return(null);
        }
Esempio n. 6
0
        public DateTime getRegistrationDate(string username, string channel)
        {
            if (username == string.Empty)
            {
                throw new ArgumentNullException();
            }
            string baseWiki = Configuration.singleton()["baseWiki", channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string        api     = DAL.singleton().executeScalarSelect(q);
            XmlTextReader creader =
                new XmlTextReader(
                    HttpRequest.get(api + "?action=query&list=users&usprop=registration&format=xml&ususers=" + username));

            do
            {
                creader.Read();
            } while (creader.Name != "user");
            string apiRegDate = creader.GetAttribute("registration");

            if (apiRegDate != null)
            {
                if (apiRegDate == "")
                {
                    return(new DateTime(1970, 1, 1, 0, 0, 0));
                }
                DateTime regDate = DateTime.Parse(apiRegDate);
                return(regDate);
            }
            return(new DateTime(0));
        }
Esempio n. 7
0
        private static int getWatcherId(string keyword)
        {
            DAL.Select q = new DAL.Select("watcher_id");
            q.setFrom("watcher");
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            string watcherIdString = DAL.singleton().executeScalarSelect(q);

            return(int.Parse(watcherIdString));
        }
Esempio n. 8
0
        private static ArrayList updateDatabaseTable(ArrayList items, string keyword)
        {
            ArrayList newItems = new ArrayList();

            foreach (string item in items)
            {
                DAL.Select q = new DAL.Select("COUNT(*)");
                q.setFrom("categoryitems");
                q.addWhere(new DAL.WhereConds("item_name", item));
                q.addWhere(new DAL.WhereConds("item_keyword", keyword));

                string dbResult;
                try
                {
                    dbResult = DAL.singleton().executeScalarSelect(q);
                }
                catch (MySqlException ex)
                {
                    GlobalFunctions.errorLog(ex);
                    dbResult = "0";
                }

                if (dbResult == "0")
                {
                    DAL.singleton().insert("categoryitems", "", item, "", keyword, "1");
                    newItems.Add(item);
                }
                else
                {
                    Dictionary <string, string> v = new Dictionary <string, string>
                    {
                        {
                            "item_updateflag",
                            "1"
                        }
                    };
                    DAL.singleton().update("categoryitems", v, 1, new DAL.WhereConds("item_name", item),
                                           new DAL.WhereConds("item_keyword", keyword));
                }
            }
            DAL.singleton().delete("categoryitems", 0, new DAL.WhereConds("item_updateflag", 0),
                                   new DAL.WhereConds("item_keyword", keyword));
            Dictionary <string, string> val = new Dictionary <string, string>
            {
                { "item_updateflag", "0" }
            };

            DAL.singleton().update("categoryitems", val, 0);
            return(newItems);
        }
Esempio n. 9
0
        private ArrayList removeBlacklistedItems(ArrayList pageList)
        {
            DAL.Select q = new DAL.Select("ip_title");
            q.setFrom("ignoredpages");
            ArrayList blacklist = DAL.singleton().executeSelect(q);

            foreach (object[] item in blacklist)
            {
                if (pageList.Contains(item[0]))
                {
                    pageList.Remove(item[0]);
                }
            }

            return(pageList);
        }
Esempio n. 10
0
        /// <summary>
        /// Adds the watcher to channel.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <param name="channel">The channel.</param>
        /// <returns></returns>
        public bool addWatcherToChannel(string keyword, string channel)
        {
            string channelId = Configuration.singleton().getChannelId(channel);
            int    watcherId = getWatcherId(keyword);

            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelwatchers");
            q.addWhere(new DAL.WhereConds("cw_channel", channelId));
            q.addWhere(new DAL.WhereConds("cw_watcher", watcherId));
            string count = DAL.singleton().executeScalarSelect(q);

            if (count == "0")
            {
                DAL.singleton().insert("channelwatchers", channelId, watcherId.ToString());
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CategoryWatcher"/> class.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="key">The key.</param>
        /// <param name="sleepTime">The sleep time.</param>
        public CategoryWatcher(string category, string key, int sleepTime)
        {
            // look up site id
            string baseWiki = Configuration.singleton()["baseWiki"];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            _site = DAL.singleton().executeScalarSelect(q);

            _category  = category;
            _key       = key;
            _sleepTime = sleepTime;

            this.registerInstance();

            this._watcherThread = new Thread(watcherThreadMethod);
            this._watcherThread.Start();
        }
Esempio n. 12
0
        /// <summary>
        /// Determines whether [is watcher in channel] [the specified channel].
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="keyword">The keyword.</param>
        /// <returns>
        ///     <c>true</c> if [is watcher in channel] [the specified channel]; otherwise, <c>false</c>.
        /// </returns>
        public bool isWatcherInChannel(string channel, string keyword)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelwatchers");
            q.addWhere(new DAL.WhereConds("channel_name", channel));
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            q.addJoin("channel", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "cw_channel", "=", false, "channel_id"));
            q.addJoin("watcher", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "cw_watcher", "=", false, "watcher_id"));

            string count = DAL.singleton().executeScalarSelect(q);

            if (count == "0")
            {
                return(false);
            }
            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// Gets the rights of a wikipedian.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="channel">The channel to get the base wiki for.</param>
        /// <returns></returns>
        public string getRights(string username, string channel)
        {
            if (username == string.Empty)
            {
                throw new ArgumentNullException();
            }
            string baseWiki = Configuration.singleton()["baseWiki", channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            string        returnStr   = "";
            int           rightsCount = 0;
            XmlTextReader creader     =
                new XmlTextReader(
                    HttpRequest.get(api + "?action=query&list=users&usprop=groups&format=xml&ususers=" + username));

            do
            {
                creader.Read();
            } while (creader.Name != "user");
            creader.Read();
            if (creader.Name == "groups") //the start of the group list
            {
                do
                {
                    creader.Read();
                    string rightsList = (creader.ReadString());
                    if (!(rightsList == "" || rightsList == "*"))
                    {
                        returnStr = returnStr + rightsList + ", ";
                    }
                    rightsCount = rightsCount + 1;
                } while (creader.Name == "g"); //each group should be added
            }
            returnStr = rightsCount == 0 ? "" : returnStr.Remove(returnStr.Length - 2);


            return(returnStr);
        }
Esempio n. 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WatcherController"/> class.
        /// </summary>
        protected WatcherController()
        {
            this._watchers = new Dictionary<string, CategoryWatcher>();

            DAL.Select q = new DAL.Select("watcher_category", "watcher_keyword", "watcher_sleeptime");
            q.addOrder(new DAL.Select.Order("watcher_priority", true));
            q.setFrom("watcher");
            q.addLimit(100, 0);
            ArrayList watchersInDb = DAL.singleton().executeSelect(q);
            foreach (object[] item in watchersInDb)
            {
                this._watchers.Add((string) item[1],
                             new CategoryWatcher((string) item[0], (string) item[1],
                                                 int.Parse(((UInt32) item[2]).ToString())));
            }
            foreach (KeyValuePair<string, CategoryWatcher> item in this._watchers)
            {
                item.Value.categoryHasItemsEvent += categoryHasItemsEvent;
            }
        }
Esempio n. 15
0
        protected NewbieWelcomer()
        {
            DAL.Select q = new DAL.Select("bin_blob");
            q.setFrom("binary_store");
            q.addWhere(new DAL.WhereConds("bin_desc", "newbie_hostnames"));
            ArrayList result = DAL.singleton().executeSelect(q);

            byte[] list = ((byte[]) (((object[]) (result[0]))[0]));

            BinaryFormatter bf = new BinaryFormatter();
            try
            {
                this._hostNames = (SerializableArrayList) bf.Deserialize(new MemoryStream(list));
            }
            catch (SerializationException ex)
            {
                GlobalFunctions.errorLog(ex);
                this._hostNames = new SerializableArrayList();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WatcherController"/> class.
        /// </summary>
        protected WatcherController()
        {
            this._watchers = new Dictionary <string, CategoryWatcher>();

            DAL.Select q = new DAL.Select("watcher_category", "watcher_keyword", "watcher_sleeptime");
            q.addOrder(new DAL.Select.Order("watcher_priority", true));
            q.setFrom("watcher");
            q.addLimit(100, 0);
            ArrayList watchersInDb = DAL.singleton().executeSelect(q);

            foreach (object[] item in watchersInDb)
            {
                this._watchers.Add((string)item[1],
                                   new CategoryWatcher((string)item[0], (string)item[1],
                                                       int.Parse(((UInt32)item[2]).ToString())));
            }
            foreach (KeyValuePair <string, CategoryWatcher> item in this._watchers)
            {
                item.Value.categoryHasItemsEvent += categoryHasItemsEvent;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the edit count.
        /// </summary>
        /// <param name="username">The username to retrieve the edit count for.</param>
        /// <param name="channel">The channel the command was issued in. (Gets the correct base wiki)</param>
        /// <returns></returns>
        public int getEditCount(string username, string channel)
        {
            if (username == string.Empty)
            {
                throw new ArgumentNullException();
            }

            string baseWiki = Configuration.singleton()["baseWiki", channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            username = HttpUtility.UrlEncode(username);

            XPathDocument xpd =
                new XPathDocument(
                    HttpRequest.get(api + "?format=xml&action=query&list=users&usprop=editcount&format=xml&ususers=" +
                                    username));

            XPathNodeIterator xpni = xpd.CreateNavigator().Select("//user");


            if (xpni.MoveNext())
            {
                string editcount = xpni.Current.GetAttribute("editcount", "");
                if (editcount != "")
                {
                    return(int.Parse(editcount));
                }

                if (xpni.Current.GetAttribute("missing", "") == "")
                {
                    return(-1);
                }
            }

            throw new ArgumentException();
        }
Esempio n. 18
0
        /// <summary>
        /// Gets the user page URL.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="channel">The channel.</param>
        /// <returns></returns>
        private static string getUserPageUrl(string userName, string channel)
        {
            if (userName == string.Empty)
            {
                throw new ArgumentNullException();
            }
            // look up site id
            string baseWiki = Configuration.singleton()["baseWiki", channel];

            // get api
            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);


            // api-> get mainpage name (Mediawiki:mainpage)
            const string  apiQuery = "?action=query&prop=revisions&titles=Mediawiki:Mainpage&rvprop=content&format=xml";
            XmlTextReader creader  = new XmlTextReader(HttpRequest.get(api + apiQuery));

            do
            {
                creader.Read();
            } while (creader.Name != "rev");
            string mainpagename = creader.ReadElementContentAsString();

            mainpagename = mainpagename.Replace(" ", "_");

            // get mainpage url from site table
            q = new DAL.Select("site_mainpage");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string mainpageurl = DAL.singleton().executeScalarSelect(q);

            // replace mainpage in mainpage url with user:<username>

            userName = userName.Replace(" ", "_");

            return(mainpageurl.Replace(mainpagename, "User:" + userName));
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the maximum replication lag between the Wikimedia Foundation MySQL database cluster for the base wiki of the channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns></returns>
        public string getMaxLag(string channel)
        {
            // look up site id
            string baseWiki = Configuration.singleton()["baseWiki", channel];

            // get api

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            XmlTextReader mlreader =
                new XmlTextReader(HttpRequest.get(api + "?action=query&meta=siteinfo&siprop=dbrepllag&format=xml"));

            do
            {
                mlreader.Read();
            } while (mlreader.Name != "db");

            string lag = mlreader.GetAttribute("lag");

            return(lag);
        }
Esempio n. 20
0
        /// <summary>
        /// Gets the size of a category.
        /// </summary>
        /// <param name="categoryName">The category to retrieve the article count for.</param>
        /// <param name="channel">The channel the command was issued in. (Gets the correct base wiki)</param>
        /// <returns></returns>
        public int getCategorySize(string categoryName, string channel)
        {
            if (categoryName == string.Empty)
            {
                throw new ArgumentNullException();
            }

            string baseWiki = Configuration.singleton()["baseWiki", channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            XmlTextReader creader =
                new XmlTextReader(
                    HttpRequest.get(api + "?action=query&format=xml&prop=categoryinfo&titles=Category:" +
                                    categoryName));

            do
            {
                creader.Read();
            } while (creader.Name != "page");
            if (creader.GetAttribute("missing") == "")
            {
                return(-2);
            }
            creader.Read();
            string categorySize = creader.GetAttribute("size");

            if (categorySize != null)
            {
                return(int.Parse(categorySize));
            }
            return(-1);
        }
Esempio n. 21
0
 /// <summary>
 /// Loads all watched pages from the database.
 /// </summary>
 public void loadAllWatchedPages()
 {
     this._watchedPageList.Clear();
     DAL.Select q = new DAL.Select("pw_title");
     q.setFrom("watchedpages");
     ArrayList pL = DAL.singleton().executeSelect(q);
     foreach (object[] item in pL)
     {
         this._watchedPageList.Add(item[0]);
     }
 }
Esempio n. 22
0
        private static void categoryHasItemsEvent(ArrayList items, string keyword)
        {
            ArrayList newItems = updateDatabaseTable(items, keyword);

            DAL.Select q = new DAL.Select("channel_name");
            q.addJoin("channelwatchers", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "watcher_id", "=", false, "cw_watcher"));
            q.addJoin("channel", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "channel_id", "=", false, "cw_channel"));
            q.setFrom("watcher");
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            q.addLimit(10, 0);

            ArrayList channels = DAL.singleton().executeSelect(q);
            foreach (object[] item in channels)
            {
                string channel = (string) item[0];

                string message = compileMessage(items, keyword, channel, false);
                if (Configuration.singleton()["silence",channel] == "false")
                    Helpmebot6.irc.ircPrivmsg(channel, message);
            }

            if (newItems.Count > 0)
              new Twitter(  ).updateStatus(compileMessage(newItems, keyword, ">TWITTER<", false));
        }
Esempio n. 23
0
        /// <summary>
        /// Determines whether [is watcher in channel] [the specified channel].
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="keyword">The keyword.</param>
        /// <returns>
        /// 	<c>true</c> if [is watcher in channel] [the specified channel]; otherwise, <c>false</c>.
        /// </returns>
        public bool isWatcherInChannel(string channel, string keyword)
        {
            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelwatchers");
            q.addWhere(new DAL.WhereConds("channel_name", channel));
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            q.addJoin("channel", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "cw_channel", "=", false, "channel_id"));
            q.addJoin("watcher", DAL.Select.JoinTypes.Inner,
                      new DAL.WhereConds(false, "cw_watcher", "=", false, "watcher_id"));

            string count = DAL.singleton().executeScalarSelect(q);
            if (count == "0")
                return false;
            return true;
        }
Esempio n. 24
0
        private static int getWatcherId(string keyword)
        {
            DAL.Select q = new DAL.Select("watcher_id");
            q.setFrom("watcher");
            q.addWhere(new DAL.WhereConds("watcher_keyword", keyword));
            string watcherIdString = DAL.singleton().executeScalarSelect(q);

            return int.Parse(watcherIdString);
        }
Esempio n. 25
0
        //private string compileMessage( ArrayList items, string keyword )
        //{
        //    return compileMessage( items, keyword, "" , false);
        //}
        private static string compileMessage(ArrayList items, string keyword, string destination, bool forceShowAll)
        {
            // keywordHasItems: 0: count, 1: plural word(s), 2: items in category
            // keywordNoItems: 0: plural word(s)
            // keywordPlural
            // keywordSingular

            string fakedestination = destination == ">TWITTER<" ? "" : destination;

            bool showWaitTime = (fakedestination == ""
                                     ? false
                                     : (Configuration.singleton()["showWaitTime",destination] ==
                                        "true"
                                            ? true
                                            : false));

            TimeSpan minimumWaitTime;
            if (
                !TimeSpan.TryParse(Configuration.singleton()["minimumWaitTime",destination],
                                   out minimumWaitTime))
                minimumWaitTime = new TimeSpan(0);

            bool shortenUrls = (fakedestination == ""
                                    ? false
                                    : (Configuration.singleton()["useShortUrlsInsteadOfWikilinks", destination] == "true"
                                           ? true
                                           : false));
            bool showDelta = (fakedestination == ""
                                  ? false
                                  : (Configuration.singleton()["catWatcherShowDelta",
                                                                                         destination] == "true"
                                         ? true
                                         : false));

            if (destination == ">TWITTER<")
            {
                shortenUrls = true;
                showDelta = true;
            }

            if (forceShowAll)
                showDelta = false;

            string message;

            if (items.Count > 0)
            {
                string listString = "";
                foreach (string item in items)
                {
                    if (!shortenUrls)
                    {
                        listString += "[[" + item + "]]";
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(Configuration.singleton()["wikiUrl"] + item);
                            listString += IsGd.shorten(uri).ToString();
                        }
                        catch (UriFormatException ex)
                        {
                            listString += Configuration.singleton()["wikiUrl"] + item;
                            GlobalFunctions.errorLog(ex);
                        }
                    }

                    if (showWaitTime)
                    {
                        DAL.Select q = new DAL.Select("item_entrytime");
                        q.addWhere(new DAL.WhereConds("item_name", item));
                        q.addWhere(new DAL.WhereConds("item_keyword", keyword));
                        q.setFrom("categoryitems");

                        string insertDate = DAL.singleton().executeScalarSelect(q);
                        DateTime realInsertDate;
                        if (!DateTime.TryParse(insertDate, out realInsertDate))
                            realInsertDate = DateTime.Now;

                        TimeSpan ts = DateTime.Now - realInsertDate;

                        if (ts >= minimumWaitTime)
                        {
                            string[] messageparams = {
                                                         ts.Hours.ToString().PadLeft(2, '0'),
                                                         ts.Minutes.ToString().PadLeft(2, '0'),
                                                         ts.Seconds.ToString().PadLeft(2, '0'),
                                                         ts.TotalDays >= 1 ? ((int)Math.Floor(ts.TotalDays)) + "d " : ""
                                                     };
                            listString += new Message().get("catWatcherWaiting", messageparams);
                        }
                    }

                    // trailing space added as a hack because MediaWiki doesn't preserve the trailing space :(
                    listString += new Message().get("listSeparator") + " ";
                }
                listString = listString.TrimEnd(' ', ',');
                string pluralString = items.Count == 1 ? new Message().get(keyword + "Singular", "keywordSingularDefault") : new Message().get(keyword + "Plural", "keywordPluralDefault");
                string[] messageParams = {items.Count.ToString(), pluralString, listString};
                message = new Message().get(keyword + (showDelta ? "New" : "") + "HasItems",
                                                               messageParams);
            }
            else
            {
                string[] mp = {new Message().get(keyword + "Plural", "keywordPluralDefault")};
                message = new Message().get(keyword + "NoItems", mp);
            }
            return message;
        }
Esempio n. 26
0
        private ArrayList removeBlacklistedItems(ArrayList pageList)
        {
            DAL.Select q = new DAL.Select("ip_title");
            q.setFrom("ignoredpages");
            ArrayList blacklist = DAL.singleton().executeSelect(q);

            foreach (object[] item in blacklist)
            {
                if (pageList.Contains(item[0]))
                {
                    pageList.Remove(item[0]);
                }
            }

            return pageList;
        }
Esempio n. 27
0
        private static ArrayList updateDatabaseTable(ArrayList items, string keyword)
        {
            ArrayList newItems = new ArrayList();
            foreach (string item in items)
            {
                DAL.Select q = new DAL.Select("COUNT(*)");
                q.setFrom("categoryitems");
                q.addWhere(new DAL.WhereConds("item_name", item));
                q.addWhere(new DAL.WhereConds("item_keyword", keyword));

                string dbResult;
                try
                {
                    dbResult = DAL.singleton().executeScalarSelect(q);
                }
                catch(MySqlException ex)
                {
                    GlobalFunctions.errorLog(ex);
                    dbResult = "0";
                }

                if (dbResult == "0")
                {
                    DAL.singleton().insert("categoryitems", "", item, "", keyword, "1");
                    newItems.Add(item);
                }
                else
                {
                    Dictionary<string, string> v = new Dictionary<string, string>
                                                       {
                                                           {
                                                               "item_updateflag",
                                                               "1"
                                                               }
                                                       };
                    DAL.singleton().update("categoryitems", v, 1, new DAL.WhereConds("item_name", item),
                                           new DAL.WhereConds("item_keyword", keyword));
                }
            }
            DAL.singleton().delete("categoryitems", 0, new DAL.WhereConds("item_updateflag", 0),
                                   new DAL.WhereConds("item_keyword", keyword));
            Dictionary<string, string> val = new Dictionary<string, string>
                                                 { { "item_updateflag", "0" } };
            DAL.singleton().update("categoryitems", val, 0);
            return newItems;
        }
Esempio n. 28
0
        //private string compileMessage( ArrayList items, string keyword )
        //{
        //    return compileMessage( items, keyword, "" , false);
        //}
        private static string compileMessage(ArrayList items, string keyword, string destination, bool forceShowAll)
        {
            // keywordHasItems: 0: count, 1: plural word(s), 2: items in category
            // keywordNoItems: 0: plural word(s)
            // keywordPlural
            // keywordSingular

            string fakedestination = destination == ">TWITTER<" ? "" : destination;

            bool showWaitTime = (fakedestination != "" && (Configuration.singleton()["showWaitTime", destination] == "true"));

            TimeSpan minimumWaitTime;

            if (
                !TimeSpan.TryParse(Configuration.singleton()["minimumWaitTime", destination],
                                   out minimumWaitTime))
            {
                minimumWaitTime = new TimeSpan(0);
            }

            bool shortenUrls = (fakedestination != "" && (Configuration.singleton()["useShortUrlsInsteadOfWikilinks", destination] == "true"));
            bool showDelta   = (fakedestination != "" && (Configuration.singleton()["catWatcherShowDelta", destination] == "true"));

            if (destination == ">TWITTER<")
            {
                shortenUrls = true;
                showDelta   = true;
            }

            if (forceShowAll)
            {
                showDelta = false;
            }

            string message;


            if (items != null && items.Count > 0)
            {
                string listString = "";
                foreach (string item in items)
                {
                    if (!shortenUrls)
                    {
                        listString += "[[" + item + "]]";
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(Configuration.singleton()["wikiUrl"] + item);
                            listString += IsGd.shorten(uri).ToString();
                        }
                        catch (UriFormatException ex)
                        {
                            listString += Configuration.singleton()["wikiUrl"] + item;
                            GlobalFunctions.errorLog(ex);
                        }
                    }

                    if (showWaitTime)
                    {
                        DAL.Select q = new DAL.Select("item_entrytime");
                        q.addWhere(new DAL.WhereConds("item_name", item));
                        q.addWhere(new DAL.WhereConds("item_keyword", keyword));
                        q.setFrom("categoryitems");

                        string   insertDate = DAL.singleton().executeScalarSelect(q);
                        DateTime realInsertDate;
                        if (!DateTime.TryParse(insertDate, out realInsertDate))
                        {
                            realInsertDate = DateTime.Now;
                        }

                        TimeSpan ts = DateTime.Now - realInsertDate;

                        if (ts >= minimumWaitTime)
                        {
                            string[] messageparams =
                            {
                                ts.Hours.ToString().PadLeft(2,   '0'),
                                ts.Minutes.ToString().PadLeft(2, '0'),
                                ts.Seconds.ToString().PadLeft(2, '0'),
                                ts.TotalDays >= 1 ? ((int)Math.Floor(ts.TotalDays)) + "d " : ""
                            };
                            listString += new Message().get("catWatcherWaiting", messageparams);
                        }
                    }

                    // trailing space added as a hack because MediaWiki doesn't preserve the trailing space :(
                    listString += new Message().get("listSeparator") + " ";
                }
                listString = listString.TrimEnd(' ', ',');
                string   pluralString  = items.Count == 1 ? new Message().get(keyword + "Singular", "keywordSingularDefault") : new Message().get(keyword + "Plural", "keywordPluralDefault");
                string[] messageParams = { items.Count.ToString(), pluralString, listString };
                message = new Message().get(keyword + (showDelta ? "New" : "") + "HasItems",
                                            messageParams);
            }
            else
            {
                string[] mp = { new Message().get(keyword + "Plural", "keywordPluralDefault") };
                message = new Message().get(keyword + "NoItems", mp);
            }
            return(message);
        }
Esempio n. 29
0
        /// <summary>
        /// Adds the watcher to channel.
        /// </summary>
        /// <param name="keyword">The keyword.</param>
        /// <param name="channel">The channel.</param>
        /// <returns></returns>
        public bool addWatcherToChannel(string keyword, string channel)
        {
            string channelId = Configuration.singleton().getChannelId(channel);
            int watcherId = getWatcherId(keyword);

            DAL.Select q = new DAL.Select("COUNT(*)");
            q.setFrom("channelwatchers");
            q.addWhere(new DAL.WhereConds("cw_channel", channelId));
            q.addWhere(new DAL.WhereConds("cw_watcher", watcherId));
            string count = DAL.singleton().executeScalarSelect(q);

            if (count == "0")
            {
                DAL.singleton().insert("channelwatchers", channelId, watcherId.ToString());
                return true;
            }
            return false;
        }
Esempio n. 30
0
        /// <summary>
        /// Gets the block information for a user or IP address on a wiki.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="channel">The channel the command was requested in.</param>
        /// <returns></returns>
        public BlockInformation getBlockInformation(string userName, string channel)
        {
            IPAddress ip;

            string baseWiki = Configuration.singleton()["baseWiki",channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);

            string apiParams = "?action=query&list=blocks&bk";
            if (IPAddress.TryParse(userName, out ip))
            {
                apiParams += "ip";
            }
            else
            {
                apiParams += "users";
            }
            apiParams += "=" + userName + "&format=xml";
            XmlTextReader creader = new XmlTextReader(HttpRequest.get(api + apiParams));

            while (creader.Name != "blocks")
            {
                creader.Read();
            }
            creader.Read();

            if ( creader.Name != "block" )
                return new BlockInformation( );
            BlockInformation bi = new BlockInformation
                                      {
                                          id = creader.GetAttribute( "id" ),
                                          target =
                                              creader.GetAttribute( "user" ),
                                          blockedBy =
                                              creader.GetAttribute( "by" ),
                                          start =
                                              creader.GetAttribute(
                                                  "timestamp" ),
                                          expiry =
                                              creader.GetAttribute( "expiry" ),
                                          blockReason =
                                              creader.GetAttribute( "reason" ),
                                          autoblock =
                                              creader.GetAttribute(
                                                  "autoblock" ) == ""
                                                  ? true
                                                  : false,
                                          nocreate =
                                              creader.GetAttribute(
                                                  "nocreate" ) == ""
                                                  ? true
                                                  : false,
                                          noemail =
                                              creader.GetAttribute(
                                                  "noemail" ) == ""
                                                  ? true
                                                  : false,
                                          allowusertalk =
                                              creader.GetAttribute(
                                                  "allowusertalk" ) == ""
                                                  ? true
                                                  : false
                                      };

            return bi;
        }
Esempio n. 31
0
        private static void sendNewYearMessage(string places)
        {
            DAL.Select q = new DAL.Select("channel_name");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_enabled", "1"));

            foreach (object[] res in DAL.singleton().executeSelect(q))
            {
                string channel = res[ 0 ].ToString( );
                if ( Configuration.singleton()["newYearDateAlerting",channel] != "true" )
                    continue;
                string[ ] args = { places };
                string message = new Message().get( "newYearMessage", args );
                Helpmebot6.irc.ircPrivmsg( channel, message );
                new Twitter().updateStatus( message );
            }
        }
Esempio n. 32
0
        private void threadBody()
        {
            Logger.instance().addToLog("Starting ACC Notifications watcher", Logger.LogTypes.General);
            try
            {
                DAL.Select query = new DAL.Select("notif_id", "notif_text", "notif_type");
                query.setFrom("acc_notifications");
                query.addLimit(1, 0);
                query.addOrder(new DAL.Select.Order("notif_id", true));

                while (true)
                {
                    Thread.Sleep(5000);

                    ArrayList data = DAL.singleton().executeSelect(query);

                    if (data.Count == 0)
                    {
                        continue;
                    }

                    foreach (object raw in data)
                    {
                        var d    = (object[])raw;
                        var id   = (int)d[0];
                        var text = (string)d[1];
                        var type = (int)d[2];

                        var destination = "##helpmebot";

                        switch (type)
                        {
                        case 1:
                            destination = "#wikipedia-en-accounts";
                            break;

                        case 2:
                            destination = "#wikipedia-en-accounts-devs";
                            break;
                        }

                        DAL.singleton().delete("acc_notifications", 1, new DAL.WhereConds("notif_id", id));

                        if (Configuration.singleton()["silence", destination] == "false")
                        {
                            Helpmebot6.irc.ircPrivmsg(destination, text);
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                EventHandler temp = this.threadFatalError;
                if (temp != null)
                {
                    temp(this, new EventArgs());
                }
            }
            Helpmebot6.irc.ircPrivmsg("##helpmebot", "ACC Notifications watcher died");
            Logger.instance().addToLog("ACC Notifications watcher died.", Logger.LogTypes.Error);
        }
Esempio n. 33
0
        /// <summary>
        /// irc.wikimedia.org IRC connection registration succeeded event handler
        /// </summary>
        private void irc_ConnectionRegistrationSucceededEvent()
        {
            uint network = uint.Parse( Configuration.singleton( )[ "wikimediaRcNetwork" ] );

            DAL.Select q = new DAL.Select("channel_name");
            q.setFrom("channel");
            q.addWhere(new DAL.WhereConds("channel_enabled", 1));
            q.addWhere(new DAL.WhereConds("channel_network", network.ToString()));
            foreach (object[] item in DAL.singleton().executeSelect(q))
            {
                this._irc.ircJoin((string) (item[0]));
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Gets the block information for a user or IP address on a wiki.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="channel">The channel the command was requested in.</param>
        /// <returns></returns>
        public BlockInformation getBlockInformation(string userName, string channel)
        {
            IPAddress ip;

            string baseWiki = Configuration.singleton()["baseWiki", channel];

            DAL.Select q = new DAL.Select("site_api");
            q.setFrom("site");
            q.addWhere(new DAL.WhereConds("site_id", baseWiki));
            string api = DAL.singleton().executeScalarSelect(q);


            string apiParams = "?action=query&list=blocks&bk";

            if (IPAddress.TryParse(userName, out ip))
            {
                apiParams += "ip";
            }
            else
            {
                apiParams += "users";
            }
            apiParams += "=" + userName + "&format=xml";
            XmlTextReader creader = new XmlTextReader(HttpRequest.get(api + apiParams));

            while (creader.Name != "blocks")
            {
                creader.Read();
            }
            creader.Read();

            if (creader.Name != "block")
            {
                return(new BlockInformation( ));
            }
            BlockInformation bi = new BlockInformation
            {
                id     = creader.GetAttribute("id"),
                target =
                    creader.GetAttribute("user"),
                blockedBy =
                    creader.GetAttribute("by"),
                start =
                    creader.GetAttribute(
                        "timestamp"),
                expiry =
                    creader.GetAttribute("expiry"),
                blockReason =
                    creader.GetAttribute("reason"),
                autoblock =
                    creader.GetAttribute(
                        "autoblock") == ""
                                                  ? true
                                                  : false,
                nocreate =
                    creader.GetAttribute(
                        "nocreate") == ""
                                                  ? true
                                                  : false,
                noemail =
                    creader.GetAttribute(
                        "noemail") == ""
                                                  ? true
                                                  : false,
                allowusertalk =
                    creader.GetAttribute(
                        "allowusertalk") == ""
                                                  ? true
                                                  : false
            };

            return(bi);
        }