Index: trunk/tools/wmib/DumpHtm.cs |
— | — | @@ -103,6 +103,7 @@ |
104 | 104 | try |
105 | 105 | { |
106 | 106 | string text = CreateHeader(); |
| 107 | + text = text + "<h4>Infobot</h4>\n"; |
107 | 108 | text = text + "<table border=1 width=100%>\n<tr><td width=10%>Key</td><td>Value</td></tr>\n"; |
108 | 109 | Channel.Keys.locked = true; |
109 | 110 | if (Channel.Keys.text.Count > 0) |
— | — | @@ -112,8 +113,19 @@ |
113 | 114 | text += AddLine(Key.key, Key.text); |
114 | 115 | } |
115 | 116 | } |
| 117 | + text = text + "</table>\n"; |
| 118 | + text = text + "<h4>Aliases</h4>\n<table border=1 width=100%>\n"; |
| 119 | + foreach (dictionary.staticalias data in Channel.Keys.Alias) |
| 120 | + { |
| 121 | + text += AddLine(data.Name, data.Key); |
| 122 | + } |
| 123 | + text = text + "</table>\n"; |
116 | 124 | Channel.Keys.locked = false; |
117 | | - text = text + "<table>\n"; |
| 125 | + if (Channel.feed) |
| 126 | + { |
| 127 | + text += "<h4>Recent changes</h4>"; |
| 128 | + text = text + Channel.RC.ToTable(); |
| 129 | + } |
118 | 130 | text = text + CreateFooter(); |
119 | 131 | File.WriteAllText(dumpname, text); |
120 | 132 | } |
Index: trunk/tools/wmib/Core.cs |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | public static Thread dumphtmt; |
53 | 53 | public static Thread rc; |
54 | 54 | public static Thread check_thread; |
| 55 | + public static bool disabled; |
55 | 56 | private static StreamReader rd; |
56 | 57 | private static StreamWriter wd; |
57 | 58 | private static List<user> User = new List<user>(); |
— | — | @@ -178,7 +179,7 @@ |
179 | 180 | /// List of all users in a channel |
180 | 181 | /// </summary> |
181 | 182 | private List<user> Users = new List<user>(); |
182 | | - |
| 183 | + |
183 | 184 | /// <summary> |
184 | 185 | /// Channel this class belong to |
185 | 186 | /// </summary> |
— | — | @@ -500,11 +501,12 @@ |
501 | 502 | { |
502 | 503 | if (config.debugchan != null) |
503 | 504 | { |
504 | | - SlowQueue.DeliverMessage("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", config.debugchan); |
| 505 | + SlowQueue.DeliverMessage("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", config.debugchan); |
505 | 506 | } |
506 | 507 | Program.Log(ex.Message + ex.Source + ex.StackTrace); |
507 | | - } catch (Exception) // exception happened while we tried to handle another one, ignore that (probably issue with logging) |
508 | | - { } |
| 508 | + } |
| 509 | + catch (Exception) // exception happened while we tried to handle another one, ignore that (probably issue with logging) |
| 510 | + { } |
509 | 511 | } |
510 | 512 | |
511 | 513 | /// <summary> |
— | — | @@ -659,7 +661,7 @@ |
660 | 662 | timedateToString(DateTime.Now.Second) + "] " + "<" + |
661 | 663 | user + ">\t " + message + "\n"; |
662 | 664 | } |
663 | | - File.AppendAllText(channel.log + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt", log); |
| 665 | + File.AppendAllText(channel.log + DateTime.Now.Year + timedateToString(DateTime.Now.Month) + timedateToString(DateTime.Now.Day) + ".txt", log); |
664 | 666 | } |
665 | 667 | } |
666 | 668 | catch (Exception er) |
— | — | @@ -779,7 +781,7 @@ |
780 | 782 | File.Delete(variables.config + "/" + chan.name + ".list"); |
781 | 783 | } |
782 | 784 | } |
783 | | - catch (Exception) { } |
| 785 | + catch (Exception) { } |
784 | 786 | config.channels.Remove(chan); |
785 | 787 | config.Save(); |
786 | 788 | return; |
— | — | @@ -965,7 +967,7 @@ |
966 | 968 | } |
967 | 969 | else |
968 | 970 | { |
969 | | - SlowQueue.DeliverMessage ("Type @commands for list of commands. This bot is running http://meta.wikimedia.org/wiki/WM-Bot version " + config.version + " source code licensed under GPL and located in wikimedia svn", chan.name); |
| 971 | + SlowQueue.DeliverMessage("Type @commands for list of commands. This bot is running http://meta.wikimedia.org/wiki/WM-Bot version " + config.version + " source code licensed under GPL and located in wikimedia svn", chan.name); |
970 | 972 | return; |
971 | 973 | } |
972 | 974 | } |
— | — | @@ -1173,7 +1175,7 @@ |
1174 | 1176 | private static bool ShowHelp(string parameter, string channel) |
1175 | 1177 | { |
1176 | 1178 | switch (parameter.ToLower()) |
1177 | | - { |
| 1179 | + { |
1178 | 1180 | case "trustdel": |
1179 | 1181 | showInfo("trustdel", "Remove an entry from access list, example @trustdel regex", channel); |
1180 | 1182 | return false; |
— | — | @@ -1272,140 +1274,148 @@ |
1273 | 1275 | /// <returns></returns> |
1274 | 1276 | public static void Connect() |
1275 | 1277 | { |
1276 | | - data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
1277 | | - rd = new System.IO.StreamReader(data, System.Text.Encoding.UTF8); |
1278 | | - wd = new System.IO.StreamWriter(data); |
| 1278 | + try |
| 1279 | + { |
| 1280 | + data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
| 1281 | + rd = new System.IO.StreamReader(data, System.Text.Encoding.UTF8); |
| 1282 | + wd = new System.IO.StreamWriter(data); |
1279 | 1283 | |
1280 | | - _Queue = new Thread(SlowQueue.Run); |
1281 | | - dumphtmt = new Thread(HtmlDump.Start); |
1282 | | - dumphtmt.Start(); |
1283 | | - rc = new Thread(RecentChanges.Start); |
1284 | | - rc.Start(); |
1285 | | - check_thread = new Thread(Ping); |
1286 | | - check_thread.Start(); |
| 1284 | + _Queue = new Thread(SlowQueue.Run); |
| 1285 | + dumphtmt = new Thread(HtmlDump.Start); |
| 1286 | + dumphtmt.Start(); |
| 1287 | + rc = new Thread(RecentChanges.Start); |
| 1288 | + rc.Start(); |
| 1289 | + check_thread = new Thread(Ping); |
| 1290 | + check_thread.Start(); |
1287 | 1291 | |
1288 | | - wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
1289 | | - wd.WriteLine("NICK " + config.username); |
| 1292 | + wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
| 1293 | + wd.WriteLine("NICK " + config.username); |
1290 | 1294 | |
1291 | | - _Queue.Start(); |
1292 | | - Thread.Sleep(2000); |
| 1295 | + _Queue.Start(); |
| 1296 | + Thread.Sleep(2000); |
1293 | 1297 | |
1294 | | - Authenticate(); |
| 1298 | + Authenticate(); |
1295 | 1299 | |
1296 | | - foreach (config.channel ch in config.channels) |
1297 | | - { |
1298 | | - if (ch.name != "") |
| 1300 | + foreach (config.channel ch in config.channels) |
1299 | 1301 | { |
1300 | | - wd.Flush(); |
1301 | | - wd.WriteLine("JOIN " + ch.name); |
1302 | | - Thread.Sleep(2000); |
| 1302 | + if (ch.name != "") |
| 1303 | + { |
| 1304 | + wd.Flush(); |
| 1305 | + wd.WriteLine("JOIN " + ch.name); |
| 1306 | + Thread.Sleep(2000); |
| 1307 | + } |
1303 | 1308 | } |
1304 | | - } |
1305 | | - wd.Flush(); |
1306 | | - string text = ""; |
1307 | | - string nick = ""; |
1308 | | - string host = ""; |
1309 | | - string message = ""; |
1310 | | - string channel = ""; |
1311 | | - char delimiter = (char)001; |
| 1309 | + wd.Flush(); |
| 1310 | + string text = ""; |
| 1311 | + string nick = ""; |
| 1312 | + string host = ""; |
| 1313 | + string message = ""; |
| 1314 | + string channel = ""; |
| 1315 | + char delimiter = (char)001; |
1312 | 1316 | |
1313 | | - while (true) |
1314 | | - { |
1315 | | - try |
| 1317 | + while (!disabled) |
1316 | 1318 | { |
1317 | | - while (!rd.EndOfStream) |
| 1319 | + try |
1318 | 1320 | { |
1319 | | - text = rd.ReadLine(); |
1320 | | - if (text.StartsWith(":")) |
| 1321 | + while (!rd.EndOfStream) |
1321 | 1322 | { |
1322 | | - string check = text.Substring(text.IndexOf(" ")); |
1323 | | - if (check.StartsWith(" 005")) |
| 1323 | + text = rd.ReadLine(); |
| 1324 | + if (text.StartsWith(":")) |
1324 | 1325 | { |
| 1326 | + string check = text.Substring(text.IndexOf(" ")); |
| 1327 | + if (check.StartsWith(" 005")) |
| 1328 | + { |
1325 | 1329 | |
1326 | | - } |
1327 | | - else |
1328 | | - { |
1329 | | - if (text.Contains("PRIVMSG")) |
| 1330 | + } |
| 1331 | + else |
1330 | 1332 | { |
1331 | | - string info = text.Substring(1, text.IndexOf(" :", 1) - 1); |
1332 | | - string info_host; |
1333 | | - // we got a message here :) |
1334 | | - if (text.Contains("!") && text.Contains("@")) |
| 1333 | + if (text.Contains("PRIVMSG")) |
1335 | 1334 | { |
1336 | | - nick = info.Substring(0, info.IndexOf("!")); |
1337 | | - host = info.Substring(info.IndexOf("@") + 1, info.IndexOf(" ", info.IndexOf("@")) - 1 - info.IndexOf("@")); |
1338 | | - } |
1339 | | - info_host = info.Substring(info.IndexOf("PRIVMSG ")); |
| 1335 | + string info = text.Substring(1, text.IndexOf(" :", 1) - 1); |
| 1336 | + string info_host; |
| 1337 | + // we got a message here :) |
| 1338 | + if (text.Contains("!") && text.Contains("@")) |
| 1339 | + { |
| 1340 | + nick = info.Substring(0, info.IndexOf("!")); |
| 1341 | + host = info.Substring(info.IndexOf("@") + 1, info.IndexOf(" ", info.IndexOf("@")) - 1 - info.IndexOf("@")); |
| 1342 | + } |
| 1343 | + info_host = info.Substring(info.IndexOf("PRIVMSG ")); |
1340 | 1344 | |
1341 | | - if (info_host.Contains("#")) |
1342 | | - { |
1343 | | - channel = info_host.Substring(info_host.IndexOf("#")); |
1344 | | - message = text.Replace(info, ""); |
1345 | | - message = message.Substring(message.IndexOf(" :") + 2); |
1346 | | - if (message.Contains(delimiter.ToString() + "ACTION")) |
| 1345 | + if (info_host.Contains("#")) |
1347 | 1346 | { |
1348 | | - getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, host, nick); |
1349 | | - continue; |
| 1347 | + channel = info_host.Substring(info_host.IndexOf("#")); |
| 1348 | + message = text.Replace(info, ""); |
| 1349 | + message = message.Substring(message.IndexOf(" :") + 2); |
| 1350 | + if (message.Contains(delimiter.ToString() + "ACTION")) |
| 1351 | + { |
| 1352 | + getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, host, nick); |
| 1353 | + continue; |
| 1354 | + } |
| 1355 | + else |
| 1356 | + { |
| 1357 | + getMessage(channel, nick, host, message); |
| 1358 | + continue; |
| 1359 | + } |
1350 | 1360 | } |
1351 | 1361 | else |
1352 | 1362 | { |
1353 | | - getMessage(channel, nick, host, message); |
1354 | | - continue; |
| 1363 | + message = text.Substring(text.IndexOf("PRIVMSG")); |
| 1364 | + message = message.Substring(message.IndexOf(":")); |
| 1365 | + // private message |
| 1366 | + if (message.StartsWith(":" + delimiter.ToString() + "FINGER")) |
| 1367 | + { |
| 1368 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + " I am a bot don't finger me"); |
| 1369 | + wd.Flush(); |
| 1370 | + continue; |
| 1371 | + } |
| 1372 | + if (message.StartsWith(":" + delimiter.ToString() + "TIME")) |
| 1373 | + { |
| 1374 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + System.DateTime.Now.ToString()); |
| 1375 | + wd.Flush(); |
| 1376 | + continue; |
| 1377 | + } |
| 1378 | + if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
| 1379 | + { |
| 1380 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING") + 5)); |
| 1381 | + wd.Flush(); |
| 1382 | + continue; |
| 1383 | + } |
| 1384 | + if (message.StartsWith(":" + delimiter.ToString() + "VERSION")) |
| 1385 | + { |
| 1386 | + wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + config.version); |
| 1387 | + wd.Flush(); |
| 1388 | + continue; |
| 1389 | + } |
1355 | 1390 | } |
1356 | 1391 | } |
1357 | | - else |
| 1392 | + if (text.Contains("PING ")) |
1358 | 1393 | { |
1359 | | - message = text.Substring(text.IndexOf("PRIVMSG")); |
1360 | | - message = message.Substring(message.IndexOf(":")); |
1361 | | - // private message |
1362 | | - if (message.StartsWith(":" + delimiter.ToString() + "FINGER")) |
1363 | | - { |
1364 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + " I am a bot don't finger me"); |
1365 | | - wd.Flush(); |
1366 | | - continue; |
1367 | | - } |
1368 | | - if (message.StartsWith(":" + delimiter.ToString() + "TIME")) |
1369 | | - { |
1370 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + System.DateTime.Now.ToString()); |
1371 | | - wd.Flush(); |
1372 | | - continue; |
1373 | | - } |
1374 | | - if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
1375 | | - { |
1376 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING") + 5)); |
1377 | | - wd.Flush(); |
1378 | | - continue; |
1379 | | - } |
1380 | | - if (message.StartsWith(":" + delimiter.ToString() + "VERSION")) |
1381 | | - { |
1382 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + config.version); |
1383 | | - wd.Flush(); |
1384 | | - continue; |
1385 | | - } |
| 1394 | + wd.WriteLine("PONG " + text.Substring(text.IndexOf("PING ") + 5)); |
| 1395 | + wd.Flush(); |
1386 | 1396 | } |
1387 | 1397 | } |
1388 | | - if (text.Contains("PING ")) |
1389 | | - { |
1390 | | - wd.WriteLine("PONG " + text.Substring(text.IndexOf("PING ") + 5)); |
1391 | | - wd.Flush(); |
1392 | | - } |
1393 | 1398 | } |
| 1399 | + Thread.Sleep(50); |
1394 | 1400 | } |
1395 | | - Thread.Sleep(50); |
| 1401 | + Program.Log("Reconnecting, end of data stream"); |
| 1402 | + Reconnect(); |
1396 | 1403 | } |
1397 | | - Program.Log("Reconnecting, end of data stream"); |
1398 | | - Reconnect(); |
| 1404 | + catch (System.IO.IOException xx) |
| 1405 | + { |
| 1406 | + Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
| 1407 | + Reconnect(); |
| 1408 | + } |
| 1409 | + catch (Exception xx) |
| 1410 | + { |
| 1411 | + handleException(xx, channel); |
| 1412 | + } |
1399 | 1413 | } |
1400 | | - catch (System.IO.IOException xx) |
1401 | | - { |
1402 | | - Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
1403 | | - Reconnect(); |
1404 | | - } |
1405 | | - catch (Exception xx) |
1406 | | - { |
1407 | | - handleException(xx, channel); |
1408 | | - } |
1409 | 1414 | } |
| 1415 | + catch (Exception) |
| 1416 | + { |
| 1417 | + Console.WriteLine("RecentChanges disabled, no connection"); |
| 1418 | + disabled = true; |
| 1419 | + } |
1410 | 1420 | } |
1411 | 1421 | public static int Disconnect() |
1412 | 1422 | { |
Index: trunk/tools/wmib/RClogs.cs |
— | — | @@ -60,6 +60,8 @@ |
61 | 61 | /// Channels |
62 | 62 | /// </summary> |
63 | 63 | private static List<string> channels; |
| 64 | + public bool changed; |
| 65 | + private bool writable = true; |
64 | 66 | |
65 | 67 | private static List<RecentChanges> rc = new List<RecentChanges>(); |
66 | 68 | |
— | — | @@ -89,9 +91,31 @@ |
90 | 92 | } |
91 | 93 | } |
92 | 94 | |
| 95 | + public string ToTable() |
| 96 | + { |
| 97 | + string output = "<table>"; |
| 98 | + try |
| 99 | + { |
| 100 | + writable = false; |
| 101 | + foreach (IWatch b in pages) |
| 102 | + { |
| 103 | + output = output + "<tr><td>" + b.Channel + "</td><td>" + b.Page + "</td></tr>\n"; |
| 104 | + } |
| 105 | + output = output + "</table>"; |
| 106 | + writable = true; |
| 107 | + return output; |
| 108 | + } |
| 109 | + catch (Exception) |
| 110 | + { |
| 111 | + writable = true; |
| 112 | + return ""; |
| 113 | + } |
| 114 | + } |
| 115 | + |
93 | 116 | public RecentChanges(config.channel _channel) |
94 | 117 | { |
95 | 118 | channel = _channel; |
| 119 | + changed = false; |
96 | 120 | Load(); |
97 | 121 | rc.Add(this); |
98 | 122 | } |
— | — | @@ -225,6 +249,7 @@ |
226 | 250 | public void Load() |
227 | 251 | { |
228 | 252 | string name = variables.config + "/" + channel.name + ".list"; |
| 253 | + writable = false; |
229 | 254 | if (File.Exists(name)) |
230 | 255 | { |
231 | 256 | string[] content = File.ReadAllLines(name); |
— | — | @@ -238,6 +263,7 @@ |
239 | 264 | } |
240 | 265 | } |
241 | 266 | } |
| 267 | + writable = true; |
242 | 268 | } |
243 | 269 | |
244 | 270 | /// <summary> |
— | — | @@ -301,7 +327,12 @@ |
302 | 328 | } |
303 | 329 | if (pages.Contains(currpage)) |
304 | 330 | { |
| 331 | + while (!writable) |
| 332 | + { |
| 333 | + System.Threading.Thread.Sleep(100); |
| 334 | + } |
305 | 335 | pages.Remove(currpage); |
| 336 | + channel.Keys.update = true; |
306 | 337 | Save(); |
307 | 338 | irc.SlowQueue.DeliverMessage("Deleted item from feed", channel.name); |
308 | 339 | return true; |
— | — | @@ -314,13 +345,25 @@ |
315 | 346 | return false; |
316 | 347 | } |
317 | 348 | irc.SlowQueue.DeliverMessage( |
318 | | - "Unable to delete the string from the list because there is no such wiki site known by a bot", |
| 349 | + "Unable to delete the string from the list because there is no such a wiki site known by a bot", |
319 | 350 | channel.name); |
320 | 351 | return false; |
321 | 352 | } |
322 | 353 | |
323 | 354 | public static int InsertSite() |
324 | 355 | { |
| 356 | + if (File.Exists("sites")) |
| 357 | + { |
| 358 | + string[] content = File.ReadAllLines("sites"); |
| 359 | + foreach (string a in content) |
| 360 | + { |
| 361 | + string[] values = a.Split('|'); |
| 362 | + if (values.Length == 3) |
| 363 | + { |
| 364 | + wikiinfo.Add(new wiki(values[0], values[1], values[2])); |
| 365 | + } |
| 366 | + } |
| 367 | + } |
325 | 368 | wikiinfo.Add(new wiki("#cs.wikinews", "https://cs.wikipedia.org/w/index.php", "cs_wikinews")); |
326 | 369 | wikiinfo.Add(new wiki("#en.wikinews", "https://en.wikipedia.org/w/index.php", "en_wikinews")); |
327 | 370 | wikiinfo.Add(new wiki("#de.wikinews", "https://de.wikipedia.org/w/index.php", "de_wikinews")); |
— | — | @@ -389,8 +432,13 @@ |
390 | 433 | channel.name); |
391 | 434 | return true; |
392 | 435 | } |
| 436 | + while (!writable) |
| 437 | + { |
| 438 | + System.Threading.Thread.Sleep(100); |
| 439 | + } |
393 | 440 | pages.Add(new IWatch(site, Page, site.channel)); |
394 | 441 | irc.SlowQueue.DeliverMessage("Inserted new item to feed of changes", channel.name); |
| 442 | + channel.Keys.update = true; |
395 | 443 | Save(); |
396 | 444 | return true; |
397 | 445 | } |
— | — | @@ -439,10 +487,6 @@ |
440 | 488 | string link = Edit.Groups[4].Value; |
441 | 489 | string summary = Edit.Groups[8].Value; |
442 | 490 | |
443 | | - if (summary.Length > 20) |
444 | | - { |
445 | | - summary = summary.Substring(0, 16) + " ..."; |
446 | | - } |
447 | 491 | foreach (RecentChanges curr in rc) |
448 | 492 | { |
449 | 493 | if (curr.channel.feed) |
— | — | @@ -452,9 +496,9 @@ |
453 | 497 | if (w.Channel == _channel && page == w.Page) |
454 | 498 | { |
455 | 499 | irc.SlowQueue.DeliverMessage( |
456 | | - "Change on 12" + w.URL.name + "1 a page " + page + |
457 | | - " was modified, summary: " + summary + " changed by " + username + |
458 | | - " link " + w.URL.url + "?diff=" + link, curr.channel.name); |
| 500 | + "Change on 12" + w.URL.name + " a page " + page + |
| 501 | + " was modified," + " changed by " + username + |
| 502 | + " link " + w.URL.url + "?diff=" + link, curr.channel.name + " edit summary: " + summary); |
459 | 503 | } |
460 | 504 | } |
461 | 505 | } |