r106009 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106008‎ | r106009 | r106010 >
Date:10:51, 13 December 2011
Author:reedy
Status:deferred
Tags:
Comment:
Reformat whitespace
Modified paths:
  • /trunk/tools/wmib/Program.cs (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/Program.cs
@@ -20,12 +20,13 @@
2121 {
2222 class Program
2323 {
24 - public static bool Log(string msg )
 24+ public static bool Log(string msg)
2525 {
2626 Console.WriteLine("LOG: " + msg);
2727 return false;
2828 }
29 - static void Main(string[] args)
 29+
 30+ private static void Main(string[] args)
3031 {
3132 Log("Connecting");
3233 irc.Connect();
@@ -41,32 +42,38 @@
4243 public string log;
4344 public irc.dictionary Keys = new irc.dictionary();
4445 public irc.trust Users;
 46+
4547 public channel(string Name)
4648 {
4749 logged = true;
48 - name = Name;
 50+ name = Name;
4951 log = Name + ".txt";
5052 Keys.Load(name);
5153 Users = new irc.trust(name);
5254 }
5355 }
 56+
5457 /// <summary>
5558 /// Network
5659 /// </summary>
5760 public static string network = "irc.freenode.net";
 61+
5862 public static string username = "wm-bot";
 63+
5964 /// <summary>
6065 ///
6166 /// </summary>
6267 public static string version = "wikimedia bot v. 1.0.1";
 68+
6369 /// <summary>
6470 /// User name
6571 /// </summary>
6672 public static string name = "wm-bot";
 73+
6774 /// <summary>
6875 /// Channels
6976 /// </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")};
7178 }
7279
7380 public static class irc
@@ -83,6 +90,7 @@
8491 this.level = level;
8592 this.name = name;
8693 }
 94+
8795 public string name;
8896 public string level;
8997 }
@@ -92,8 +100,9 @@
93101 private List<user> Users = new List<user>();
94102 public string _Channel;
95103 public string File;
 104+
96105 public trust(string channel)
97 - {
 106+ {
98107 // Load
99108 File = channel + "_user";
100109 if (!System.IO.File.Exists(File))
@@ -115,6 +124,7 @@
116125 }
117126 }
118127 }
 128+
119129 public bool Save()
120130 {
121131 System.IO.File.WriteAllText(File, "");
@@ -174,7 +184,7 @@
175185 }
176186
177187 public bool matchLevel(int level, string rights)
178 - {
 188+ {
179189 if (level == 2)
180190 {
181191 return (rights == "admin");
@@ -182,7 +192,7 @@
183193 if (level == 1)
184194 {
185195 return (rights == "trusted" || rights == "admin");
186 -
 196+
187197 }
188198 return false;
189199 }
@@ -197,23 +207,23 @@
198208
199209 if (command == "alias_key")
200210 {
201 - return matchLevel(1, current.level);
 211+ return matchLevel(1, current.level);
202212 }
203213 if (command == "new_key")
204214 {
205 - return matchLevel(1, current.level);
 215+ return matchLevel(1, current.level);
206216 }
207217 if (command == "shutdown")
208218 {
209 - return matchLevel(1, current.level);
 219+ return matchLevel(1, current.level);
210220 }
211221 if (command == "delete_key")
212222 {
213 - return matchLevel(1, current.level);
 223+ return matchLevel(1, current.level);
214224 }
215225 if (command == "trust")
216226 {
217 - return matchLevel(1, current.level);
 227+ return matchLevel(1, current.level);
218228 }
219229 if (command == "admin")
220230 {
@@ -221,11 +231,11 @@
222232 }
223233 if (command == "trustadd")
224234 {
225 - return matchLevel(1, current.level);
 235+ return matchLevel(1, current.level);
226236 }
227237 if (command == "trustdel")
228238 {
229 - return matchLevel(1, current.level);
 239+ return matchLevel(1, current.level);
230240 }
231241 return false;
232242 }
@@ -242,13 +252,16 @@
243253 locked = Lock;
244254 user = User;
245255 }
 256+
246257 public string text;
247258 public string key;
248259 public string user;
249260 public string locked;
250261 }
 262+
251263 public List<item> text = new List<item>();
252264 public string Channel;
 265+
253266 public void Load(string channel)
254267 {
255268 Channel = channel;
@@ -299,7 +312,7 @@
300313 return false;
301314 }
302315 }
303 - string User ="";
 316+ string User = "";
304317 if (name.Contains("|"))
305318 {
306319 User = name.Substring(name.IndexOf("|"));
@@ -309,14 +322,15 @@
310323 name = name.Replace(" ", "");
311324 }
312325 foreach (item data in text)
313 - {
314 -
 326+ {
 327+
315328 if (data.key == name)
316329 {
317330 if (User == "")
318331 {
319332 Message(name + " is: " + data.text, Channel);
320 - } else
 333+ }
 334+ else
321335 {
322336 Message(User + ":" + data.text, Channel);
323337 }
@@ -346,7 +360,9 @@
347361 }
348362 else
349363 {
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);
351367 }
352368 Save();
353369 }
@@ -355,10 +371,12 @@
356372 handleException(b, Channel);
357373 }
358374 }
 375+
359376 public void aliasKey(string key, string alias, string user)
360377 {
361378 Save();
362379 }
 380+
363381 public void rmKey(string key, string user)
364382 {
365383 foreach (item keys in text)
@@ -381,7 +399,7 @@
382400 }
383401
384402 public static config.channel getChannel(string name)
385 - {
 403+ {
386404 foreach (config.channel current in config.channels)
387405 {
388406 if (current.name == name)
@@ -460,7 +478,8 @@
461479 {
462480 if (channel.logged)
463481 {
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;
465484 System.IO.File.AppendAllText(channel.log, log);
466485 }
467486 }
@@ -470,9 +489,9 @@
471490 config.channel curr = getChannel(channel);
472491 if (curr != null)
473492 {
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);
477496 }
478497
479498
@@ -516,11 +535,15 @@
517536 if (text.Contains("!") && text.Contains("@"))
518537 {
519538 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("@"));
521541 }
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("#"))
523545 {
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("#"));
525548 message = text.Substring(text.IndexOf("PRIVMSG"));
526549 message = message.Substring(message.IndexOf(":") + 1);
527550 if (message.Contains("ACTION"))
@@ -533,20 +556,21 @@
534557 }
535558 }
536559 else
537 - {
 560+ {
538561 // private message
539562 }
540563 }
541564 }
542565 System.Threading.Thread.Sleep(50);
543 - }
 566+ }
544567 }
545568 return 0;
546569 }
 570+
547571 public static int Disconnect()
548572 {
549573 wd.Flush();
550574 return 0;
551 - }
 575+ }
552576 }
553577 }

Status & tagging log