r106538 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106537‎ | r106538 | r106539 >
Date:00:37, 18 December 2011
Author:reedy
Status:deferred
Tags:
Comment:
Fix indenting
Modified paths:
  • /trunk/tools/wmib/Config.cs (modified) (history)
  • /trunk/tools/wmib/Core.cs (modified) (history)
  • /trunk/tools/wmib/DumpHtm.cs (modified) (history)
  • /trunk/tools/wmib/Program.cs (modified) (history)

Diff [purge]

Index: trunk/tools/wmib/DumpHtm.cs
@@ -18,10 +18,12 @@
1919 /// Channel name
2020 /// </summary>
2121 public config.channel Channel;
 22+
2223 /// <summary>
2324 /// Dump
2425 /// </summary>
2526 public string dumpname;
 27+
2628 // This function is called on start of bot
2729 public static void Start()
2830 {
@@ -37,6 +39,7 @@
3840 System.Threading.Thread.Sleep(320000);
3941 }
4042 }
 43+
4144 /// <summary>
4245 /// Constructor
4346 /// </summary>
@@ -62,7 +65,7 @@
6366 /// <returns></returns>
6467 public string CreateHeader()
6568 {
66 - return "<html><head><title>"+ Channel.name +"</title></head><body>\n";
 69+ return "<html><head><title>" + Channel.name + "</title></head><body>\n";
6770 }
6871
6972 /// <summary>
Index: trunk/tools/wmib/Config.cs
@@ -23,24 +23,31 @@
2424 /// Channel name
2525 /// </summary>
2626 public string name;
 27+
2728 public bool logged;
 29+
2830 /// <summary>
2931 /// Log
3032 /// </summary>
3133 public string log;
 34+
3235 public bool info;
 36+
3337 /// <summary>
3438 /// Keys
3539 /// </summary>
3640 public irc.dictionary Keys;
 41+
3742 /// <summary>
3843 /// Configuration text
3944 /// </summary>
4045 private string conf;
 46+
4147 /// <summary>
4248 /// Users
4349 /// </summary>
4450 public irc.IRCTrust Users;
 51+
