Index: trunk/tools/wmib/DumpHtm.cs |
— | — | @@ -18,9 +18,15 @@ |
19 | 19 | |
20 | 20 | namespace wmib |
21 | 21 | { |
22 | | -public class HtmlDump |
| 22 | + public class HtmlDump |
23 | 23 | { |
| 24 | + /// <summary> |
| 25 | + /// Channel name |
| 26 | + /// </summary> |
24 | 27 | public config.channel Channel; |
| 28 | + /// <summary> |
| 29 | + /// Dump |
| 30 | + /// </summary> |
25 | 31 | public string dumpname; |
26 | 32 | // This function is called on start of bot |
27 | 33 | public static void Start() |
— | — | @@ -39,29 +45,60 @@ |
40 | 46 | System.Threading.Thread.Sleep(320000); |
41 | 47 | } |
42 | 48 | } |
| 49 | + /// <summary> |
| 50 | + /// Constructor |
| 51 | + /// </summary> |
| 52 | + /// <param name="channel"></param> |
43 | 53 | public HtmlDump(config.channel channel) |
44 | 54 | { |
45 | 55 | dumpname = config.DumpDir + "/" + channel.name + ".htm"; |
46 | 56 | Channel = channel; |
47 | 57 | } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Html code |
| 61 | + /// </summary> |
| 62 | + /// <returns></returns> |
48 | 63 | public string CreateFooter() |
49 | 64 | { |
50 | 65 | return "</body></html>\n"; |
51 | 66 | } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Html |
| 70 | + /// </summary> |
| 71 | + /// <returns></returns> |
52 | 72 | public string CreateHeader() |
53 | 73 | { |
54 | | - return "<html><head></head><body>\n"; |
| 74 | + return "<html><head><title>"+ Channel.name +"</title></head><body>\n"; |
55 | 75 | } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Remove html |
| 79 | + /// </summary> |
| 80 | + /// <param name="text"></param> |
| 81 | + /// <returns></returns> |
56 | 82 | public string Encode(string text) |
57 | 83 | { |
58 | 84 | text = text.Replace("<", "<"); |
59 | 85 | text = text.Replace(">", ">"); |
60 | 86 | return text; |
61 | 87 | } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Insert another table row |
| 91 | + /// </summary> |
| 92 | + /// <param name="name"></param> |
| 93 | + /// <param name="value"></param> |
| 94 | + /// <returns></returns> |
62 | 95 | public string AddLine(string name, string value) |
63 | 96 | { |
64 | 97 | return "<tr><td>" + Encode(name) + "</td><td>" + Encode(value) + "</td></tr>\n"; |
65 | 98 | } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Generate a dump file |
| 102 | + /// </summary> |
66 | 103 | public void Make() |
67 | 104 | { |
68 | 105 | try |
— | — | @@ -81,7 +118,8 @@ |
82 | 119 | text = text + "<table>\n"; |
83 | 120 | text = text + CreateFooter(); |
84 | 121 | System.IO.File.WriteAllText(dumpname, text); |
85 | | - } catch (Exception b) |
| 122 | + } |
| 123 | + catch (Exception b) |
86 | 124 | { |
87 | 125 | Channel.Keys.locked = false; |
88 | 126 | Console.WriteLine(b.Message); |
Index: trunk/tools/wmib/Config.cs |
— | — | @@ -20,39 +20,48 @@ |
21 | 21 | { |
22 | 22 | public static class config |
23 | 23 | { |
24 | | - public static string text; |
25 | | - private static void AddConfig(string a, string b) |
26 | | - { |
27 | | - text = text + "\n" + a + "=" + b + ";"; |
28 | | - } |
29 | | - public static void Save() |
30 | | - { |
31 | | - text =""; |
32 | | - AddConfig("username", username); |
33 | | - AddConfig("password", password); |
34 | | - AddConfig("network", network); |
35 | | - AddConfig("nick", login); |
36 | | - text = text + "\nchannels="; |
37 | | - foreach (channel current in channels) |
38 | | - { |
39 | | - text = text + current.name + ",\n"; |
40 | | - } |
41 | | - text = text + ";"; |
42 | | - System.IO.File.WriteAllText("wmib", text); |
43 | | - } |
44 | 24 | public class channel |
45 | 25 | { |
| 26 | + /// <summary> |
| 27 | + /// Channel name |
| 28 | + /// </summary> |
46 | 29 | public string name; |
47 | 30 | public bool logged; |
| 31 | + /// <summary> |
| 32 | + /// Log |
| 33 | + /// </summary> |
48 | 34 | public string log; |
| 35 | + public bool info; |
| 36 | + /// <summary> |
| 37 | + /// Keys |
| 38 | + /// </summary> |
49 | 39 | public irc.dictionary Keys; |
| 40 | + /// <summary> |
| 41 | + /// Configuration text |
| 42 | + /// </summary> |
50 | 43 | private string conf; |
| 44 | + /// <summary> |
| 45 | + /// Users |
| 46 | + /// </summary> |
51 | 47 | public irc.IRCTrust Users; |
| 48 | + /// <summary> |
| 49 | + /// Path of db |
| 50 | + /// </summary> |
52 | 51 | public string keydb = ""; |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Add a line to config |
| 55 | + /// </summary> |
| 56 | + /// <param name="a">Name of key</param> |
| 57 | + /// <param name="b">Value</param> |
53 | 58 | private void AddConfig(string a, string b) |
54 | 59 | { |
55 | 60 | conf = conf + "\n" + a + "=" + b + ";"; |
56 | 61 | } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Load config of channel :) |
| 65 | + /// </summary> |
57 | 66 | public void LoadConfig() |
58 | 67 | { |
59 | 68 | string conf_file = name + ".setting"; |
— | — | @@ -71,19 +80,33 @@ |
72 | 81 | { |
73 | 82 | logged = bool.Parse(config.parseConfig(conf, "logged")); |
74 | 83 | } |
| 84 | + if (config.parseConfig(conf, "infodb") != "") |
| 85 | + { |
| 86 | + info = bool.Parse(config.parseConfig(conf, "infodb")); |
| 87 | + } |
75 | 88 | } |
76 | 89 | |
| 90 | + /// <summary> |
| 91 | + /// Save config |
| 92 | + /// </summary> |
77 | 93 | public void SaveConfig() |
78 | 94 | { |
79 | 95 | conf = ""; |
| 96 | + AddConfig("infodb", info.ToString()); |
| 97 | + AddConfig("logged", logged.ToString()); |
80 | 98 | AddConfig("keysdb", keydb); |
81 | | - AddConfig("logged", logged.ToString()); |
82 | 99 | System.IO.File.WriteAllText(name + ".setting", conf); |
83 | 100 | } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Constructor |
| 104 | + /// </summary> |
| 105 | + /// <param name="Name">Channel</param> |
84 | 106 | public channel(string Name) |
85 | 107 | { |
86 | 108 | conf = ""; |
87 | 109 | keydb = Name + ".db"; |
| 110 | + info = true; |
88 | 111 | logged = true; |
89 | 112 | name = Name; |
90 | 113 | LoadConfig(); |
— | — | @@ -101,6 +124,38 @@ |
102 | 125 | } |
103 | 126 | } |
104 | 127 | |
| 128 | + /// <summary> |
| 129 | + /// Add line to the config file |
| 130 | + /// </summary> |
| 131 | + /// <param name="a"></param> |
| 132 | + /// <param name="b"></param> |
| 133 | + private static void AddConfig(string a, string b) |
| 134 | + { |
| 135 | + text = text + "\n" + a + "=" + b + ";"; |
| 136 | + } |
| 137 | + |
| 138 | + public static void Save() |
| 139 | + { |
| 140 | + text = ""; |
| 141 | + AddConfig("username", username); |
| 142 | + AddConfig("password", password); |
| 143 | + AddConfig("network", network); |
| 144 | + AddConfig("nick", login); |
| 145 | + text = text + "\nchannels="; |
| 146 | + foreach (channel current in channels) |
| 147 | + { |
| 148 | + text = text + current.name + ",\n"; |
| 149 | + } |
| 150 | + text = text + ";"; |
| 151 | + System.IO.File.WriteAllText("wmib", text); |
| 152 | + } |
| 153 | + |
| 154 | + /// <summary> |
| 155 | + /// Parse config data text |
| 156 | + /// </summary> |
| 157 | + /// <param name="text"></param> |
| 158 | + /// <param name="name"></param> |
| 159 | + /// <returns></returns> |
105 | 160 | public static string parseConfig(string text, string name) |
106 | 161 | { |
107 | 162 | if (text.Contains(name)) |
— | — | @@ -113,6 +168,9 @@ |
114 | 169 | return ""; |
115 | 170 | } |
116 | 171 | |
| 172 | + /// <summary> |
| 173 | + /// Load config of bot |
| 174 | + /// </summary> |
117 | 175 | public static void Load() |
118 | 176 | { |
119 | 177 | text = System.IO.File.ReadAllText("wmib"); |
— | — | @@ -133,6 +191,7 @@ |
134 | 192 | System.IO.Directory.CreateDirectory(config.DumpDir); |
135 | 193 | } |
136 | 194 | } |
| 195 | + public static string text; |
137 | 196 | /// <summary> |
138 | 197 | /// Network |
139 | 198 | /// </summary> |
— | — | @@ -141,13 +200,25 @@ |
142 | 201 | /// Nick name |
143 | 202 | /// </summary> |
144 | 203 | public static string username = "wm-bot"; |
| 204 | + /// <summary> |
| 205 | + /// Login name |
| 206 | + /// </summary> |
145 | 207 | public static string login = ""; |
| 208 | + /// <summary> |
| 209 | + /// Login pw |
| 210 | + /// </summary> |
146 | 211 | public static string password = ""; |
| 212 | + /// <summary> |
| 213 | + /// Dump |
| 214 | + /// </summary> |
147 | 215 | public static string DumpDir = "dump"; |
148 | 216 | /// <summary> |
149 | 217 | /// Version |
150 | 218 | /// </summary> |
151 | 219 | public static string version = "wikimedia bot v. 1.1.4"; |
| 220 | + /// <summary> |
| 221 | + /// Separator |
| 222 | + /// </summary> |
152 | 223 | public static string separator = "|"; |
153 | 224 | /// <summary> |
154 | 225 | /// User name |
Index: trunk/tools/wmib/Core.cs |
— | — | @@ -25,53 +25,47 @@ |
26 | 26 | private static System.IO.StreamWriter wd; |
27 | 27 | private static List<user> User = new List<user>(); |
28 | 28 | |
29 | | - public static void Ping() |
30 | | - { |
31 | | - while (true) |
32 | | - { |
33 | | - System.Threading.Thread.Sleep(20000); |
34 | | - wd.WriteLine("PING :" + config.network); |
35 | | - wd.Flush(); |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - public static string encode(string text) |
40 | | - { |
41 | | - return text.Replace(config.separator, "<separator>"); |
42 | | - } |
43 | | - |
44 | | - public static bool Authenticate() |
45 | | - { |
46 | | - if (config.login != "") |
47 | | - { |
48 | | - wd.WriteLine("PRIVMSG nickserv :identify " + config.login + " " + config.password); |
49 | | - wd.Flush(); |
50 | | - System.Threading.Thread.Sleep(4000); |
51 | | - } |
52 | | - return true; |
53 | | - } |
54 | | - |
55 | | - public static string decode(string text) |
56 | | - { |
57 | | - return text.Replace("<separator>", config.separator); |
58 | | - } |
59 | | - |
60 | 29 | public class user |
61 | 30 | { |
| 31 | + /// <summary> |
| 32 | + /// Regex |
| 33 | + /// </summary> |
| 34 | + public string name; |
| 35 | + /// <summary> |
| 36 | + /// Level |
| 37 | + /// </summary> |
| 38 | + public string level; |
| 39 | + /// <summary> |
| 40 | + /// Constructor |
| 41 | + /// </summary> |
| 42 | + /// <param name="level"></param> |
| 43 | + /// <param name="name"></param> |
62 | 44 | public user(string level, string name) |
63 | 45 | { |
64 | 46 | this.level = level; |
65 | 47 | this.name = name; |
66 | 48 | } |
67 | | - public string name; |
68 | | - public string level; |
69 | 49 | } |
70 | 50 | |
71 | 51 | public class IRCTrust |
72 | 52 | { |
| 53 | + /// <summary> |
| 54 | + /// List of all users in a channel |
| 55 | + /// </summary> |
73 | 56 | private List<user> Users = new List<user>(); |
| 57 | + /// <summary> |
| 58 | + /// Channel this class belong to |
| 59 | + /// </summary> |
74 | 60 | public string _Channel; |
| 61 | + /// <summary> |
| 62 | + /// File where data are stored |
| 63 | + /// </summary> |
75 | 64 | public string File; |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Constructor |
| 68 | + /// </summary> |
| 69 | + /// <param name="channel"></param> |
76 | 70 | public IRCTrust(string channel) |
77 | 71 | { |
78 | 72 | // Load |
— | — | @@ -95,6 +89,11 @@ |
96 | 90 | } |
97 | 91 | } |
98 | 92 | } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Save |
| 96 | + /// </summary> |
| 97 | + /// <returns></returns> |
99 | 98 | public bool Save() |
100 | 99 | { |
101 | 100 | System.IO.File.WriteAllText(File, ""); |
— | — | @@ -105,6 +104,12 @@ |
106 | 105 | return true; |
107 | 106 | } |
108 | 107 | |
| 108 | + /// <summary> |
| 109 | + /// New |
| 110 | + /// </summary> |
| 111 | + /// <param name="level">Level</param> |
| 112 | + /// <param name="user">Regex</param> |
| 113 | + /// <returns></returns> |
109 | 114 | public bool addUser(string level, string user) |
110 | 115 | { |
111 | 116 | foreach (user u in Users) |
— | — | @@ -119,6 +124,11 @@ |
120 | 125 | return true; |
121 | 126 | } |
122 | 127 | |
| 128 | + /// <summary> |
| 129 | + /// |
| 130 | + /// </summary> |
| 131 | + /// <param name="user">Regex</param> |
| 132 | + /// <returns></returns> |
123 | 133 | public bool delUser(string user) |
124 | 134 | { |
125 | 135 | foreach (user u in Users) |
— | — | @@ -140,6 +150,11 @@ |
141 | 151 | return true; |
142 | 152 | } |
143 | 153 | |
| 154 | + /// <summary> |
| 155 | + /// Return level |
| 156 | + /// </summary> |
| 157 | + /// <param name="level"></param> |
| 158 | + /// <returns></returns> |
144 | 159 | private int getLevel(string level) |
145 | 160 | { |
146 | 161 | if (level == "admin") |
— | — | @@ -153,6 +168,11 @@ |
154 | 169 | return 0; |
155 | 170 | } |
156 | 171 | |
| 172 | + /// <summary> |
| 173 | + /// Return user object from a name |
| 174 | + /// </summary> |
| 175 | + /// <param name="user"></param> |
| 176 | + /// <returns></returns> |
157 | 177 | public user getUser(string user) |
158 | 178 | { |
159 | 179 | user lv = new user("null", ""); |
— | — | @@ -172,6 +192,9 @@ |
173 | 193 | return lv; |
174 | 194 | } |
175 | 195 | |
| 196 | + /// <summary> |
| 197 | + /// List all users to a channel |
| 198 | + /// </summary> |
176 | 199 | public void listAll() |
177 | 200 | { |
178 | 201 | string users_ok = ""; |
— | — | @@ -182,6 +205,12 @@ |
183 | 206 | Message("I trust: " + users_ok, _Channel); |
184 | 207 | } |
185 | 208 | |
| 209 | + /// <summary> |
| 210 | + /// Check if user match the necessary level |
| 211 | + /// </summary> |
| 212 | + /// <param name="level"></param> |
| 213 | + /// <param name="rights"></param> |
| 214 | + /// <returns></returns> |
186 | 215 | public bool matchLevel(int level, string rights) |
187 | 216 | { |
188 | 217 | if (level == 2) |
— | — | @@ -195,6 +224,13 @@ |
196 | 225 | return false; |
197 | 226 | } |
198 | 227 | |
| 228 | + /// <summary> |
| 229 | + /// Check if user is approved to do operation requested |
| 230 | + /// </summary> |
| 231 | + /// <param name="User"></param> |
| 232 | + /// <param name="Host"></param> |
| 233 | + /// <param name="command"></param> |
| 234 | + /// <returns></returns> |
199 | 235 | public bool isApproved(string User, string Host, string command) |
200 | 236 | { |
201 | 237 | user current = getUser(User + "!@" + Host); |
— | — | @@ -221,12 +257,35 @@ |
222 | 258 | |
223 | 259 | public class dictionary |
224 | 260 | { |
| 261 | + /// <summary> |
| 262 | + /// Data file |
| 263 | + /// </summary> |
225 | 264 | public string datafile = ""; |
226 | 265 | // if we need to update dump |
227 | 266 | public bool update = true; |
| 267 | + /// <summary> |
| 268 | + /// Locked |
| 269 | + /// </summary> |
228 | 270 | public bool locked = false; |
229 | 271 | public class item |
230 | 272 | { |
| 273 | + /// <summary> |
| 274 | + /// Text |
| 275 | + /// </summary> |
| 276 | + public string text; |
| 277 | + /// <summary> |
| 278 | + /// Key |
| 279 | + /// </summary> |
| 280 | + public string key; |
| 281 | + public string user; |
| 282 | + public string locked; |
| 283 | + /// <summary> |
| 284 | + /// Constructor |
| 285 | + /// </summary> |
| 286 | + /// <param name="Key"></param> |
| 287 | + /// <param name="Text"></param> |
| 288 | + /// <param name="User"></param> |
| 289 | + /// <param name="Lock"></param> |
231 | 290 | public item(string Key, string Text, string User, string Lock = "false") |
232 | 291 | { |
233 | 292 | text = Text; |
— | — | @@ -234,24 +293,43 @@ |
235 | 294 | locked = Lock; |
236 | 295 | user = User; |
237 | 296 | } |
238 | | - public string text; |
239 | | - public string key; |
240 | | - public string user; |
241 | | - public string locked; |
242 | 297 | } |
243 | 298 | public class staticalias |
244 | 299 | { |
| 300 | + /// <summary> |
| 301 | + /// Name |
| 302 | + /// </summary> |
245 | 303 | public string Name; |
| 304 | + /// <summary> |
| 305 | + /// Key |
| 306 | + /// </summary> |
246 | 307 | public string Key; |
| 308 | + /// <summary> |
| 309 | + /// Constructor |
| 310 | + /// </summary> |
| 311 | + /// <param name="name"></param> |
| 312 | + /// <param name="key"></param> |
247 | 313 | public staticalias(string name, string key) |
248 | 314 | { |
249 | 315 | Name = name; |
250 | 316 | Key = key; |
251 | 317 | } |
252 | 318 | } |
| 319 | + /// <summary> |
| 320 | + /// List of all items in class |
| 321 | + /// </summary> |
253 | 322 | public List<item> text = new List<item>(); |
| 323 | + /// <summary> |
| 324 | + /// List of all aliases we want to use |
| 325 | + /// </summary> |
254 | 326 | public List<staticalias> Alias = new List<staticalias>(); |
| 327 | + /// <summary> |
| 328 | + /// Channel name |
| 329 | + /// </summary> |
255 | 330 | public string Channel; |
| 331 | + /// <summary> |
| 332 | + /// Load it |
| 333 | + /// </summary> |
256 | 334 | public void Load() |
257 | 335 | { |
258 | 336 | text.Clear(); |
— | — | @@ -282,6 +360,11 @@ |
283 | 361 | } |
284 | 362 | } |
285 | 363 | |
| 364 | + /// <summary> |
| 365 | + /// Constructor |
| 366 | + /// </summary> |
| 367 | + /// <param name="database"></param> |
| 368 | + /// <param name="channel"></param> |
286 | 369 | public dictionary(string database, string channel) |
287 | 370 | { |
288 | 371 | datafile = database; |
— | — | @@ -289,6 +372,9 @@ |
290 | 373 | Load(); |
291 | 374 | } |
292 | 375 | |
| 376 | + /// <summary> |
| 377 | + /// Save to a file |
| 378 | + /// </summary> |
293 | 379 | public void Save() |
294 | 380 | { |
295 | 381 | update = true; |
— | — | @@ -310,6 +396,11 @@ |
311 | 397 | } |
312 | 398 | } |
313 | 399 | |
| 400 | + /// <summary> |
| 401 | + /// Get value of key |
| 402 | + /// </summary> |
| 403 | + /// <param name="key"></param> |
| 404 | + /// <returns></returns> |
314 | 405 | public string getValue(string key) |
315 | 406 | { |
316 | 407 | foreach (item data in text) |
— | — | @@ -322,6 +413,14 @@ |
323 | 414 | return ""; |
324 | 415 | } |
325 | 416 | |
| 417 | + /// <summary> |
| 418 | + /// Print a value to channel if found this message doesn't need to be a valid command |
| 419 | + /// </summary> |
| 420 | + /// <param name="name"></param> |
| 421 | + /// <param name="user"></param> |
| 422 | + /// <param name="chan"></param> |
| 423 | + /// <param name="host"></param> |
| 424 | + /// <returns></returns> |
326 | 425 | public bool print(string name, string user, config.channel chan, string host) |
327 | 426 | { |
328 | 427 | if (!name.StartsWith("!")) |
— | — | @@ -356,7 +455,12 @@ |
357 | 456 | config.channel _Chan = getChannel(Channel); |
358 | 457 | if (chan.Users.isApproved(user, host, "info")) |
359 | 458 | { |
360 | | - this.aliasKey(name.Substring(name.IndexOf("alias") + 6), parm[0], ""); |
| 459 | + if (parm.Length < 3) |
| 460 | + { |
| 461 | + Message("It would be cool to give me also a name of key", Channel); |
| 462 | + return true; |
| 463 | + } |
| 464 | + this.aliasKey(name.Substring(name.IndexOf(" alias") + 7), parm[0], ""); |
361 | 465 | } |
362 | 466 | else |
363 | 467 | { |
— | — | @@ -379,6 +483,7 @@ |
380 | 484 | return false; |
381 | 485 | } |
382 | 486 | } |
| 487 | + return false; |
383 | 488 | } |
384 | 489 | else |
385 | 490 | { |
— | — | @@ -449,6 +554,11 @@ |
450 | 555 | return true; |
451 | 556 | } |
452 | 557 | |
| 558 | + /// <summary> |
| 559 | + /// Search |
| 560 | + /// </summary> |
| 561 | + /// <param name="key"></param> |
| 562 | + /// <param name="Chan"></param> |
453 | 563 | public void RSearch(string key, config.channel Chan) |
454 | 564 | { |
455 | 565 | if (!key.StartsWith("@regsearch")) |
— | — | @@ -510,6 +620,12 @@ |
511 | 621 | } |
512 | 622 | } |
513 | 623 | |
| 624 | + /// <summary> |
| 625 | + /// Save a new key |
| 626 | + /// </summary> |
| 627 | + /// <param name="Text"></param> |
| 628 | + /// <param name="key"></param> |
| 629 | + /// <param name="user"></param> |
514 | 630 | public void setKey(string Text, string key, string user) |
515 | 631 | { |
516 | 632 | while (locked) |
— | — | @@ -535,6 +651,13 @@ |
536 | 652 | handleException(b, Channel); |
537 | 653 | } |
538 | 654 | } |
| 655 | + |
| 656 | + /// <summary> |
| 657 | + /// Alias |
| 658 | + /// </summary> |
| 659 | + /// <param name="key"></param> |
| 660 | + /// <param name="al"></param> |
| 661 | + /// <param name="user"></param> |
539 | 662 | public void aliasKey(string key, string al, string user) |
540 | 663 | { |
541 | 664 | foreach(staticalias stakey in this.Alias) |
— | — | @@ -549,6 +672,7 @@ |
550 | 673 | Message("Successfully created", Channel); |
551 | 674 | Save(); |
552 | 675 | } |
| 676 | + |
553 | 677 | public void rmKey(string key, string user) |
554 | 678 | { |
555 | 679 | while (locked) |
— | — | @@ -569,11 +693,69 @@ |
570 | 694 | } |
571 | 695 | } |
572 | 696 | |
| 697 | + /// <summary> |
| 698 | + /// Ping |
| 699 | + /// </summary> |
| 700 | + public static void Ping() |
| 701 | + { |
| 702 | + while (true) |
| 703 | + { |
| 704 | + System.Threading.Thread.Sleep(20000); |
| 705 | + wd.WriteLine("PING :" + config.network); |
| 706 | + wd.Flush(); |
| 707 | + } |
| 708 | + } |
| 709 | + |
| 710 | + /// <summary> |
| 711 | + /// Encode a data before saving it to a file |
| 712 | + /// </summary> |
| 713 | + /// <param name="text"></param> |
| 714 | + /// <returns></returns> |
| 715 | + public static string encode(string text) |
| 716 | + { |
| 717 | + return text.Replace(config.separator, "<separator>"); |
| 718 | + } |
| 719 | + |
| 720 | + /// <summary> |
| 721 | + /// Nickserv |
| 722 | + /// </summary> |
| 723 | + /// <returns></returns> |
| 724 | + public static bool Authenticate() |
| 725 | + { |
| 726 | + if (config.login != "") |
| 727 | + { |
| 728 | + wd.WriteLine("PRIVMSG nickserv :identify " + config.login + " " + config.password); |
| 729 | + wd.Flush(); |
| 730 | + System.Threading.Thread.Sleep(4000); |
| 731 | + } |
| 732 | + return true; |
| 733 | + } |
| 734 | + |
| 735 | + /// <summary> |
| 736 | + /// Decode |
| 737 | + /// </summary> |
| 738 | + /// <param name="text"></param> |
| 739 | + /// <returns></returns> |
| 740 | + public static string decode(string text) |
| 741 | + { |
| 742 | + return text.Replace("<separator>", config.separator); |
| 743 | + } |
| 744 | + |
| 745 | + /// <summary> |
| 746 | + /// Exceptions :o |
| 747 | + /// </summary> |
| 748 | + /// <param name="ex"></param> |
| 749 | + /// <param name="chan"></param> |
573 | 750 | public static void handleException(Exception ex, string chan) |
574 | 751 | { |
575 | 752 | Message("DEBUG Exception: " + ex.Message + " I feel crushed, uh :|", chan); |
576 | 753 | } |
577 | 754 | |
| 755 | + /// <summary> |
| 756 | + /// Get a channel object |
| 757 | + /// </summary> |
| 758 | + /// <param name="name"></param> |
| 759 | + /// <returns></returns> |
578 | 760 | public static config.channel getChannel(string name) |
579 | 761 | { |
580 | 762 | foreach (config.channel current in config.channels) |
— | — | @@ -586,6 +768,12 @@ |
587 | 769 | return null; |
588 | 770 | } |
589 | 771 | |
| 772 | + /// <summary> |
| 773 | + /// Send a message to channel |
| 774 | + /// </summary> |
| 775 | + /// <param name="message"></param> |
| 776 | + /// <param name="channel"></param> |
| 777 | + /// <returns></returns> |
590 | 778 | public static bool Message(string message, string channel) |
591 | 779 | { |
592 | 780 | wd.WriteLine("PRIVMSG " + channel + " :" + message); |
— | — | @@ -593,6 +781,14 @@ |
594 | 782 | return true; |
595 | 783 | } |
596 | 784 | |
| 785 | + /// <summary> |
| 786 | + /// Change rights of user |
| 787 | + /// </summary> |
| 788 | + /// <param name="message"></param> |
| 789 | + /// <param name="channel"></param> |
| 790 | + /// <param name="user"></param> |
| 791 | + /// <param name="host"></param> |
| 792 | + /// <returns></returns> |
597 | 793 | public static int modifyRights(string message, config.channel channel, string user, string host) |
598 | 794 | { |
599 | 795 | try |
— | — | @@ -661,6 +857,14 @@ |
662 | 858 | return 0; |
663 | 859 | } |
664 | 860 | |
| 861 | + /// <summary> |
| 862 | + /// Log file |
| 863 | + /// </summary> |
| 864 | + /// <param name="message"></param> |
| 865 | + /// <param name="channel"></param> |
| 866 | + /// <param name="user"></param> |
| 867 | + /// <param name="host"></param> |
| 868 | + /// <param name="noac"></param> |
665 | 869 | public static void chanLog(string message, config.channel channel, string user, string host, bool noac = true) |
666 | 870 | { |
667 | 871 | try |
— | — | @@ -686,6 +890,14 @@ |
687 | 891 | } |
688 | 892 | } |
689 | 893 | |
| 894 | + /// <summary> |
| 895 | + /// Called on action |
| 896 | + /// </summary> |
| 897 | + /// <param name="message"></param> |
| 898 | + /// <param name="Channel"></param> |
| 899 | + /// <param name="host"></param> |
| 900 | + /// <param name="nick"></param> |
| 901 | + /// <returns></returns> |
690 | 902 | public static bool getAction(string message, string Channel, string host, string nick) |
691 | 903 | { |
692 | 904 | config.channel curr = getChannel(Channel); |
— | — | @@ -693,6 +905,13 @@ |
694 | 906 | return false; |
695 | 907 | } |
696 | 908 | |
| 909 | + /// <summary> |
| 910 | + /// |
| 911 | + /// </summary> |
| 912 | + /// <param name="chan"></param> |
| 913 | + /// <param name="user"></param> |
| 914 | + /// <param name="host"></param> |
| 915 | + /// <param name="message"></param> |
697 | 916 | public static void addChannel(config.channel chan, string user, string host, string message) |
698 | 917 | { |
699 | 918 | if (message.StartsWith("@add")) |
— | — | @@ -720,7 +939,7 @@ |
721 | 940 | wd.Flush(); |
722 | 941 | System.Threading.Thread.Sleep(100); |
723 | 942 | config.channel Chan = getChannel(channel); |
724 | | - Chan.Users.addUser("admin", user + ".*" + host ); |
| 943 | + Chan.Users.addUser("admin", user + "!.*@" + host ); |
725 | 944 | } else |
726 | 945 | { |
727 | 946 | Message("Invalid name", chan.name); |
— | — | @@ -732,8 +951,32 @@ |
733 | 952 | } |
734 | 953 | } |
735 | 954 | |
| 955 | + /// <summary> |
| 956 | + /// Part a channel |
| 957 | + /// </summary> |
| 958 | + /// <param name="chan">Channel object</param> |
| 959 | + /// <param name="user">User</param> |
| 960 | + /// <param name="host">Host</param> |
| 961 | + /// <param name="message">Message</param> |
736 | 962 | public static void partChannel(config.channel chan, string user, string host, string message) |
737 | 963 | { |
| 964 | + if (message.StartsWith("@drop")) |
| 965 | + { |
| 966 | + if (chan.Users.isApproved(user, host, "admin")) |
| 967 | + { |
| 968 | + wd.WriteLine("PART " + chan.name); |
| 969 | + System.Threading.Thread.Sleep(100); |
| 970 | + System.IO.File.Delete(chan.Users.File); |
| 971 | + wd.Flush(); |
| 972 | + System.IO.File.Delete(chan.name + ".setting"); |
| 973 | + config.channels.Remove(chan); |
| 974 | + config.Save(); |
| 975 | + } |
| 976 | + else |
| 977 | + { |
| 978 | + Message("Permission denied", chan.name); |
| 979 | + } |
| 980 | + } |
738 | 981 | if (message.StartsWith("@part")) |
739 | 982 | { |
740 | 983 | if (chan.Users.isApproved(user, host, "admin")) |
— | — | @@ -816,15 +1059,79 @@ |
817 | 1060 | } |
818 | 1061 | Message("I am now in following channels: " + channels, chan.name); |
819 | 1062 | } |
| 1063 | + if (message.StartsWith("@infobot-off")) |
| 1064 | + { |
| 1065 | + if (chan.Users.isApproved(user, host, "admin")) |
| 1066 | + { |
| 1067 | + if (!chan.info) |
| 1068 | + { |
| 1069 | + Message("Channel had infobot disabled", chan.name); |
| 1070 | + } |
| 1071 | + else |
| 1072 | + { |
| 1073 | + Message("Infobot disabled", chan.name); |
| 1074 | + chan.info = false; |
| 1075 | + chan.SaveConfig(); |
| 1076 | + config.Save(); |
| 1077 | + } |
| 1078 | + } |
| 1079 | + else |
| 1080 | + { |
| 1081 | + Message("Permission denied", chan.name); |
| 1082 | + } |
| 1083 | + } |
| 1084 | + if (message.StartsWith("@infobot-on")) |
| 1085 | + { |
| 1086 | + if (chan.Users.isApproved(user, host, "admin")) |
| 1087 | + { |
| 1088 | + if (!chan.logged) |
| 1089 | + { |
| 1090 | + Message("Infobot was already enabled :O", chan.name); |
| 1091 | + } |
| 1092 | + else |
| 1093 | + { |
| 1094 | + chan.info = true; |
| 1095 | + config.Save(); |
| 1096 | + chan.SaveConfig(); |
| 1097 | + Message("Infobot enabled", chan.name); |
| 1098 | + } |
| 1099 | + } |
| 1100 | + else |
| 1101 | + { |
| 1102 | + Message("Permission denied", chan.name); |
| 1103 | + } |
| 1104 | + } |
| 1105 | + if (message.StartsWith("@commands")) |
| 1106 | + { |
| 1107 | + Message("Commands: channellist, trusted, trustadd, trustdel, infobot-off, infobot-on, drop, add, flush, logon, logoff", chan.name); |
| 1108 | + } |
| 1109 | + |
| 1110 | + if (message.StartsWith("@channellist")) |
| 1111 | + { |
| 1112 | + string channels = ""; |
| 1113 | + foreach (config.channel a in config.channels) |
| 1114 | + { |
| 1115 | + channels = channels + a.name + ", "; |
| 1116 | + } |
| 1117 | + Message("I am now in following channels: " + channels, chan.name); |
| 1118 | + } |
820 | 1119 | } |
821 | 1120 | |
| 1121 | + /// <summary> |
| 1122 | + /// Called when someone post a message to server |
| 1123 | + /// </summary> |
| 1124 | + /// <param name="channel"></param> |
| 1125 | + /// <param name="nick"></param> |
| 1126 | + /// <param name="host"></param> |
| 1127 | + /// <param name="message"></param> |
| 1128 | + /// <returns></returns> |
822 | 1129 | public static bool getMessage(string channel, string nick, string host, string message) |
823 | 1130 | { |
824 | 1131 | config.channel curr = getChannel(channel); |
825 | 1132 | if (curr != null) |
826 | 1133 | { |
827 | 1134 | chanLog(message, curr, nick, host); |
828 | | - if (message.StartsWith("!")) |
| 1135 | + if (message.StartsWith("!") && curr.info) |
829 | 1136 | { |
830 | 1137 | curr.Keys.print(message, nick, curr, host); |
831 | 1138 | } |
— | — | @@ -839,12 +1146,13 @@ |
840 | 1147 | } |
841 | 1148 | } |
842 | 1149 | |
843 | | - |
844 | | - |
845 | | - |
846 | 1150 | return false; |
847 | 1151 | } |
848 | 1152 | |
| 1153 | + /// <summary> |
| 1154 | + /// Connection |
| 1155 | + /// </summary> |
| 1156 | + /// <returns></returns> |
849 | 1157 | public static bool Reconnect() |
850 | 1158 | { |
851 | 1159 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
— | — | @@ -862,6 +1170,10 @@ |
863 | 1171 | return false; |
864 | 1172 | } |
865 | 1173 | |
| 1174 | + /// <summary> |
| 1175 | + /// Connection |
| 1176 | + /// </summary> |
| 1177 | + /// <returns></returns> |
866 | 1178 | public static int Connect() |
867 | 1179 | { |
868 | 1180 | data = new System.Net.Sockets.TcpClient(config.network, 6667).GetStream(); |
— | — | @@ -932,7 +1244,7 @@ |
933 | 1245 | message = message.Substring(message.IndexOf(":") + 1); |
934 | 1246 | if (message.Contains(delimiter.ToString() + "ACTION")) |
935 | 1247 | { |
936 | | - getAction(message.Replace("", "").Replace(delimiter.ToString() +"ACTION ", ""), channel, host, nick); |
| 1248 | + getAction(message.Replace(delimiter.ToString() +"ACTION", ""), channel, host, nick); |
937 | 1249 | continue; |
938 | 1250 | } |
939 | 1251 | else |