r107392 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107391‎ | r107392 | r107393 >
Date:16:06, 27 December 2011
Author:petrb
Status:deferred
Tags:
Comment:
inserted a new feature for watching the rc feed from irc
Modified paths:
  • /trunk/tools/wmib/Config.cs (modified) (history)
  • /trunk/tools/wmib/Core.cs (modified) (history)
  • /trunk/tools/wmib/Infobot.cs (modified) (history)
  • /trunk/tools/wmib/RClogs.cs (added) (history)
  • /trunk/tools/wmib/WMIB.csproj (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/Infobot.cs
@@ -1,4 +1,14 @@
2 -using System;
 2+//This program is free software: you can redistribute it and/or modify
 3+//it under the terms of the GNU General Public License as published by
 4+//the Free Software Foundation, either version 3 of the License, or
 5+//(at your option) any later version.
 6+
 7+//This program is distributed in the hope that it will be useful,
 8+//but WITHOUT ANY WARRANTY; without even the implied warranty of
 9+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10+//GNU General Public License for more details.
 11+
 12+using System;
313 using System.Collections.Generic;
414 using System.Threading;
515 using System.Text.RegularExpressions;
Index: trunk/tools/wmib/Config.cs
@@ -32,6 +32,7 @@
3333 /// </summary>
3434 public string log;
3535
 36+ public bool feed;
3637 public bool info;
3738
3839 /// <summary>
@@ -40,6 +41,11 @@
4142 public dictionary Keys;
4243
4344 /// <summary>
 45+ /// Recent changes
 46+ /// </summary>
 47+ public RecentChanges RC;
 48+
 49+ /// <summary>
4450 /// Configuration text
4551 /// </summary>
4652 private string conf;
@@ -69,7 +75,8 @@
7076 /// </summary>
7177 public void LoadConfig()
7278 {
73 - string conf_file = name + ".setting";
 79+ string conf_file = variables.config + "/" + name + ".setting";
 80+ RecentChanges.InsertSite();
7481 if (!File.Exists(conf_file))
7582 {
7683 File.WriteAllText(conf_file, "");
@@ -85,6 +92,10 @@
8693 {
8794 logged = bool.Parse(parseConfig(conf, "logged"));
8895 }
 96+ if (parseConfig(conf, "feed") != "")
 97+ {
 98+ feed = bool.Parse(parseConfig(conf, "feed"));
 99+ }
89100 if (parseConfig(conf, "infodb") != "")
90101 {
91102 info = bool.Parse(parseConfig(conf, "infodb"));
@@ -99,8 +110,9 @@
100111 conf = "";
101112 AddConfig("infodb", info.ToString());
102113 AddConfig("logged", logged.ToString());
 114+ AddConfig("feed", feed.ToString());
103115 AddConfig("keysdb", keydb);
104 - File.WriteAllText(name + ".setting", conf);
 116+ File.WriteAllText(variables.config + "/" + name + ".setting", conf);
105117 }
106118
107119 /// <summary>
@@ -110,11 +122,13 @@
111123 public channel(string Name)
112124 {
113125 conf = "";
114 - keydb = Name + ".db";
 126+ keydb = variables.config + "/" + Name + ".db";
115127 info = true;
 128+ feed = false;
116129 logged = false;
117130 name = Name;
118131 LoadConfig();
 132+ RC = new RecentChanges(this);
119133 if (!Directory.Exists("log"))
120134 {
121135 Directory.CreateDirectory("log");
@@ -153,7 +167,7 @@
154168 text = text + current.name + ",\n";
155169 }
156170 text = text + ";";
157 - File.WriteAllText("wmib", text);
 171+ File.WriteAllText(variables.config + "/wmib", text);
158172 }
159173
160174 /// <summary>
@@ -181,7 +195,11 @@
182196 {
183197 try
184198 {
185 - text = File.ReadAllText("wmib");
 199+ if (System.IO.Directory.Exists(variables.config) == false)
 200+ {
 201+ System.IO.Directory.CreateDirectory(variables.config);
 202+ }
 203+ text = File.ReadAllText(variables.config + "/wmib");
186204 foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(','))
187205 {
188206 string name = x.Replace(" ", "");
Index: trunk/tools/wmib/Core.cs
@@ -18,6 +18,13 @@
1919
2020 namespace wmib
2121 {
 22+ public class variables
 23+ {
 24+ /// <summary>
 25+ /// Configuration directory
 26+ /// </summary>
 27+ public static readonly string config = "configuration";
 28+ }
2229 public class misc
2330 {
2431 public static bool IsValidRegex(string pattern)
@@ -36,13 +43,15 @@
3744 return true;
3845 }
3946 }
 47+
4048 public class irc
4149 {
4250 public static Thread _Queue;
4351 private static System.Net.Sockets.NetworkStream data;
4452 public static Thread dumphtmt;
 53+ public static Thread rc;
4554 public static Thread check_thread;
46 - public static StreamReader rd;
 55+ private static StreamReader rd;
4756 private static StreamWriter wd;
4857 private static List<user> User = new List<user>();
4958
@@ -106,7 +115,7 @@
107116 foreach (Message message in messages)
108117 {
109118 irc.Message(message.message, message.channel);
110 - Thread.Sleep(2000);
 119+ Thread.Sleep(1000);
111120 }
112121 messages.Clear();
113122 locked = false;
@@ -186,20 +195,20 @@
187196 public IRCTrust(string channel)
188197 {
189198 // Load
190 - File = channel + "_user";
 199+ File = variables.config + "/" + channel + "_user";
191200 if (!System.IO.File.Exists(File))
192201 {
193202 // Create db
194203 Program.Log("Creating user file for " + channel);
195204 System.IO.File.WriteAllText(File, "");
196205 }
197 - if (!System.IO.File.Exists("admins"))
 206+ if (!System.IO.File.Exists(variables.config + "/" + "admins"))
198207 {
199208 // Create db
200209 Program.Log("Creating user file for admins");
201 - System.IO.File.WriteAllText("admins", "");
 210+ System.IO.File.WriteAllText(variables.config + "/" + "admins", "");
202211 }
203 - string[] db = System.IO.File.ReadAllLines(channel + "_user");
 212+ string[] db = System.IO.File.ReadAllLines(File);
204213 _Channel = channel;
205214 foreach (string x in db)
206215 {
@@ -211,7 +220,7 @@
212221 Users.Add(new user(level, name));
213222 }
214223 }
215 - string[] dba = System.IO.File.ReadAllLines("admins");
 224+ string[] dba = System.IO.File.ReadAllLines(variables.config + "/" + "admins");
216225 _Channel = channel;
217226 foreach (string x in dba)
218227 {
@@ -737,8 +746,12 @@
738747 }
739748 catch (Exception)
740749 { }
741 - File.Delete(chan.name + ".setting");
742 - File.Delete(chan.Users.File);
 750+ File.Delete(variables.config + "/" + chan.name + ".setting");
 751+ File.Delete(variables.config + "/" + chan.Users.File);
 752+ if (File.Exists(variables.config + "/" + chan.name + ".list"))
 753+ {
 754+ File.Delete(variables.config + "/" + chan.name + ".list");
 755+ }
743756 config.channels.Remove(chan);
744757 config.Save();
745758 return;
@@ -803,6 +816,161 @@
804817 Message(messages.PermissionDenied, chan.name);
805818 return;
806819 }
 820+
 821+ if (message == "@recentchanges-on")
 822+ {
 823+ if (chan.Users.isApproved(user, host, "admin"))
 824+ {
 825+ if (chan.feed)
 826+ {
 827+ Message("Channel had already feed enabled", chan.name);
 828+ return;
 829+ }
 830+ else
 831+ {
 832+ Message("Feed is enabled", chan.name);
 833+ chan.feed = true;
 834+ chan.SaveConfig();
 835+ config.Save();
 836+ return;
 837+ }
 838+ }
 839+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 840+ return;
 841+ }
 842+
 843+ if (message.StartsWith("@recentchanges+"))
 844+ {
 845+ if (chan.Users.isApproved(user, host, "admin"))
 846+ {
 847+ if (chan.feed)
 848+ {
 849+ if (!message.Contains(" "))
 850+ {
 851+ SlowQueue.DeliverMessage("Invalid wiki", chan.name);
 852+ return;
 853+ }
 854+ string channel = message.Substring(message.IndexOf(" ") + 1);
 855+ if (RecentChanges.InsertChannel(chan, channel))
 856+ {
 857+ Message("Wiki inserted", chan.name);
 858+ }
 859+ return;
 860+ }
 861+ else
 862+ {
 863+ Message("Channel doesn't have enabled recent changes", chan.name);
 864+ return;
 865+ }
 866+ }
 867+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 868+ return;
 869+ }
 870+
 871+ if (message.StartsWith("@recentchanges- "))
 872+ {
 873+ if (chan.Users.isApproved(user, host, "admin"))
 874+ {
 875+ if (chan.feed)
 876+ {
 877+ if (!message.Contains(" "))
 878+ {
 879+ SlowQueue.DeliverMessage("Invalid wiki", chan.name);
 880+ return;
 881+ }
 882+ string channel = message.Substring(message.IndexOf(" ") + 1);
 883+ if (RecentChanges.DeleteChannel(chan, channel))
 884+ {
 885+ Message("Wiki deleted", chan.name);
 886+ }
 887+ return;
 888+ }
 889+ else
 890+ {
 891+ Message("Channel doesn't have enabled recent changes", chan.name);
 892+ return;
 893+ }
 894+ }
 895+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 896+ return;
 897+ }
 898+
 899+ if (message.StartsWith("@RC+ "))
 900+ {
 901+ if (chan.Users.isApproved(user, host, "trust"))
 902+ {
 903+ if (chan.feed)
 904+ {
 905+ string[] a = message.Split(' ');
 906+ if (a.Length < 3)
 907+ {
 908+ SlowQueue.DeliverMessage("Error, " + user + ": Wrong number of parameters!", chan.name);
 909+ return;
 910+ }
 911+ string wiki = a[1];
 912+ string Page = a[2];
 913+ chan.RC.insertString(wiki, Page);
 914+ return;
 915+ }
 916+ else
 917+ {
 918+ SlowQueue.DeliverMessage("Channel doesn't have enabled recent changes", chan.name);
 919+ return;
 920+ }
 921+ }
 922+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 923+ return;
 924+ }
 925+
 926+ if (message.StartsWith("@RC-"))
 927+ {
 928+ if (chan.Users.isApproved(user, host, "trust"))
 929+ {
 930+ if (chan.feed)
 931+ {
 932+ string[] a = message.Split(' ');
 933+ if (a.Length < 3)
 934+ {
 935+ SlowQueue.DeliverMessage("Error, " + user + ": Wrong number of parameters!", chan.name);
 936+ return;
 937+ }
 938+ string wiki = a[1];
 939+ string Page = a[2];
 940+ chan.RC.removeString(wiki, Page);
 941+ return;
 942+ }
 943+ else
 944+ {
 945+ SlowQueue.DeliverMessage("Channel doesn't have enabled recent changes", chan.name);
 946+ return;
 947+ }
 948+ }
 949+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 950+ return;
 951+ }
 952+
 953+ if (message == "@recentchanges-off")
 954+ {
 955+ if (chan.Users.isApproved(user, host, "admin"))
 956+ {
 957+ if (!chan.feed)
 958+ {
 959+ Message("Channel had already feed disabled", chan.name);
 960+ return;
 961+ }
 962+ else
 963+ {
 964+ Message("Feed disabled", chan.name);
 965+ chan.feed = false;
 966+ chan.SaveConfig();
 967+ config.Save();
 968+ return;
 969+ }
 970+ }
 971+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
 972+ return;
 973+ }
 974+
807975 if (message == "@logon")
808976 {
809977 if (chan.Users.isApproved(user, host, "admin"))
@@ -824,12 +992,13 @@
825993 SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
826994 return;
827995 }
 996+
828997 if (message == "@whoami")
829998 {
830999 user current = chan.Users.getUser(user + "!@" + host);
8311000 if (current.level == "null")
8321001 {
833 - Message("You are unknown to me :)", chan.name);
 1002+ SlowQueue.DeliverMessage("You are unknown to me :)", chan.name);
8341003 return;
8351004 }
8361005 Message("You are " + current.level + " identified by name " + current.name, chan.name);
@@ -908,7 +1077,7 @@
9091078 }
9101079 if (message == "@commands")
9111080 {
912 - Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add, reload, logon, logoff", chan.name);
 1081+ Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add, reload, RC-, recentchanges-on, recentchanges-off, logon, logoff, recentchanges-, recentchanges+, RC+", chan.name);
9131082 return;
9141083 }
9151084 }
@@ -966,6 +1135,7 @@
9671136 {
9681137 Thread.Sleep(2000);
9691138 wd.WriteLine("JOIN " + ch.name);
 1139+ wd.Flush();
9701140 }
9711141 SlowQueue.newmessages.Clear();
9721142 SlowQueue.messages.Clear();
@@ -987,6 +1157,8 @@
9881158 _Queue = new Thread(SlowQueue.Run);
9891159 dumphtmt = new Thread(HtmlDump.Start);
9901160 dumphtmt.Start();
 1161+ rc = new Thread(RecentChanges.Start);
 1162+ rc.Start();
9911163 check_thread = new Thread(Ping);
9921164 check_thread.Start();
9931165
@@ -1002,6 +1174,7 @@
10031175 {
10041176 if (ch.name != "")
10051177 {
 1178+ wd.Flush();
10061179 wd.WriteLine("JOIN " + ch.name);
10071180 Thread.Sleep(2000);
10081181 }
Index: trunk/tools/wmib/RClogs.cs
@@ -0,0 +1,394 @@
 2+using System;
 3+using System.Collections.Generic;
 4+using System.Text;
 5+using System.IO;
 6+
 7+namespace wmib
 8+{
 9+ public class RecentChanges
 10+ {
 11+ public class IWatch
 12+ {
 13+ public string Channel;
 14+ public string Page;
 15+ public wiki URL;
 16+ public IWatch(wiki site, string page, string channel)
 17+ {
 18+ Channel = channel;
 19+ Page = page;
 20+ URL = site;
 21+ }
 22+ }
 23+ public class wiki
 24+ {
 25+ public string name;
 26+ public string channel;
 27+ public string url;
 28+ public wiki(string _channel, string _url, string _name)
 29+ {
 30+ url = _url;
 31+ name = _name;
 32+ channel = _channel;
 33+ }
 34+ }
 35+
 36+ private List<IWatch> pages = new List<IWatch>();
 37+ public static List<wiki> wikiinfo = new List<wiki>();
 38+ private static List<string> channels;
 39+ private static List<RecentChanges> rc = new List<RecentChanges>();
 40+ private static StreamReader RD;
 41+ private static string channeldata = variables.config + "/feed";
 42+ public static StreamWriter WD;
 43+ public static System.Net.Sockets.NetworkStream stream;
 44+ public static System.Text.RegularExpressions.Regex line = new System.Text.RegularExpressions.Regex(":rc-pmtpa!~rc-pmtpa@[^ ]* PRIVMSG #[^:]*:14\\[\\[07([^]*)14\\]\\]4 (M?)(B?)10 02.*di" +
 45+ "ff=([^&]*)&oldid=([^]*) 5\\* 03([^]*) 5\\* \\(?([^]*)?\\) 10([^]*)?");
 46+ public config.channel channel;
 47+ public RecentChanges(config.channel _channel)
 48+ {
 49+ channel = _channel;
 50+ Load();
 51+ rc.Add(this);
 52+ }
 53+
 54+ public static bool InsertChannel(config.channel target, string name)
 55+ {
 56+ wiki web = null;
 57+ foreach (wiki site in wikiinfo)
 58+ {
 59+ if (name == site.name)
 60+ {
 61+ web = site;
 62+ break;
 63+ }
 64+ }
 65+ if (web == null)
 66+ {
 67+ irc.Message("There is no such a wiki in list of wikis", target.name);
 68+ return false;
 69+ }
 70+ if (channels.Contains(web.channel))
 71+ {
 72+ irc.Message("This channel is already watched", target.name);
 73+ return false;
 74+ }
 75+ channels.Add(web.channel);
 76+ WD.WriteLine("JOIN " + web.channel);
 77+ WD.Flush();
 78+ System.IO.File.WriteAllText(channeldata, "");
 79+ foreach (string x in channels)
 80+ {
 81+ System.IO.File.AppendAllText(channeldata, x + "\n");
 82+ }
 83+ return true;
 84+ }
 85+
 86+ public static bool DeleteChannel(config.channel target, string WikiName)
 87+ {
 88+ wiki W = null;
 89+ foreach (wiki site in wikiinfo)
 90+ {
 91+ if (WikiName == site.name)
 92+ {
 93+ W = site;
 94+ break;
 95+ }
 96+ }
 97+ if (W == null)
 98+ {
 99+ irc.Message("There is no such a wiki in list of wikis", target.name);
 100+ return false;
 101+ }
 102+ if (!channels.Contains(W.channel))
 103+ {
 104+ irc.Message("This channel is already not being watched", target.name);
 105+ return false;
 106+ }
 107+ channels.Remove(W.channel);
 108+ WD.WriteLine("PART " + W.channel);
 109+ WD.Flush();
 110+ System.IO.File.WriteAllText(channeldata, "");
 111+ foreach (string x in channels)
 112+ {
 113+ System.IO.File.AppendAllText(channeldata, x + "\n");
 114+ }
 115+ return true;
 116+ }
 117+
 118+ public static void Connect()
 119+ {
 120+ stream = new System.Net.Sockets.TcpClient("irc.wikimedia.org", 6667).GetStream();
 121+ WD = new StreamWriter(stream);
 122+ RD = new StreamReader(stream, System.Text.Encoding.UTF8);
 123+ System.Threading.Thread pinger = new System.Threading.Thread(Pong);
 124+ WD.WriteLine("USER " + "wm-bot" + " 8 * :" + "wm-bot");
 125+ WD.WriteLine("NICK " + "wm-bot" + System.DateTime.Now.ToShortDateString().Replace("/", "").Replace(":", "").Replace("\\", "").Replace(".", ""));
 126+ WD.Flush();
 127+ pinger.Start();
 128+ foreach (string b in channels)
 129+ {
 130+ System.Threading.Thread.Sleep(800);
 131+ WD.WriteLine("JOIN " + b);
 132+ WD.Flush();
 133+ }
 134+ }
 135+
 136+ /// <summary>
 137+ /// get the wiki from a name
 138+ /// </summary>
 139+ /// <param name="Name"></param>
 140+ /// <returns></returns>
 141+ private static wiki getWiki(string Name)
 142+ {
 143+ foreach (wiki curr in wikiinfo)
 144+ {
 145+ if (curr.name == Name)
 146+ {
 147+ return curr;
 148+ }
 149+ }
 150+ return null;
 151+ }
 152+
 153+ /// <summary>
 154+ /// Load the list
 155+ /// </summary>
 156+ public void Load()
 157+ {
 158+ string name = variables.config + "/" + channel.name + ".list";
 159+ if (File.Exists(name))
 160+ {
 161+ string[] content = File.ReadAllLines(name);
 162+ pages.Clear();
 163+ foreach (string value in content)
 164+ {
 165+ string[] values = value.Split('|');
 166+ if (values.Length == 3)
 167+ {
 168+ pages.Add(new IWatch(getWiki(values[0]), values[1].Replace("<separator>", "|"), values[2]));
 169+ }
 170+ }
 171+ }
 172+ }
 173+
 174+ /// <summary>
 175+ /// Save the list
 176+ /// </summary>
 177+ public void Save()
 178+ {
 179+ string dbn = variables.config + "/" + channel.name + ".list";
 180+ string content = "";
 181+ foreach (IWatch values in pages)
 182+ {
 183+ content = content + values.URL.name + "|" + values.Page.Replace("|", "<separator>") + "|" + values.Channel;
 184+ }
 185+ File.WriteAllText(dbn, content);
 186+ }
 187+
 188+ private static void Pong()
 189+ {
 190+ while (true)
 191+ {
 192+ WD.WriteLine("PING irc.wikimedia.org");
 193+ WD.Flush();
 194+ System.Threading.Thread.Sleep(10000);
 195+ }
 196+ }
 197+
 198+ public bool removeString(string WS, string Page)
 199+ {
 200+ Page = Page.Replace("_", " ");
 201+ wiki site = null;
 202+ foreach (wiki Site in wikiinfo)
 203+ {
 204+ if (Site.name == WS)
 205+ {
 206+ site = Site;
 207+ }
 208+ }
 209+
 210+ if (site != null)
 211+ {
 212+ if (channels.Contains(site.channel))
 213+ {
 214+ IWatch currpage = null;
 215+ foreach (IWatch iw in pages)
 216+ {
 217+ if (iw.Page == Page)
 218+ {
 219+ currpage = iw;
 220+ break;
 221+ }
 222+ }
 223+ if (pages.Contains(currpage))
 224+ {
 225+ pages.Remove(currpage);
 226+ Save();
 227+ irc.SlowQueue.DeliverMessage("Deleted item from feed", channel.name);
 228+ return true;
 229+ }
 230+ irc.SlowQueue.DeliverMessage("Can't find item in a list", channel.name);
 231+ return true;
 232+ }
 233+ irc.SlowQueue.DeliverMessage("Unable to delete the string because the channel is not being watched now", channel.name);
 234+ return false;
 235+ }
 236+ irc.SlowQueue.DeliverMessage("Unable to delete the string from the list because there is no such wiki site known by a bot", channel.name);
 237+ return false;
 238+ }
 239+
 240+ public static int InsertSite()
 241+ {
 242+ wikiinfo.Add(new wiki("#cs.wikinews", "https://cs.wikipedia.org/w/index.php", "cs_wikinews"));
 243+ wikiinfo.Add(new wiki("#en.wikinews", "https://en.wikipedia.org/w/index.php", "en_wikinews"));
 244+ wikiinfo.Add(new wiki("#de.wikinews", "https://de.wikipedia.org/w/index.php", "de_wikinews"));
 245+ wikiinfo.Add(new wiki("#fr.wikinews", "https://fr.wikipedia.org/w/index.php", "fr_wikinews"));
 246+ wikiinfo.Add(new wiki("#pt.wikinews", "https://pt.wikipedia.org/w/index.php", "pt_wikinews"));
 247+ wikiinfo.Add(new wiki("#zh.wikinews", "https://fr.wikipedia.org/w/index.php", "zh_wikinews"));
 248+ wikiinfo.Add(new wiki("#es.wikinews", "https://fr.wikipedia.org/w/index.php", "es_wikinews"));
 249+ wikiinfo.Add(new wiki("#ru.wikinews", "https://fr.wikipedia.org/w/index.php", "ru_wikinews"));
 250+ wikiinfo.Add(new wiki("#it.wikinews", "https://fr.wikipedia.org/w/index.php", "it_wikinews"));
 251+ wikiinfo.Add(new wiki("#nl.wikinews", "https://fr.wikipedia.org/w/index.php", "nl_wikinews"));
 252+ wikiinfo.Add(new wiki("#ja.wikinews", "https://fr.wikipedia.org/w/index.php", "ja_wikinews"));
 253+ wikiinfo.Add(new wiki("#en.wiktionary", "https://en.wiktionary.org/w/index.php", "en_wiktionary"));
 254+ wikiinfo.Add(new wiki("#cs.wiktionary", "https://cs.wikipedia.org/w/index.php", "cs_wiktionary"));
 255+ wikiinfo.Add(new wiki("#de.wiktionary", "https://de.wikipedia.org/w/index.php", "de_wiktionary"));
 256+ wikiinfo.Add(new wiki("#fr.wiktionary", "https://fr.wikipedia.org/w/index.php", "fr_wiktionary"));
 257+ wikiinfo.Add(new wiki("#pt.wiktionary", "https://pt.wikipedia.org/w/index.php", "pt_wiktionary"));
 258+ wikiinfo.Add(new wiki("#zh.wiktionary", "https://fr.wikipedia.org/w/index.php", "zh_wiktionary"));
 259+ wikiinfo.Add(new wiki("#es.wiktionary", "https://fr.wikipedia.org/w/index.php", "es_wiktionary"));
 260+ wikiinfo.Add(new wiki("#ru.wiktionary", "https://fr.wikipedia.org/w/index.php", "ru_wiktionary"));
 261+ wikiinfo.Add(new wiki("#it.wiktionary", "https://fr.wikipedia.org/w/index.php", "it_wiktionary"));
 262+ wikiinfo.Add(new wiki("#nl.wiktionary", "https://fr.wikipedia.org/w/index.php", "nl_wiktionary"));
 263+ wikiinfo.Add(new wiki("#ja.wiktionary", "https://fr.wikipedia.org/w/index.php", "ja_wiktionary"));
 264+ wikiinfo.Add(new wiki("#cs.wikipedia", "https://cs.wikipedia.org/w/index.php", "cs_wikipedia"));
 265+ wikiinfo.Add(new wiki("#en.wikipedia", "https://en.wikipedia.org/w/index.php", "en_wikipedia"));
 266+ wikiinfo.Add(new wiki("#de.wikipedia", "https://de.wikipedia.org/w/index.php", "de_wikipedia"));
 267+ wikiinfo.Add(new wiki("#fr.wikipedia", "https://fr.wikipedia.org/w/index.php", "fr_wikipedia"));
 268+ wikiinfo.Add(new wiki("#pt.wikipedia", "https://pt.wikipedia.org/w/index.php", "pt_wikipedia"));
 269+ wikiinfo.Add(new wiki("#zh.wikipedia", "https://fr.wikipedia.org/w/index.php", "zh_wikipedia"));
 270+ wikiinfo.Add(new wiki("#es.wikipedia", "https://fr.wikipedia.org/w/index.php", "es_wikipedia"));
 271+ wikiinfo.Add(new wiki("#ru.wikipedia", "https://fr.wikipedia.org/w/index.php", "ru_wikipedia"));
 272+ wikiinfo.Add(new wiki("#it.wikipedia", "https://fr.wikipedia.org/w/index.php", "it_wikipedia"));
 273+ wikiinfo.Add(new wiki("#nl.wikipedia", "https://fr.wikipedia.org/w/index.php", "nl_wikipedia"));
 274+ wikiinfo.Add(new wiki("#ja.wikipedia", "https://fr.wikipedia.org/w/index.php", "ja_wikipedia"));
 275+ wikiinfo.Add(new wiki("#mediawiki.wikipedia", "https://www.mediawiki.org/w/index.php", "mediawiki"));
 276+ return 0;
 277+ }
 278+
 279+ public bool insertString(string WS, string Page)
 280+ {
 281+ wiki site = null;
 282+ Page = Page.Replace("_", " ");
 283+ foreach (wiki Site in wikiinfo)
 284+ {
 285+ if (Site.name == WS)
 286+ {
 287+ site = Site;
 288+ }
 289+ }
 290+ if (site != null)
 291+ {
 292+ if (channels.Contains(site.channel))
 293+ {
 294+ IWatch currpage = null;
 295+ foreach (IWatch iw in pages)
 296+ {
 297+ if (iw.Page == Page)
 298+ {
 299+ currpage = iw;
 300+ break;
 301+ }
 302+ }
 303+ if (pages.Contains(currpage))
 304+ {
 305+ irc.SlowQueue.DeliverMessage("There is already this string in a list of watched items", channel.name);
 306+ return true;
 307+ }
 308+ pages.Add(new IWatch(site, Page, site.channel));
 309+ irc.SlowQueue.DeliverMessage("Inserted new item to feed of changes", channel.name);
 310+ Save();
 311+ return true;
 312+ }
 313+ irc.SlowQueue.DeliverMessage("Unable to insert the string because the channel is not being watched now", channel.name);
 314+ return false;
 315+ }
 316+ irc.SlowQueue.DeliverMessage("Unable to insert the string to the list because there is no such wiki site known by a bot, contact some developer with svn access in order to insert it", channel.name);
 317+ return false;
 318+ }
 319+
 320+ public static void Start()
 321+ {
 322+ channels = new List<string>();
 323+ if (!File.Exists(channeldata))
 324+ {
 325+ File.WriteAllText(channeldata, "");
 326+ }
 327+ try
 328+ {
 329+ string[] list = System.IO.File.ReadAllLines(channeldata);
 330+ foreach (string chan in list)
 331+ {
 332+ channels.Add(chan);
 333+ }
 334+ Connect();
 335+ while (true)
 336+ {
 337+ try
 338+ {
 339+ string message;
 340+ while (!RD.EndOfStream)
 341+ {
 342+ message = RD.ReadLine();
 343+ System.Text.RegularExpressions.Match Edit = line.Match(message);
 344+ if (line.IsMatch(message))
 345+ {
 346+ string _channel = message.Substring(message.IndexOf("PRIVMSG"));
 347+ _channel = _channel.Substring(_channel.IndexOf("#"));
 348+ _channel = _channel.Substring(0, _channel.IndexOf(" "));
 349+ string username = Edit.Groups[6].Value;
 350+ string change = Edit.Groups[7].Value;
 351+ string page = Edit.Groups[1].Value;
 352+ string link = Edit.Groups[4].Value;
 353+ string summary = Edit.Groups[8].Value;
 354+
 355+ if (summary.Length > 20)
 356+ {
 357+ summary = summary.Substring(0, 16) + " ...";
 358+ }
 359+ foreach (RecentChanges curr in rc)
 360+ {
 361+ if (curr.channel.feed)
 362+ {
 363+ foreach (IWatch w in curr.pages)
 364+ {
 365+ if (w.Channel == _channel && page == w.Page)
 366+ {
 367+ irc.SlowQueue.DeliverMessage("Change on 12" + w.URL.name + "1 a page " + page + " was modified, summary: " + summary + " changed by " + username + " link " + w.URL.url + "?diff=" + link, curr.channel.name);
 368+ }
 369+ }
 370+ }
 371+ }
 372+ }
 373+ System.Threading.Thread.Sleep(100);
 374+ }
 375+ System.Threading.Thread.Sleep(100);
 376+ }
 377+ catch (System.IO.IOException)
 378+ {
 379+ Connect();
 380+ }
 381+ catch (Exception x)
 382+ {
 383+ Console.WriteLine(x.Message);
 384+ }
 385+ }
 386+
 387+ }
 388+ catch (Exception x)
 389+ {
 390+ Console.WriteLine(x.Message);
 391+ // abort
 392+ }
 393+ }
 394+ }
 395+}
Index: trunk/tools/wmib/WMIB.csproj
@@ -46,6 +46,7 @@
4747 <Compile Include="Infobot.cs" />
4848 <Compile Include="Program.cs" />
4949 <Compile Include="Properties\AssemblyInfo.cs" />
 50+ <Compile Include="RClogs.cs" />
5051 </ItemGroup>
5152 <ItemGroup>
5253 <None Include="app.config" />

Status & tagging log