4552 /// <summary>
4653 /// Path of db
4754 /// </summary>
@@ -61,7 +68,7 @@
6269 /// </summary>
6370 public void LoadConfig()
6471 {
65 - string conf_file = name + ".setting";
 72+ string conf_file = name + ".setting";
6673 if (!File.Exists(conf_file))
6774 {
6875 File.WriteAllText(conf_file, "");
@@ -174,7 +181,7 @@
175182 text = File.ReadAllText("wmib");
176183 foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(','))
177184 {
178 - string config =x.Replace(" ", "");
 185+ string config = x.Replace(" ", "");
179186 if (config != "")
180187 {
181188 channels.Add(new channel(config));
@@ -197,6 +204,7 @@
198205 /// Network
199206 /// </summary>
200207 public static string network = "irc.freenode.net";
 208+
201209 /// <summary>
202210 /// Nick name
203211 /// </summary>
Index: trunk/tools/wmib/Program.cs
@@ -14,15 +14,15 @@
1515
1616 namespace wmib
1717 {
18 - class Program
 18+ internal class Program
1919 {
20 - public static bool Log(string msg )
 20+ public static bool Log(string msg)
2121 {
2222 Console.WriteLine("LOG: " + msg);
2323 return false;
2424 }
2525
26 - static void Main(string[] args)
 26+ private static void Main(string[] args)
2727 {
2828 Log("Connecting");
2929 config.Load();
Index: trunk/tools/wmib/Core.cs
@@ -15,7 +15,7 @@
1616 namespace wmib
1717 {
1818 public class misc
19 - {
 19+ {
2020 public static bool IsValidRegex(string pattern)
2121 {
2222 if (pattern == null) return false;
@@ -32,6 +32,7 @@
3333 return true;
3434 }
3535 }
 36+
3637 public class irc
3738 {
3839 private static System.Net.Sockets.NetworkStream data;
@@ -53,10 +54,12 @@
5455 /// Regex
5556 /// </summary>
5657 public string name;
 58+
5759 /// <summary>
5860 /// Level
5961 /// </summary>
6062 public string level;
 63+
6164 /// <summary>
6265 /// Constructor
6366 /// </summary>
@@ -114,10 +117,12 @@
115118 /// List of all users in a channel
116119 /// </summary>
117120 private List<user> Users = new List<user>();
 121+
118122 /// <summary>
119123 /// Channel this class belong to
120124 /// </summary>
121125 public string _Channel;
 126+
122127 /// <summary>
123128 /// File where data are stored
124129 /// </summary>
@@ -333,24 +338,30 @@
334339 /// Data file
335340 /// </summary>
336341 public string datafile = "";
 342+
337343 // if we need to update dump
338344 public bool update = true;
 345+
339346 /// <summary>
340347 /// Locked
341348 /// </summary>
342349 public bool locked = false;
 350+
343351 public class item
344352 {
345353 /// <summary>
346354 /// Text
347355 /// </summary>
348356 public string text;
 357+
349358 /// <summary>
350359 /// Key
351360 /// </summary>
352361 public string key;
 362+
353363 public string user;
354364 public string locked;
 365+
355366 /// <summary>
356367 /// Constructor
357368 /// </summary>
@@ -366,16 +377,19 @@
367378 user = User;
368379 }
369380 }
 381+
370382 public class staticalias
371383 {
372384 /// <summary>
373385 /// Name
374386 /// </summary>
375387 public string Name;
 388+
376389 /// <summary>
377390 /// Key
378391 /// </summary>
379392 public string Key;
 393+
380394 /// <summary>
381395 /// Constructor
382396 /// </summary>
@@ -387,20 +401,25 @@
388402 Key = key;
389403 }
390404 }
 405+
391406 /// <summary>
392407 /// List of all items in class
393408 /// </summary>
394409 public List<item> text = new List<item>();
 410+
395411 /// <summary>
396412 /// List of all aliases we want to use
397413 /// </summary>
398414 public List<staticalias> Alias = new List<staticalias>();
 415+
399416 /// <summary>
400417 /// Channel name
401418 /// </summary>
402419 public string Channel;
 420+
403421 private bool running;
404422 private string search_key;
 423+
405424 /// <summary>
406425 /// Load it
407426 /// </summary>
@@ -458,11 +477,14 @@
459478 File.WriteAllText(datafile, "");
460479 foreach (staticalias key in Alias)
461480 {
462 - File.AppendAllText(datafile, key.Name + config.separator + key.Key + config.separator + "alias" + "\n");
 481+ File.AppendAllText(datafile,
 482+ key.Name + config.separator + key.Key + config.separator + "alias" + "\n");
463483 }
464484 foreach (item key in text)
465485 {
466 - File.AppendAllText(datafile, key.key + config.separator + key.text + config.separator + "key" + config.separator + key.locked + config.separator + key.user + "\n");
 486+ File.AppendAllText(datafile,
 487+ key.key + config.separator + key.text + config.separator + "key" +
 488+ config.separator + key.locked + config.separator + key.user + "\n");
467489 }
468490 }
469491 catch (Exception b)
@@ -535,7 +557,7 @@
536558 Message("It would be cool to give me also a name of key", Channel);
537559 return true;
538560 }
539 - this.aliasKey(name.Substring(name.IndexOf(" alias") + 7), parm[0], "");
 561+ this.aliasKey(name.Substring(name.IndexOf(" alias") + 7), parm[0], "");
540562 }
541563 else
542564 {
@@ -579,7 +601,7 @@
580602 return false;
581603 }
582604 }
583 - string User ="";
 605+ string User = "";
584606 if (name.Contains("|"))
585607 {
586608 User = name.Substring(name.IndexOf("|"));
@@ -590,26 +612,27 @@
591613 string[] p = name.Split(' ');
592614 int parameters = p.Length;
593615 string keyv = getValue(p[0]);
594 - if (!(keyv == ""))
 616+ if (!(keyv == ""))
 617+ {
 618+ if (parameters > 1)
595619 {
596 - if ( parameters > 1)
 620+ int curr = 1;
 621+ while (parameters > curr)
597622 {
598 - int curr = 1;
599 - while ( parameters > curr )
600 - {
601 - keyv = keyv.Replace("$" + curr.ToString(), p[curr]);
602 - curr++;
603 - }
 623+ keyv = keyv.Replace("$" + curr.ToString(), p[curr]);
 624+ curr++;
604625 }
605 - if (User == "")
606 - {
607 - Message(keyv, Channel);
608 - } else
609 - {
610 - Message(User + ": " + keyv, Channel);
611 - }
612 - return true;
613626 }
 627+ if (User == "")
 628+ {
 629+ Message(keyv, Channel);
 630+ }
 631+ else
 632+ {
 633+ Message(User + ": " + keyv, Channel);
 634+ }
 635+ return true;
 636+ }
614637 foreach (staticalias b in Alias)
615638 {
616639 if (b.Name == p[0])
@@ -617,10 +640,10 @@
618641 keyv = getValue(b.Key);
619642 if (keyv != "")
620643 {
621 - if ( parameters > 1)
 644+ if (parameters > 1)
622645 {
623646 int curr = 1;
624 - while ( parameters > curr )
 647+ while (parameters > curr)
625648 {
626649 keyv = keyv.Replace("$" + curr.ToString(), p[curr]);
627650 curr++;
@@ -643,7 +666,11 @@
644667
645668 private void StartSearch()
646669 {
647 - System.Text.RegularExpressions.Regex value = new System.Text.RegularExpressions.Regex(search_key, System.Text.RegularExpressions.RegexOptions.Compiled);
 670+ System.Text.RegularExpressions.Regex value = new System.Text.RegularExpressions.Regex(search_key,
 671+ System.Text.
 672+ RegularExpressions
 673+ .RegexOptions.
 674+ Compiled);
648675 string results = "";
649676 foreach (item data in text)
650677 {
@@ -712,7 +739,7 @@
713740 if (key.Length < 9)
714741 {
715742 Message("Could you please tell me what I should search for :P", Chan.name);
716 - return;
 743+ return;
717744 }
718745 key = key.Substring(8);
719746 string results = "";
@@ -743,20 +770,20 @@
744771 {
745772 while (locked)
746773 {
747 - System.Threading.Thread.Sleep(200);
 774+ System.Threading.Thread.Sleep(200);
748775 }
749776 try
750777 {
751 - foreach (item data in text)
 778+ foreach (item data in text)
 779+ {
 780+ if (data.key == key)
752781 {
753 - if (data.key == key)
754 - {
755 - Message("Key exist!", Channel);
756 - return;
757 - }
 782+ Message("Key exist!", Channel);
 783+ return;
758784 }
759 - text.Add(new item(key, encode(Text), user, "false"));
760 - Message("Key was added!", Channel);
 785+ }
 786+ text.Add(new item(key, encode(Text), user, "false"));
 787+ Message("Key was added!", Channel);
761788 Save();
762789 }
763790 catch (Exception b)
@@ -773,7 +800,7 @@
774801 /// <param name="user">User</param>
775802 public void aliasKey(string key, string al, string user)
776803 {
777 - foreach(staticalias stakey in this.Alias)
 804+ foreach (staticalias stakey in this.Alias)
778805 {
779806 if (stakey.Name == al)
780807 {
@@ -790,7 +817,7 @@
791818 {
792819 while (locked)
793820 {
794 - System.Threading.Thread.Sleep(200);
 821+ System.Threading.Thread.Sleep(200);
795822 }
796823 foreach (item keys in text)
797824 {
@@ -892,7 +919,7 @@
893920 {
894921 if (number <= 9 && number >= 0)
895922 {
896 - return "0"+number.ToString();
 923+ return "0" + number.ToString();
897924 }
898925 return number.ToString();
899926 }
@@ -907,7 +934,7 @@
908935 {
909936 config.channel curr = getChannel(channel);
910937 wd.WriteLine("PRIVMSG " + channel + " :" + message);
911 - chanLog( message, curr, config.username, "" );
 938+ chanLog(message, curr, config.username, "");
912939 wd.Flush();
913940 return true;
914941 }
@@ -931,7 +958,8 @@
932959 {
933960 if (rights_info.Length < 3)
934961 {
935 - Message("Wrong number of parameters, go fix it - example @trustadd regex (admin|trusted)", channel.name);
 962+ Message("Wrong number of parameters, go fix it - example @trustadd regex (admin|trusted)",
 963+ channel.name);
936964 return 0;
937965 }
938966 if (!(rights_info[2] == "admin" || rights_info[2] == "trusted"))
@@ -1005,17 +1033,22 @@
10061034 string log;
10071035 if (!noac)
10081036 {
1009 - log = "[" + timedateToString(System.DateTime.Now.Hour) + ":" + timedateToString(System.DateTime.Now.Minute) + ":" + timedateToString( System.DateTime.Now.Second) + "] * " + user + " " + message + "\n";
 1037+ log = "[" + timedateToString(System.DateTime.Now.Hour) + ":" +
 1038+ timedateToString(System.DateTime.Now.Minute) + ":" +
 1039+ timedateToString(System.DateTime.Now.Second) + "] * " + user + " " + message + "\n";
10101040 }
10111041 else
10121042 {
1013 - log = "[" + timedateToString( System.DateTime.Now.Hour) + ":" + timedateToString( System.DateTime.Now.Minute ) + ":" + timedateToString( System.DateTime.Now.Second) + "] " + "<" + user + ">\t " + message + "\n";
 1043+ log = "[" + timedateToString(System.DateTime.Now.Hour) + ":" +
 1044+ timedateToString(System.DateTime.Now.Minute) + ":" +
 1045+ timedateToString(System.DateTime.Now.Second) + "] " + "<" + user + ">\t " + message + "\n";
10141046 }
1015 - File.AppendAllText(channel.log + System.DateTime.Now.Year + System.DateTime.Now.Month + System.DateTime.Now.Day +".txt", log);
 1047+ File.AppendAllText(
 1048+ channel.log + DateTime.Now.Year + DateTime.Now.Month + System.DateTime.Now.Day + ".txt", log);
10161049 }
10171050 }
10181051 catch (Exception er)
1019 - {
 1052+ {
10201053 // nothing
10211054 Console.WriteLine(er.Message);
10221055 }
@@ -1038,7 +1071,9 @@
10391072
10401073 public static bool validFile(string name)
10411074 {
1042 - return !(name.Contains(" ") || name.Contains("?") || name.Contains("|") || name.Contains("/") || name.Contains("\\") || name.Contains(">") || name.Contains("<") || name.Contains("*"));
 1075+ return
 1076+ !(name.Contains(" ") || name.Contains("?") || name.Contains("|") || name.Contains("/") ||
 1077+ name.Contains("\\") || name.Contains(">") || name.Contains("<") || name.Contains("*"));
10431078 }
10441079
10451080 /// <summary>
@@ -1054,45 +1089,42 @@
10551090 {
10561091 if (message.StartsWith("@add"))
10571092 {
1058 - if (chan.Users.isApproved(user, host, "admin"))
 1093+ return;
 1094+ }
 1095+ if (!chan.Users.isApproved(user, host, "admin"))
 1096+ {
 1097+ Message(messages.PermissionDenied, chan.name);
 1098+ return;
 1099+ }
 1100+ if (!message.Contains(" "))
 1101+ {
 1102+ Message("Invalid name", chan.name);
 1103+ return;
 1104+ }
 1105+ string channel = message.Substring(message.IndexOf(" ") + 1);
 1106+ if (!validFile(channel) || (channel.Contains("#") == false))
 1107+ {
 1108+ Message("Invalid name", chan.name);
 1109+ return;
 1110+ }
 1111+ foreach (config.channel cu in config.channels)
 1112+ {
 1113+ if (channel == cu.name)
10591114 {
1060 - if (message.Contains(" "))
1061 - {
1062 - string channel = message.Substring(message.IndexOf(" ") + 1);
1063 - if ( !validFile(channel) || (channel.Contains("#") == false))
1064 - {
1065 - Message("Invalid name", chan.name);
1066 - return;
1067 - }
1068 - foreach (config.channel cu in config.channels)
1069 - {
1070 - if (channel == cu.name)
1071 - {
1072 - return;
1073 - }
1074 - }
1075 - config.channels.Add(new config.channel(channel));
1076 - config.Save();
1077 - wd.WriteLine("JOIN " + channel);
1078 - wd.Flush();
1079 - System.Threading.Thread.Sleep(100);
1080 - config.channel Chan = getChannel(channel);
1081 - Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + host);
1082 - }
1083 - else
1084 - {
1085 - Message("Invalid name", chan.name);
1086 - }
 1115+ return;
10871116 }
1088 - else
1089 - {
1090 - Message(messages.PermissionDenied, chan.name);
1091 - }
10921117 }
 1118+ config.channels.Add(new config.channel(channel));
 1119+ config.Save();
 1120+ wd.WriteLine("JOIN " + channel);
 1121+ wd.Flush();
 1122+ System.Threading.Thread.Sleep(100);
 1123+ config.channel Chan = getChannel(channel);
 1124+ Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + host);
10931125 }
10941126 catch (Exception b)
1095 - {
1096 -
 1127+ {
 1128+
10971129 }
10981130 }
10991131
@@ -1166,10 +1198,10 @@
11671199 {
11681200 if (chan.Users.isApproved(user, host, "admin"))
11691201 {
1170 - chan.LoadConfig();
1171 - chan.Keys = new dictionary(chan.keydb, chan.name);
1172 - Message("Channel config was reloaded", chan.name);
1173 - return;
 1202+ chan.LoadConfig();
 1203+ chan.Keys = new dictionary(chan.keydb, chan.name);
 1204+ Message("Channel config was reloaded", chan.name);
 1205+ return;
11741206 }
11751207 else
11761208 {
@@ -1204,11 +1236,12 @@
12051237 if (message == "@whoami")
12061238 {
12071239 user current = chan.Users.getUser(user + "!@" + host);
1208 - if(current.level == "null")
 1240+ if (current.level == "null")
12091241 {
12101242 Message("You are unknown to me :)", chan.name);
12111243 return;
1212 - } else
 1244+ }
 1245+ else
12131246 {
12141247 Message("You are " + current.level + " identified by name " + current.name, chan.name);
12151248 return;
@@ -1295,7 +1328,9 @@
12961329 }
12971330 if (message == "@commands")
12981331 {
1299 - Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, whoami, add, reload, logon, logoff", chan.name);
 1332+ Message(
 1333+ "Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, whoami, add, reload, logon, logoff",
 1334+ chan.name);
13001335 return;
13011336 }
13021337 }
@@ -1392,7 +1427,7 @@
13931428 string host = "";
13941429 string message = "";
13951430 string channel = "";
1396 - char delimiter = (char)001;
 1431+ char delimiter = (char) 001;
13971432
13981433 while (true)
13991434 {
@@ -1418,7 +1453,9 @@
14191454 if (text.Contains("!") && text.Contains("@"))
14201455 {
14211456 nick = info.Substring(0, info.IndexOf("!"));
1422 - host = info.Substring(info.IndexOf("@") + 1, info.IndexOf(" ", info.IndexOf("@")) - 1 - info.IndexOf("@"));
 1457+ host = info.Substring(info.IndexOf("@") + 1,
 1458+ info.IndexOf(" ", info.IndexOf("@")) - 1 -
 1459+ info.IndexOf("@"));
14231460 }
14241461 info_host = info.Substring(info.IndexOf("PRIVMSG "));
14251462
@@ -1429,7 +1466,8 @@
14301467 message = message.Substring(message.IndexOf(" :") + 2);
14311468 if (message.Contains(delimiter.ToString() + "ACTION"))
14321469 {
1433 - getAction(message.Replace(delimiter.ToString() +"ACTION", ""), channel, host, nick);
 1470+ getAction(message.Replace(delimiter.ToString() + "ACTION", ""), channel,
 1471+ host, nick);
14341472 continue;
14351473 }
14361474 getMessage(channel, nick, host, message);
@@ -1442,25 +1480,30 @@
14431481 // private message
14441482 if (message.StartsWith(":" + delimiter.ToString() + "FINGER"))
14451483 {
1446 - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" + " I am a bot don't finger me");
 1484+ wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "FINGER" +
 1485+ " I am a bot don't finger me");
14471486 wd.Flush();
14481487 continue;
14491488 }
14501489 if (message.StartsWith(":" + delimiter.ToString() + "TIME"))
14511490 {
1452 - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " + System.DateTime.Now.ToString());
 1491+ wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "TIME " +
 1492+ System.DateTime.Now.ToString());
14531493 wd.Flush();
14541494 continue;
14551495 }
14561496 if (message.StartsWith(":" + delimiter.ToString() + "PING"))
14571497 {
1458 - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" + message.Substring(message.IndexOf(delimiter.ToString() + "PING")+5));
 1498+ wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "PING" +
 1499+ message.Substring(
 1500+ message.IndexOf(delimiter.ToString() + "PING") + 5));
14591501 wd.Flush();
14601502 continue;
14611503 }
14621504 if (message.StartsWith(":" + delimiter.ToString() + "VERSION"))
14631505 {
1464 - wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " + config.version);
 1506+ wd.WriteLine("NOTICE " + nick + " :" + delimiter.ToString() + "VERSION " +
 1507+ config.version);
14651508 wd.Flush();
14661509 continue;
14671510 }
@@ -1495,6 +1538,6 @@
14961539 {
14971540 wd.Flush();
14981541 return 0;
1499 - }
 1542+ }
15001543 }
15011544 }

Status & tagging log