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; }
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); }
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); }
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)); }
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); } }
/// <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(); }
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)); }
/// <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); }
/// <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); }
/// <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(); }
/// <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); }
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(); } }
/// <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(); }
/// <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)); }
/// <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); }
/// <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); }
/// <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; }
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)); }
//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; }
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); }
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; }
//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); }
/// <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; }
/// <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; }
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 ); } }
/// <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); }
/// <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])); } }