Index: trunk/tools/wmib/Program.cs |
— | — | @@ -20,12 +20,13 @@ |
21 | 21 | { |
22 | 22 | class Program |
23 | 23 | { |
24 | | - public static bool Log(string msg ) |
| 24 | + public static bool Log(string msg) |
25 | 25 | { |
26 | 26 | Console.WriteLine("LOG: " + msg); |
27 | 27 | return false; |
28 | 28 | } |
29 | | - static void Main(string[] args) |
| 29 | + |
| 30 | + private static void Main(string[] args) |
30 | 31 | { |
31 | 32 | Log("Connecting"); |
32 | 33 | irc.Connect(); |
— | — | @@ -41,32 +42,38 @@ |
42 | 43 | public string log; |
43 | 44 | public irc.dictionary Keys = new irc.dictionary(); |
44 | 45 | public irc.trust Users; |
| 46 | + |
45 | 47 | public channel(string Name) |
46 | 48 | { |
47 | 49 | logged = true; |
48 | | - name = Name; |
| 50 | + name = Name; |
49 | 51 | log = Name + ".txt"; |
50 | 52 | Keys.Load(name); |
51 | 53 | Users = new irc.trust(name); |
52 | 54 | } |
53 | 55 | } |
| 56 | + |
54 | 57 | /// <summary> |
55 | 58 | /// Network |
56 | 59 | /// </summary> |
57 | 60 | public static string network = "irc.freenode.net"; |
| 61 | + |
58 | 62 | public static string username = "wm-bot"; |
| 63 | + |
59 | 64 | /// <summary> |
60 | 65 | /// |
61 | 66 | /// </summary> |
62 | 67 | public static string version = "wikimedia bot v. 1.0.1"; |
| 68 | + |
63 | 69 | /// <summary> |
64 | 70 | /// User name |
65 | 71 | /// </summary> |
66 | 72 | public static string name = "wm-bot"; |
| 73 | + |
67 | 74 | /// <summary> |
68 | 75 | /// Channels |
69 | 76 | /// </summary> |
70 | | - public static channel[] channels = { new channel("#wikimedia-labs"), new channel( "#wikimedia-test-bots") }; |
| 77 | + public static channel[] channels = {new channel("#wikimedia-labs"), new channel("#wikimedia-test-bots")}; |
71 | 78 | } |
72 | 79 | |
73 | 80 | public static class irc |
— | — | @@ -83,6 +90,7 @@ |
84 | 91 | this.level = level; |
85 | 92 | this.name = name; |
86 | 93 | } |
| 94 | + |
87 | 95 | public string name; |
88 | 96 | public string level; |
89 | 97 | } |
— | — | @@ -92,8 +100,9 @@ |
93 | 101 | private List<user> Users = new List<user>(); |
94 | 102 | public string _Channel; |
95 | 103 | public string File; |
| 104 | + |
96 | 105 | public trust(string channel) |
97 | | - { |
| 106 | + { |
98 | 107 | // Load |
99 | 108 | File = channel + "_user"; |
100 | 109 | if (!System.IO.File.Exists(File)) |
— | — | @@ -115,6 +124,7 @@ |
116 | 125 | } |
117 | 126 | } |
118 | 127 | } |
| 128 | + |
119 | 129 | public bool Save() |
120 | 130 | { |
121 | 131 | System.IO.File.WriteAllText(File, ""); |
— | — | @@ -174,7 +184,7 @@ |
175 | 185 | } |
176 | 186 | |
177 | 187 | public bool matchLevel(int level, string rights) |
178 | | - { |
| 188 | + { |
179 | 189 | if (level == 2) |
180 | 190 | { |
181 | 191 | return (rights == "admin"); |
— | — | @@ -182,7 +192,7 @@ |
183 | 193 | if (level == 1) |
184 | 194 | { |
185 | 195 | return (rights == "trusted" || rights == "admin"); |
186 | | - |
| 196 | + |
187 | 197 | } |
188 | 198 | return false; |
189 | 199 | } |
— | — | @@ -197,23 +207,23 @@ |
198 | 208 | |
199 | 209 | if (command == "alias_key") |
200 | 210 | { |
201 | | - return matchLevel(1, current.level); |
| 211 | + return matchLevel(1, current.level); |
202 | 212 | } |
203 | 213 | if (command == "new_key") |
204 | 214 | { |
205 | | - return matchLevel(1, current.level); |
| 215 | + return matchLevel(1, current.level); |
206 | 216 | } |
207 | 217 | if (command == "shutdown") |
208 | 218 | { |
209 | | - return matchLevel(1, current.level); |
| 219 | + return matchLevel(1, current.level); |
210 | 220 | } |
211 | 221 | if (command == "delete_key") |
212 | 222 | { |
213 | | - return matchLevel(1, current.level); |
| 223 | + return matchLevel(1, current.level); |
214 | 224 | } |
215 | 225 | if (command == "trust") |
216 | 226 | { |
217 | | - return matchLevel(1, current.level); |
| 227 | + return matchLevel(1, current.level); |
218 | 228 | } |
219 | 229 | if (command == "admin") |
220 | 230 | { |
— | — | @@ -221,11 +231,11 @@ |
222 | 232 | } |
223 | 233 | if (command == "trustadd") |
224 | 234 | { |
225 | | - return matchLevel(1, current.level); |
| 235 | + return matchLevel(1, current.level); |
226 | 236 | } |
227 | 237 | if (command == "trustdel") |
228 | 238 | { |
229 | | - return matchLevel(1, current.level); |
| 239 | + return matchLevel(1, current.level); |
230 | 240 | } |
231 | 241 | return false; |
232 | 242 | } |
— | — | @@ -242,13 +252,16 @@ |
243 | 253 | locked = Lock; |
244 | 254 | user = User; |
245 | 255 | } |
| 256 | + |
246 | 257 | public string text; |
247 | 258 | public string key; |
248 | 259 | public string user; |
249 | 260 | public string locked; |
250 | 261 | } |
| 262 | + |
251 | 263 | public List<item> text = new List<item>(); |
252 | 264 | public string Channel; |
| 265 | + |
253 | 266 | public void Load(string channel) |
254 | 267 | { |
255 | 268 | Channel = channel; |
— | — | @@ -299,7 +312,7 @@ |
300 | 313 | return false; |
301 | 314 | } |
302 | 315 | } |
303 | | - string User =""; |
| 316 | + string User = ""; |
304 | 317 | if (name.Contains("|")) |
305 | 318 | { |
306 | 319 | User = name.Substring(name.IndexOf("|")); |
— | — | @@ -309,14 +322,15 @@ |
310 | 323 | name = name.Replace(" ", ""); |
311 | 324 | } |
312 | 325 | foreach (item data in text) |
313 | | - { |
314 | | - |
| 326 | + { |
| 327 | + |
315 | 328 | if (data.key == name) |
316 | 329 | { |
317 | 330 | if (User == "") |
318 | 331 | { |
319 | 332 | Message(name + " is: " + data.text, Channel); |
320 | | - } else |
| 333 | + } |
| 334 | + else |
321 | 335 | { |
322 | 336 | Message(User + ":" + data.text, Channel); |
323 | 337 | } |
— | — | @@ -346,7 +360,9 @@ |
347 | 361 | } |
348 | 362 | else |
349 | 363 | { |
350 | | - Message("Error, it contains invalid characters, " + user + " you better not use pipes in text!", Channel); |
| 364 | + Message( |
| 365 | + "Error, it contains invalid characters, " + user + " you better not use pipes in text!", |
| 366 | + Channel); |
351 | 367 | } |
352 | 368 | Save(); |
353 | 369 | } |
— | — | @@ -355,10 +371,12 @@ |
356 | 372 | handleException(b, Channel); |
357 | 373 | } |
358 | 374 | } |
| 375 | + |
359 | 376 | public void aliasKey(string key, string alias, string user) |
360 | 377 | { |
361 | 378 | Save(); |
362 | 379 | } |
| 380 | + |
363 | 381 | public void rmKey(string key, string user) |
364 | 382 | { |
365 | 383 | foreach (item keys in text) |
— | — | @@ -381,7 +399,7 @@ |
382 | 400 | } |
383 | 401 | |
384 | 402 | public static config.channel getChannel(string name) |
385 | | - { |
| 403 | + { |
386 | 404 | foreach (config.channel current in config.channels) |
387 | 405 | { |
388 | 406 | if (current.name == name) |
— | — | @@ -460,7 +478,8 @@ |
461 | 479 | { |
462 | 480 | if (channel.logged) |
463 | 481 | { |
464 | | - string log = "\n" + "[" + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute + ":" + System.DateTime.Now.Second + "] " + "<" + user + "> " + message; |
| 482 | + string log = "\n" + "[" + System.DateTime.Now.Hour + ":" + System.DateTime.Now.Minute + ":" + |
| 483 | + System.DateTime.Now.Second + "] " + "<" + user + "> " + message; |
465 | 484 | System.IO.File.AppendAllText(channel.log, log); |
466 | 485 | } |
467 | 486 | } |
— | — | @@ -470,9 +489,9 @@ |
471 | 490 | config.channel curr = getChannel(channel); |
472 | 491 | if (curr != null) |
473 | 492 | { |
474 | | - curr.Keys.print(message); |
475 | | - chanLog(message, curr, nick, host); |
476 | | - modifyRights(message, curr, nick, host); |
| 493 | + curr.Keys.print(message); |
| 494 | + chanLog(message, curr, nick, host); |
| 495 | + modifyRights(message, curr, nick, host); |
477 | 496 | } |
478 | 497 | |
479 | 498 | |
— | — | @@ -516,11 +535,15 @@ |
517 | 536 | if (text.Contains("!") && text.Contains("@")) |
518 | 537 | { |
519 | 538 | nick = text.Substring(1, text.IndexOf("!") - 1); |
520 | | - host = text.Substring(text.IndexOf("@") + 1, text.IndexOf(" ", text.IndexOf("@")) - 1 - text.IndexOf("@")); |
| 539 | + host = text.Substring(text.IndexOf("@") + 1, |
| 540 | + text.IndexOf(" ", text.IndexOf("@")) - 1 - text.IndexOf("@")); |
521 | 541 | } |
522 | | - if (text.Substring(text.IndexOf("PRIVMSG ", text.IndexOf(" "), text.IndexOf("PRIVMSG "))).Contains("#")) |
| 542 | + if ( |
| 543 | + text.Substring(text.IndexOf("PRIVMSG ", text.IndexOf(" "), text.IndexOf("PRIVMSG "))). |
| 544 | + Contains("#")) |
523 | 545 | { |
524 | | - channel = text.Substring(text.IndexOf("#"), text.IndexOf(" ", text.IndexOf("#")) - text.IndexOf("#")); |
| 546 | + channel = text.Substring(text.IndexOf("#"), |
| 547 | + text.IndexOf(" ", text.IndexOf("#")) - text.IndexOf("#")); |
525 | 548 | message = text.Substring(text.IndexOf("PRIVMSG")); |
526 | 549 | message = message.Substring(message.IndexOf(":") + 1); |
527 | 550 | if (message.Contains("ACTION")) |
— | — | @@ -533,20 +556,21 @@ |
534 | 557 | } |
535 | 558 | } |
536 | 559 | else |
537 | | - { |
| 560 | + { |
538 | 561 | // private message |
539 | 562 | } |
540 | 563 | } |
541 | 564 | } |
542 | 565 | System.Threading.Thread.Sleep(50); |
543 | | - } |
| 566 | + } |
544 | 567 | } |
545 | 568 | return 0; |
546 | 569 | } |
| 570 | + |
547 | 571 | public static int Disconnect() |
548 | 572 | { |
549 | 573 | wd.Flush(); |
550 | 574 | return 0; |
551 | | - } |
| 575 | + } |
552 | 576 | } |
553 | 577 | } |