Index: trunk/tools/wmib/Core.cs |
— | — | @@ -284,17 +284,22 @@ |
285 | 285 | /// </summary> |
286 | 286 | /// <param name="user">Regex</param> |
287 | 287 | /// <returns>bool</returns> |
288 | | - public bool delUser(string user) |
| 288 | + public bool delUser(user trusted, string user) |
289 | 289 | { |
290 | 290 | foreach (user u in Users) |
291 | 291 | { |
292 | 292 | if (u.name == user) |
293 | 293 | { |
294 | | - if (u.level == "admin") |
| 294 | + if (getLevel("admin") > getLevel(trusted.level)) |
295 | 295 | { |
296 | | - Message("This user is admin which can't be deleted from db, sorry", _Channel); |
| 296 | + Message("This user has higher level than you, sorry", _Channel); |
297 | 297 | return true; |
298 | 298 | } |
| 299 | + if (u == trusted) |
| 300 | + { |
| 301 | + Message("You can't delete yourself from db", _Channel); |
| 302 | + return true; |
| 303 | + } |
299 | 304 | Users.Remove(u); |
300 | 305 | Save(); |
301 | 306 | Message("User was deleted from access list", _Channel); |
— | — | @@ -367,7 +372,7 @@ |
368 | 373 | string users_ok = ""; |
369 | 374 | foreach (user b in Users) |
370 | 375 | { |
371 | | - users_ok += " " + b.name + ","; |
| 376 | + users_ok += " " + b.name + " (16" + b.level + "1) " + ","; |
372 | 377 | } |
373 | 378 | Message("I trust: " + users_ok, _Channel); |
374 | 379 | } |
— | — | @@ -429,9 +434,14 @@ |
430 | 435 | { |
431 | 436 | while (true) |
432 | 437 | { |
433 | | - Thread.Sleep(20000); |
434 | | - wd.WriteLine("PING :" + config.network); |
435 | | - wd.Flush(); |
| 438 | + try |
| 439 | + { |
| 440 | + Thread.Sleep(20000); |
| 441 | + wd.WriteLine("PING :" + config.network); |
| 442 | + wd.Flush(); |
| 443 | + } |
| 444 | + catch (Exception) |
| 445 | + { } |
436 | 446 | } |
437 | 447 | } |
438 | 448 | |
— | — | @@ -588,7 +598,7 @@ |
589 | 599 | string x = rights_info[1]; |
590 | 600 | if (channel.Users.isApproved(user, host, "trustdel")) |
591 | 601 | { |
592 | | - channel.Users.delUser(rights_info[1]); |
| 602 | + channel.Users.delUser(channel.Users.getUser(user + "!@" + host), rights_info[1]); |
593 | 603 | return 0; |
594 | 604 | } |
595 | 605 | else |
— | — | @@ -924,6 +934,25 @@ |
925 | 935 | return; |
926 | 936 | } |
927 | 937 | |
| 938 | + if (message.StartsWith("@help")) |
| 939 | + { |
| 940 | + string parameter = ""; |
| 941 | + if (message.Contains(" ")) |
| 942 | + { |
| 943 | + parameter = message.Substring(message.IndexOf(" ") + 1); |
| 944 | + } |
| 945 | + if (parameter != "") |
| 946 | + { |
| 947 | + ShowHelp(parameter, chan.name); |
| 948 | + return; |
| 949 | + } |
| 950 | + else |
| 951 | + { |
| 952 | + 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); |
| 953 | + return; |
| 954 | + } |
| 955 | + } |
| 956 | + |
928 | 957 | if (message.StartsWith("@RC-")) |
929 | 958 | { |
930 | 959 | if (chan.Users.isApproved(user, host, "trust")) |
— | — | @@ -1079,7 +1108,7 @@ |
1080 | 1109 | } |
1081 | 1110 | if (message == "@commands") |
1082 | 1111 | { |
1083 | | - 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); |
| 1112 | + SlowQueue.DeliverMessage("Commands: channellist, trusted, trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add, reload, help, RC-, recentchanges-on, recentchanges-off, logon, logoff, recentchanges-, recentchanges+, RC+", chan.name); |
1084 | 1113 | return; |
1085 | 1114 | } |
1086 | 1115 | } |
— | — | @@ -1119,6 +1148,80 @@ |
1120 | 1149 | return false; |
1121 | 1150 | } |
1122 | 1151 | |
| 1152 | + private static void showInfo(string name, string info, string channel) |
| 1153 | + { |
| 1154 | + SlowQueue.DeliverMessage("Info for " + name + ": " + info, channel); |
| 1155 | + } |
| 1156 | + |
| 1157 | + private static bool ShowHelp(string parameter, string channel) |
| 1158 | + { |
| 1159 | + switch (parameter.ToLower()) |
| 1160 | + { |
| 1161 | + case "trustdel": |
| 1162 | + showInfo("trustdel", "Remove an entry from access list, example @trustdel regex", channel); |
| 1163 | + return false; |
| 1164 | + case "refresh": |
| 1165 | + showInfo("refresh", "Remove data from queue", channel); |
| 1166 | + return false; |
| 1167 | + case "infobot-on": |
| 1168 | + showInfo("infobot-on", "Turn on the infobot", channel); |
| 1169 | + return false; |
| 1170 | + case "infobot-off": |
| 1171 | + showInfo("infobot-off", "Turn off the infobot, preserve db", channel); |
| 1172 | + return false; |
| 1173 | + case "channellist": |
| 1174 | + showInfo("channellist", "Display the list of channels where bot should be used (only if it can join them)", channel); |
| 1175 | + return false; |
| 1176 | + case "trusted": |
| 1177 | + showInfo("trusted", "Display access list for this channel", channel); |
| 1178 | + return false; |
| 1179 | + case "trustadd": |
| 1180 | + showInfo("trustadd", "Make an entry to the access list, example @trustadd regex admin", channel); |
| 1181 | + return false; |
| 1182 | + case "drop": |
| 1183 | + showInfo("drop", "Remove bot from a channel together with all collected data", channel); |
| 1184 | + return false; |
| 1185 | + case "part": |
| 1186 | + showInfo("part", "Remove bot from a channel and preserve all config", channel); |
| 1187 | + return false; |
| 1188 | + case "whoami": |
| 1189 | + showInfo("whoami", "Display your current status in access list", channel); |
| 1190 | + return false; |
| 1191 | + case "add": |
| 1192 | + showInfo("add", "Insert bot to a specified channel and give you admin rights for that", channel); |
| 1193 | + return false; |
| 1194 | + case "reload": |
| 1195 | + showInfo("reload", "Read a config from disk", channel); |
| 1196 | + return false; |
| 1197 | + case "logon": |
| 1198 | + showInfo("logon", "Start logging to a file", channel); |
| 1199 | + return false; |
| 1200 | + case "logoff": |
| 1201 | + showInfo("logoff", "Disable logging", channel); |
| 1202 | + return false; |
| 1203 | + case "recentchanges-on": |
| 1204 | + showInfo("recentchanges-on", "Turn on a feed of changes on wmf wikis", channel); |
| 1205 | + return false; |
| 1206 | + case "recentchanges-off": |
| 1207 | + showInfo("recentchanges-off", "Turn off the wiki feed", channel); |
| 1208 | + return false; |
| 1209 | + case "recentchanges-": |
| 1210 | + showInfo("recentchanges-", "Remove a wiki from a feed, example @recentchanges- en_wikipedia", channel); |
| 1211 | + return false; |
| 1212 | + case "recentchanges+": |
| 1213 | + showInfo("recentchanges+", "Insert a wiki to feed, example @recentchanges+ en_wikipedia", channel); |
| 1214 | + return false; |
| 1215 | + case "RC-": |
| 1216 | + showInfo("RC-", "Remove a page from rc list", channel); |
| 1217 | + return false; |
| 1218 | + case "RC+": |
| 1219 | + showInfo("RC+", "Create entry for feed of specified page, example @RC+ wiki page", channel); |
| 1220 | + return false; |
| 1221 | + } |
| 1222 | + SlowQueue.DeliverMessage("Unknown command type @commands for a list of all commands I know", channel); |
| 1223 | + return false; |
| 1224 | + } |
| 1225 | + |
1123 | 1226 | /// <summary> |
1124 | 1227 | /// Connection |
1125 | 1228 | /// </summary> |
— | — | @@ -1294,94 +1397,3 @@ |
1295 | 1398 | } |
1296 | 1399 | } |
1297 | 1400 | } |
1298 | | - else |
1299 | | - { |
1300 | | - if (text.Contains("PRIVMSG")) |
1301 | | - { |
1302 | | - string info = text.Substring(1, text.IndexOf(" :", 1) - 1); |
1303 | | - string info_host; |
1304 | | - // we got a message here :) |
1305 | | - if (text.Contains("!") && text.Contains("@")) |
1306 | | - { |
1307 | | - nick = info.Substring(0, info.IndexOf("!")); |
1308 | | - host = info.Substring(info.IndexOf("@") + 1, info.IndexOf(" ", info.IndexOf("@")) - 1 - info.IndexOf("@")); |
1309 | | - } |
1310 | | - info_host = info.Substring(info.IndexOf("PRIVMSG ")); |
1311 | | - |
1312 | | - if (info_host.Contains("#")) |
1313 | | - { |
1314 | | - channel = info_host.Substring(info_host.IndexOf("#")); |
1315 | | - message = text.Replace(info, ""); |
1316 | | - message = message.Substring(message.IndexOf(" :") + 2); |
1317 | | - if (message.Contains(delimiter.ToString() + "ACTION")) |
1318 | | - { |
1319 | | - getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel, host, nick); |
1320 | | - continue; |
1321 | | - } |
1322 | | - else |
1323 | | - { |
1324 | | - getMessage(channel, nick, host, message); |
1325 | | - continue; |
1326 | | - } |
1327 | | - } |
1328 | | - else |
1329 | | - { |
1330 | | - message = text.Substring(text.IndexOf("PRIVMSG")); |
1331 | | - message = message.Substring(message.IndexOf(":")); |
1332 | | - // private message |
1333 | | - if (message.StartsWith(":" + delimiter.ToString() + "FINGER")) |
1334 | | - { |
1335 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + " I am a bot don't finger me"); |
1336 | | - wd.Flush(); |
1337 | | - continue; |
1338 | | - } |
1339 | | - if (message.StartsWith(":" + delimiter.ToString() + "TIME")) |
1340 | | - { |
1341 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + System.DateTime.Now.ToString()); |
1342 | | - wd.Flush(); |
1343 | | - continue; |
1344 | | - } |
1345 | | - if (message.StartsWith(":" + delimiter.ToString() + "PING")) |
1346 | | - { |
1347 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING") + 5)); |
1348 | | - wd.Flush(); |
1349 | | - continue; |
1350 | | - } |
1351 | | - if (message.StartsWith(":" + delimiter.ToString() + "VERSION")) |
1352 | | - { |
1353 | | - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + config.version); |
1354 | | - wd.Flush(); |
1355 | | - continue; |
1356 | | - } |
1357 | | - } |
1358 | | - } |
1359 | | - if (text.Contains("PING ")) |
1360 | | - { |
1361 | | - wd.WriteLine("PONG " + text.Substring(text.IndexOf("PING ") + 5)); |
1362 | | - wd.Flush(); |
1363 | | - } |
1364 | | - } |
1365 | | - } |
1366 | | - Thread.Sleep(50); |
1367 | | - } |
1368 | | - Program.Log("Reconnecting, end of data stream"); |
1369 | | - Reconnect(); |
1370 | | - } |
1371 | | - catch (System.IO.IOException xx) |
1372 | | - { |
1373 | | - Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
1374 | | - Reconnect(); |
1375 | | - } |
1376 | | - catch (Exception xx) |
1377 | | - { |
1378 | | - handleException(xx, channel); |
1379 | | - } |
1380 | | - } |
1381 | | - } |
1382 | | - public static int Disconnect() |
1383 | | - { |
1384 | | - wd.Flush(); |
1385 | | - return 0; |
1386 | | - } |
1387 | | - } |
1388 | | -} |
Index: trunk/tools/wmib/RClogs.cs |
— | — | @@ -134,25 +134,25 @@ |
135 | 135 | } |
136 | 136 | |
137 | 137 | public static void Connect() |
138 | | - {
|
139 | | - try
|
140 | | - {
|
141 | | - stream = new System.Net.Sockets.TcpClient("irc.wikimedia.org", 6667).GetStream();
|
142 | | - WD = new StreamWriter(stream);
|
143 | | - RD = new StreamReader(stream, System.Text.Encoding.UTF8);
|
144 | | - System.Threading.Thread pinger = new System.Threading.Thread(Pong);
|
145 | | - WD.WriteLine("USER " + "wm-bot" + " 8 * :" + "wm-bot");
|
146 | | - WD.WriteLine("NICK " + "wm-bot" + System.DateTime.Now.ToShortDateString().Replace("/", "").Replace(":", "").Replace("\\", "").Replace(".", ""));
|
147 | | - WD.Flush();
|
148 | | - pinger.Start();
|
149 | | - foreach (string b in channels)
|
150 | | - {
|
151 | | - System.Threading.Thread.Sleep(800);
|
152 | | - WD.WriteLine("JOIN " + b);
|
153 | | - WD.Flush();
|
154 | | - }
|
155 | | - }
|
156 | | - catch (Exception)
|
| 138 | + { |
| 139 | + try |
| 140 | + { |
| 141 | + stream = new System.Net.Sockets.TcpClient("irc.wikimedia.org", 6667).GetStream(); |
| 142 | + WD = new StreamWriter(stream); |
| 143 | + RD = new StreamReader(stream, System.Text.Encoding.UTF8); |
| 144 | + System.Threading.Thread pinger = new System.Threading.Thread(Pong); |
| 145 | + WD.WriteLine("USER " + "wm-bot" + " 8 * :" + "wm-bot"); |
| 146 | + WD.WriteLine("NICK " + "wm-bot" + System.DateTime.Now.ToShortDateString().Replace("/", "").Replace(":", "").Replace("\\", "").Replace(".", "")); |
| 147 | + WD.Flush(); |
| 148 | + pinger.Start(); |
| 149 | + foreach (string b in channels) |
| 150 | + { |
| 151 | + System.Threading.Thread.Sleep(800); |
| 152 | + WD.WriteLine("JOIN " + b); |
| 153 | + WD.Flush(); |
| 154 | + } |
| 155 | + } |
| 156 | + catch (Exception) |
157 | 157 | { |
158 | 158 | |
159 | 159 | } |