Index: trunk/tools/wmib/DumpHtm.cs |
— | — | @@ -8,14 +8,8 @@ |
9 | 9 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | 10 | //GNU General Public License for more details. |
11 | 11 | |
12 | | - |
13 | | - |
14 | 12 | using System; |
15 | | -using System.Collections.Generic; |
16 | | -using System.Text; |
17 | | -using System.Net; |
18 | 13 | |
19 | | - |
20 | 14 | namespace wmib |
21 | 15 | { |
22 | 16 | public class HtmlDump |
— | — | @@ -35,12 +29,10 @@ |
36 | 30 | { |
37 | 31 | foreach (config.channel chan in config.channels) |
38 | 32 | { |
39 | | - if (chan.Keys.update) |
40 | | - { |
41 | | - HtmlDump dump = new HtmlDump(chan); |
42 | | - dump.Make(); |
43 | | - chan.Keys.update = false; |
44 | | - } |
| 33 | + if (!chan.Keys.update) continue; |
| 34 | + HtmlDump dump = new HtmlDump(chan); |
| 35 | + dump.Make(); |
| 36 | + chan.Keys.update = false; |
45 | 37 | } |
46 | 38 | System.Threading.Thread.Sleep(320000); |
47 | 39 | } |
— | — | @@ -103,9 +95,8 @@ |
104 | 96 | { |
105 | 97 | try |
106 | 98 | { |
107 | | - string text; |
108 | | - text = CreateHeader(); |
109 | | - text = text + "<table border=1 width=100%>\n<tr><td width=10%>Key</td><td>Value</td></tr>\n"; |
| 99 | + string text = CreateHeader(); |
| 100 | + text += "<table border=1 width=100%>\n<tr><td width=10%>Key</td><td>Value</td></tr>\n"; |
110 | 101 | Channel.Keys.locked = true; |
111 | 102 | if (Channel.Keys.text.Count > 0) |
112 | 103 | { |
Index: trunk/tools/wmib/Config.cs |
— | — | @@ -10,12 +10,9 @@ |
11 | 11 | |
12 | 12 | // Created by Petr Bena benapetr@gmail.com |
13 | 13 | |
14 | | -using System; |
15 | 14 | using System.Collections.Generic; |
16 | | -using System.Text; |
17 | | -using System.Net; |
| 15 | +using System.IO; |
18 | 16 | |
19 | | - |
20 | 17 | namespace wmib |
21 | 18 | { |
22 | 19 | public static class config |
— | — | @@ -65,24 +62,24 @@ |
66 | 63 | public void LoadConfig() |
67 | 64 | { |
68 | 65 | string conf_file = name + ".setting"; |
69 | | - if (!System.IO.File.Exists(conf_file)) |
| 66 | + if (!File.Exists(conf_file)) |
70 | 67 | { |
71 | | - System.IO.File.WriteAllText(conf_file, ""); |
| 68 | + File.WriteAllText(conf_file, ""); |
72 | 69 | Program.Log("Creating datafile for channel " + name); |
73 | 70 | return; |
74 | 71 | } |
75 | | - conf = System.IO.File.ReadAllText(conf_file); |
76 | | - if (config.parseConfig(conf, "keysdb") != "") |
| 72 | + conf = File.ReadAllText(conf_file); |
| 73 | + if (parseConfig(conf, "keysdb") != "") |
77 | 74 | { |
78 | | - keydb = (config.parseConfig(conf, "keysdb")); |
| 75 | + keydb = (parseConfig(conf, "keysdb")); |
79 | 76 | } |
80 | | - if (config.parseConfig(conf, "logged") != "") |
| 77 | + if (parseConfig(conf, "logged") != "") |
81 | 78 | { |
82 | | - logged = bool.Parse(config.parseConfig(conf, "logged")); |
| 79 | + logged = bool.Parse(parseConfig(conf, "logged")); |
83 | 80 | } |
84 | | - if (config.parseConfig(conf, "infodb") != "") |
| 81 | + if (parseConfig(conf, "infodb") != "") |
85 | 82 | { |
86 | | - info = bool.Parse(config.parseConfig(conf, "infodb")); |
| 83 | + info = bool.Parse(parseConfig(conf, "infodb")); |
87 | 84 | } |
88 | 85 | } |
89 | 86 | |
— | — | @@ -95,7 +92,7 @@ |
96 | 93 | AddConfig("infodb", info.ToString()); |
97 | 94 | AddConfig("logged", logged.ToString()); |
98 | 95 | AddConfig("keysdb", keydb); |
99 | | - System.IO.File.WriteAllText(name + ".setting", conf); |
| 96 | + File.WriteAllText(name + ".setting", conf); |
100 | 97 | } |
101 | 98 | |
102 | 99 | /// <summary> |
— | — | @@ -110,13 +107,13 @@ |
111 | 108 | logged = true; |
112 | 109 | name = Name; |
113 | 110 | LoadConfig(); |
114 | | - if (!System.IO.Directory.Exists("log")) |
| 111 | + if (!Directory.Exists("log")) |
115 | 112 | { |
116 | | - System.IO.Directory.CreateDirectory("log"); |
| 113 | + Directory.CreateDirectory("log"); |
117 | 114 | } |
118 | | - if (!System.IO.Directory.Exists("log/" + Name)) |
| 115 | + if (!Directory.Exists("log/" + Name)) |
119 | 116 | { |
120 | | - System.IO.Directory.CreateDirectory("log/" + Name); |
| 117 | + Directory.CreateDirectory("log/" + Name); |
121 | 118 | } |
122 | 119 | Keys = new irc.dictionary(keydb, name); |
123 | 120 | log = "log/" + Name + "/"; |
— | — | @@ -148,7 +145,7 @@ |
149 | 146 | text = text + current.name + ",\n"; |
150 | 147 | } |
151 | 148 | text = text + ";"; |
152 | | - System.IO.File.WriteAllText("wmib", text); |
| 149 | + File.WriteAllText("wmib", text); |
153 | 150 | } |
154 | 151 | |
155 | 152 | /// <summary> |
— | — | @@ -174,13 +171,13 @@ |
175 | 172 | /// </summary> |
176 | 173 | public static void Load() |
177 | 174 | { |
178 | | - text = System.IO.File.ReadAllText("wmib"); |
| 175 | + text = File.ReadAllText("wmib"); |
179 | 176 | foreach (string x in parseConfig(text, "channels").Replace("\n", "").Split(',')) |
180 | 177 | { |
181 | | - string name=x.Replace(" ", ""); |
182 | | - if (!(name == "")) |
| 178 | + string config =x.Replace(" ", ""); |
| 179 | + if (config != "") |
183 | 180 | { |
184 | | - channels.Add(new channel(name)); |
| 181 | + channels.Add(new channel(config)); |
185 | 182 | } |
186 | 183 | } |
187 | 184 | username = parseConfig(text, "username"); |
— | — | @@ -188,12 +185,14 @@ |
189 | 186 | login = parseConfig(text, "nick"); |
190 | 187 | debugchan = parseConfig(text, "debug"); |
191 | 188 | password = parseConfig(text, "password"); |
192 | | - if (!System.IO.Directory.Exists(config.DumpDir)) |
| 189 | + if (!Directory.Exists(DumpDir)) |
193 | 190 | { |
194 | | - System.IO.Directory.CreateDirectory(config.DumpDir); |
| 191 | + Directory.CreateDirectory(DumpDir); |
195 | 192 | } |
196 | 193 | } |
| 194 | + |
197 | 195 | public static string text; |
| 196 | + |
198 | 197 | /// <summary> |
199 | 198 | /// Network |
200 | 199 | /// </summary> |
— | — | @@ -202,31 +201,39 @@ |
203 | 202 | /// Nick name |
204 | 203 | /// </summary> |
205 | 204 | public static string username = "wm-bot"; |
| 205 | + |
206 | 206 | public static string debugchan = ""; |
| 207 | + |
207 | 208 | /// <summary> |
208 | 209 | /// Login name |
209 | 210 | /// </summary> |
210 | 211 | public static string login = ""; |
| 212 | + |
211 | 213 | /// <summary> |
212 | 214 | /// Login pw |
213 | 215 | /// </summary> |
214 | 216 | public static string password = ""; |
| 217 | + |
215 | 218 | /// <summary> |
216 | 219 | /// Dump |
217 | 220 | /// </summary> |
218 | 221 | public static string DumpDir = "dump"; |
| 222 | + |
219 | 223 | /// <summary> |
220 | 224 | /// Version |
221 | 225 | /// </summary> |
222 | 226 | public static string version = "wikimedia bot v. 1.1.4"; |
| 227 | + |
223 | 228 | /// <summary> |
224 | 229 | /// Separator |
225 | 230 | /// </summary> |
226 | 231 | public static string separator = "|"; |
| 232 | + |
227 | 233 | /// <summary> |
228 | 234 | /// User name |
229 | 235 | /// </summary> |
230 | 236 | public static string name = "wm-bot"; |
| 237 | + |
231 | 238 | /// <summary> |
232 | 239 | /// Channels |
233 | 240 | /// </summary> |
Index: trunk/tools/wmib/Program.cs |
— | — | @@ -11,11 +11,7 @@ |
12 | 12 | // Created by Petr Bena benapetr@gmail.com |
13 | 13 | |
14 | 14 | using System; |
15 | | -using System.Collections.Generic; |
16 | | -using System.Text; |
17 | | -using System.Net; |
18 | 15 | |
19 | | - |
20 | 16 | namespace wmib |
21 | 17 | { |
22 | 18 | class Program |
— | — | @@ -25,6 +21,7 @@ |
26 | 22 | Console.WriteLine("LOG: " + msg); |
27 | 23 | return false; |
28 | 24 | } |
| 25 | + |
29 | 26 | static void Main(string[] args) |
30 | 27 | { |
31 | 28 | Log("Connecting"); |
Index: trunk/tools/wmib/Core.cs |
— | — | @@ -10,10 +10,8 @@ |
11 | 11 | |
12 | 12 | using System; |
13 | 13 | using System.Collections.Generic; |
14 | | -using System.Text; |
15 | | -using System.Net; |
| 14 | +using System.IO; |
16 | 15 | |
17 | | - |
18 | 16 | namespace wmib |
19 | 17 | { |
20 | 18 | public class misc |
— | — | @@ -39,8 +37,8 @@ |
40 | 38 | private static System.Net.Sockets.NetworkStream data; |
41 | 39 | public static System.Threading.Thread dumphtmt; |
42 | 40 | public static System.Threading.Thread check_thread; |
43 | | - public static System.IO.StreamReader rd; |
44 | | - private static System.IO.StreamWriter wd; |
| 41 | + public static StreamReader rd; |
| 42 | + private static StreamWriter wd; |
45 | 43 | private static List<user> User = new List<user>(); |
46 | 44 | |
47 | 45 | public class messages |
— | — | @@ -76,22 +74,25 @@ |
77 | 75 | public string value; |
78 | 76 | public string regex; |
79 | 77 | public bool searching; |
80 | | - public bool result = false; |
| 78 | + public bool result; |
| 79 | + |
81 | 80 | public RegexCheck(string Regex, string Data) |
82 | 81 | { |
83 | 82 | result = false; |
84 | 83 | value = Data; |
85 | 84 | regex = Regex; |
86 | 85 | } |
| 86 | + |
87 | 87 | private void Run() |
88 | 88 | { |
89 | 89 | System.Text.RegularExpressions.Regex c = new System.Text.RegularExpressions.Regex(regex); |
90 | 90 | result = c.Match(value).Success; |
91 | 91 | searching = false; |
92 | 92 | } |
| 93 | + |
93 | 94 | public int IsMatch() |
94 | 95 | { |
95 | | - System.Threading.Thread quick = new System.Threading.Thread(new System.Threading.ThreadStart(Run)); |
| 96 | + System.Threading.Thread quick = new System.Threading.Thread(Run); |
96 | 97 | searching = true; |
97 | 98 | quick.Start(); |
98 | 99 | int check = 0; |
— | — | @@ -99,17 +100,11 @@ |
100 | 101 | { |
101 | 102 | check++; |
102 | 103 | System.Threading.Thread.Sleep(10); |
103 | | - if (check > 50) |
104 | | - { |
105 | | - quick.Abort(); |
106 | | - return 2; |
107 | | - } |
| 104 | + if (check <= 50) continue; |
| 105 | + quick.Abort(); |
| 106 | + return 2; |
108 | 107 | } |
109 | | - if (result) |
110 | | - { |
111 | | - return 1; |
112 | | - } |
113 | | - return 0; |
| 108 | + return result ? 1 : 0; |
114 | 109 | } |
115 | 110 | } |
116 | 111 | |
— | — | @@ -126,7 +121,7 @@ |
127 | 122 | /// <summary> |
128 | 123 | /// File where data are stored |
129 | 124 | /// </summary> |
130 | | - public string File; |
| 125 | + public string DataFile; |
131 | 126 | |
132 | 127 | /// <summary> |
133 | 128 | /// Constructor |
— | — | @@ -135,14 +130,14 @@ |
136 | 131 | public IRCTrust(string channel) |
137 | 132 | { |
138 | 133 | // Load |
139 | | - File = channel + "_user"; |
140 | | - if (!System.IO.File.Exists(File)) |
| 134 | + DataFile = channel + "_user"; |
| 135 | + if (!File.Exists(DataFile)) |
141 | 136 | { |
142 | 137 | // Create db |
143 | 138 | Program.Log("Creating user file for " + channel); |
144 | | - System.IO.File.WriteAllText(File, ""); |
| 139 | + File.WriteAllText(DataFile, ""); |
145 | 140 | } |
146 | | - string[] db = System.IO.File.ReadAllLines(channel + "_user"); |
| 141 | + string[] db = File.ReadAllLines(channel + "_user"); |
147 | 142 | _Channel = channel; |
148 | 143 | foreach (string x in db) |
149 | 144 | { |
— | — | @@ -162,10 +157,10 @@ |
163 | 158 | /// <returns></returns> |
164 | 159 | public bool Save() |
165 | 160 | { |
166 | | - System.IO.File.WriteAllText(File, ""); |
| 161 | + File.WriteAllText(DataFile, ""); |
167 | 162 | foreach (user u in Users) |
168 | 163 | { |
169 | | - System.IO.File.AppendAllText(File, encode(u.name) + config.separator + u.level + "\n"); |
| 164 | + File.AppendAllText(DataFile, encode(u.name) + config.separator + u.level + "\n"); |
170 | 165 | } |
171 | 166 | return true; |
172 | 167 | } |
— | — | @@ -412,13 +407,13 @@ |
413 | 408 | public void Load() |
414 | 409 | { |
415 | 410 | text.Clear(); |
416 | | - if (!System.IO.File.Exists(datafile)) |
| 411 | + if (!File.Exists(datafile)) |
417 | 412 | { |
418 | 413 | // Create db |
419 | | - System.IO.File.WriteAllText(datafile, ""); |
| 414 | + File.WriteAllText(datafile, ""); |
420 | 415 | } |
421 | 416 | |
422 | | - string[] db = System.IO.File.ReadAllLines(datafile); |
| 417 | + string[] db = File.ReadAllLines(datafile); |
423 | 418 | foreach (string x in db) |
424 | 419 | { |
425 | 420 | if (x.Contains(config.separator)) |
— | — | @@ -460,14 +455,14 @@ |
461 | 456 | update = true; |
462 | 457 | try |
463 | 458 | { |
464 | | - System.IO.File.WriteAllText(datafile, ""); |
| 459 | + File.WriteAllText(datafile, ""); |
465 | 460 | foreach (staticalias key in Alias) |
466 | 461 | { |
467 | | - System.IO.File.AppendAllText(datafile, key.Name + config.separator + key.Key + config.separator + "alias" + "\n"); |
| 462 | + File.AppendAllText(datafile, key.Name + config.separator + key.Key + config.separator + "alias" + "\n"); |
468 | 463 | } |
469 | 464 | foreach (item key in text) |
470 | 465 | { |
471 | | - System.IO.File.AppendAllText(datafile, key.key + config.separator + key.text + config.separator + "key" + config.separator + key.locked + config.separator + key.user + "\n"); |
| 466 | + File.AppendAllText(datafile, key.key + config.separator + key.text + config.separator + "key" + config.separator + key.locked + config.separator + key.user + "\n"); |
472 | 467 | } |
473 | 468 | } |
474 | 469 | catch (Exception b) |
— | — | @@ -1016,7 +1011,7 @@ |
1017 | 1012 | { |
1018 | 1013 | log = "[" + timedateToString( System.DateTime.Now.Hour) + ":" + timedateToString( System.DateTime.Now.Minute ) + ":" + timedateToString( System.DateTime.Now.Second) + "] " + "<" + user + ">\t " + message + "\n"; |
1019 | 1014 | } |
1020 | | - System.IO.File.AppendAllText(channel.log + System.DateTime.Now.Year + System.DateTime.Now.Month + System.DateTime.Now.Day +".txt", log); |
| 1015 | + File.AppendAllText(channel.log + System.DateTime.Now.Year + System.DateTime.Now.Month + System.DateTime.Now.Day +".txt", log); |
1021 | 1016 | } |
1022 | 1017 | } |
1023 | 1018 | catch (Exception er) |
— | — | @@ -1119,12 +1114,12 @@ |
1120 | 1115 | wd.WriteLine("PART " + chan.name); |
1121 | 1116 | System.Threading.Thread.Sleep(100); |
1122 | 1117 | wd.Flush(); |
1123 | | - if (!System.IO.Directory.Exists(chan.log)) |
| 1118 | + if (!Directory.Exists(chan.log)) |
1124 | 1119 | { |
1125 | | - System.IO.Directory.Delete(chan.log, true); |
| 1120 | + Directory.Delete(chan.log, true); |
1126 | 1121 | } |
1127 | | - System.IO.File.Delete(chan.name + ".setting"); |
1128 | | - System.IO.File.Delete(chan.Users.File); |
| 1122 | + File.Delete(chan.name + ".setting"); |
| 1123 | + File.Delete(chan.Users.DataFile); |
1129 | 1124 | config.channels.Remove(chan); |
1130 | 1125 | config.Save(); |
1131 | 1126 | return; |
— | — | @@ -1295,11 +1290,8 @@ |
1296 | 1291 | return; |
1297 | 1292 | } |
1298 | 1293 | } |
1299 | | - else |
1300 | | - { |
1301 | | - Message(messages.PermissionDenied, chan.name); |
1302 | | - return; |
1303 | | - } |
| 1294 | + Message(messages.PermissionDenied, chan.name); |
| 1295 | + return; |
1304 | 1296 | } |
1305 | 1297 | if (message == "@commands") |
1306 | 1298 | { |
— | — | @@ -1350,8 +1342,8 @@ |
1351 | 1343 | public static bool Reconnect() |
1352 | 1344 | { |
1353 | 1345 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
1354 | | - rd = new System.IO.StreamReader(data, System.Text.Encoding.UTF8); |
1355 | | - wd = new System.IO.StreamWriter(data); |
| 1346 | + rd = new StreamReader(data, System.Text.Encoding.UTF8); |
| 1347 | + wd = new StreamWriter(data); |
1356 | 1348 | wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
1357 | 1349 | wd.WriteLine("NICK " + config.username); |
1358 | 1350 | Authenticate(); |
— | — | @@ -1371,12 +1363,12 @@ |
1372 | 1364 | public static int Connect() |
1373 | 1365 | { |
1374 | 1366 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
1375 | | - rd = new System.IO.StreamReader(data, System.Text.Encoding.UTF8); |
1376 | | - wd = new System.IO.StreamWriter(data); |
| 1367 | + rd = new StreamReader(data, System.Text.Encoding.UTF8); |
| 1368 | + wd = new StreamWriter(data); |
1377 | 1369 | |
1378 | | - dumphtmt = new System.Threading.Thread(new System.Threading.ThreadStart(HtmlDump.Start)); |
| 1370 | + dumphtmt = new System.Threading.Thread(HtmlDump.Start); |
1379 | 1371 | dumphtmt.Start(); |
1380 | | - check_thread = new System.Threading.Thread(new System.Threading.ThreadStart(Ping)); |
| 1372 | + check_thread = new System.Threading.Thread(Ping); |
1381 | 1373 | check_thread.Start(); |
1382 | 1374 | |
1383 | 1375 | wd.WriteLine("USER " + config.name + " 8 * :" + config.name); |
— | — | @@ -1440,11 +1432,8 @@ |
1441 | 1433 | getAction(message.Replace(delimiter.ToString() +"ACTION", ""), channel, host, nick); |
1442 | 1434 | continue; |
1443 | 1435 | } |
1444 | | - else |
1445 | | - { |
1446 | | - getMessage(channel, nick, host, message); |
1447 | | - continue; |
1448 | | - } |
| 1436 | + getMessage(channel, nick, host, message); |
| 1437 | + continue; |
1449 | 1438 | } |
1450 | 1439 | else |
1451 | 1440 | { |
— | — | @@ -1489,7 +1478,7 @@ |
1490 | 1479 | Program.Log("Reconnecting, end of data stream"); |
1491 | 1480 | Reconnect(); |
1492 | 1481 | } |
1493 | | - catch (System.IO.IOException xx) |
| 1482 | + catch (IOException xx) |
1494 | 1483 | { |
1495 | 1484 | Program.Log("Reconnecting, connection failed " + xx.Message + xx.StackTrace); |
1496 | 1485 | Reconnect(); |
— | — | @@ -1501,6 +1490,7 @@ |
1502 | 1491 | } |
1503 | 1492 | return 0; |
1504 | 1493 | } |
| 1494 | + |
1505 | 1495 | public static int Disconnect() |
1506 | 1496 | { |
1507 | 1497 | wd.Flush(); |