The easy to use and full featured Irc Bot everyone is talking about!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Configuration.cs 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading;
  7. using Newtonsoft.Json;
  8. namespace Combot.Modules.Plugins
  9. {
  10. public class Configuration : Module
  11. {
  12. private ReaderWriterLockSlim ConfigLock;
  13. public override void Initialize()
  14. {
  15. ConfigLock = new ReaderWriterLockSlim();
  16. Bot.CommandReceivedEvent += HandleCommandEvent;
  17. }
  18. public override void ParseCommand(CommandMessage command)
  19. {
  20. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  21. switch (foundCommand.Name)
  22. {
  23. case "Command Configuration":
  24. string parameter = command.Arguments["Parameter"];
  25. Module mod = Bot.Modules.Find(module => module.Commands.Exists(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name == command.Arguments["Command"]));
  26. if (mod != null)
  27. {
  28. Command cmd = mod.Commands.Find(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name == command.Arguments["Command"]);
  29. string action = command.Arguments["Action"];
  30. switch (parameter)
  31. {
  32. case "name":
  33. switch (action.ToLower())
  34. {
  35. case "edit":
  36. ConfigLock.EnterWriteLock();
  37. cmd.Name = command.Arguments["Value"];
  38. mod.SaveConfig();
  39. string editMessage = string.Format("Command Name is now: \u0002{0}\u0002", cmd.Name);
  40. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  41. ConfigLock.ExitWriteLock();
  42. break;
  43. case "view":
  44. string viewMessage = string.Format("Command Name: \u0002{0}\u0002", cmd.Name);
  45. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  46. break;
  47. }
  48. break;
  49. case "description":
  50. switch (action.ToLower())
  51. {
  52. case "edit":
  53. ConfigLock.EnterWriteLock();
  54. cmd.Description = command.Arguments["Value"];
  55. mod.SaveConfig();
  56. string editMessage = string.Format("\u0002{0}\u0002 Description is now: \u0002{1}\u0002", cmd.Name, cmd.Description);
  57. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  58. ConfigLock.ExitWriteLock();
  59. break;
  60. case "view":
  61. string viewMessage = string.Format("{0} Description: \u0002{1}\u0002", cmd.Name, cmd.Description);
  62. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  63. break;
  64. }
  65. break;
  66. case "enabled":
  67. switch (action.ToLower())
  68. {
  69. case "edit":
  70. ConfigLock.EnterWriteLock();
  71. cmd.Enabled = (bool) command.Arguments["Value"];
  72. mod.SaveConfig();
  73. string editMessage = string.Format("\u0002{0}\u0002 Enabled is now: \u0002{1}\u0002", cmd.Name, cmd.Enabled);
  74. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  75. ConfigLock.ExitWriteLock();
  76. break;
  77. case "view":
  78. string viewMessage = string.Format("{0} Enabled: \u0002{1}\u0002", cmd.Name, cmd.Enabled);
  79. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  80. break;
  81. }
  82. break;
  83. case "channelblacklist":
  84. switch (action.ToLower())
  85. {
  86. case "add":
  87. ConfigLock.EnterWriteLock();
  88. if (!cmd.ChannelBlacklist.Contains(command.Arguments["Value"]))
  89. {
  90. cmd.ChannelBlacklist.Add(command.Arguments["Value"]);
  91. mod.SaveConfig();
  92. }
  93. string addMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
  94. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  95. ConfigLock.ExitWriteLock();
  96. break;
  97. case "del":
  98. ConfigLock.EnterWriteLock();
  99. if (cmd.ChannelBlacklist.Contains(command.Arguments["Value"]))
  100. {
  101. cmd.ChannelBlacklist.Remove(command.Arguments["Value"]);
  102. mod.SaveConfig();
  103. }
  104. string delMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
  105. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  106. ConfigLock.ExitWriteLock();
  107. break;
  108. case "view":
  109. string viewMessage = string.Format("{0} Channel Blacklist: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
  110. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  111. break;
  112. }
  113. break;
  114. case "nickblacklist":
  115. switch (action.ToLower())
  116. {
  117. case "add":
  118. ConfigLock.EnterWriteLock();
  119. if (!cmd.NickBlacklist.Contains(command.Arguments["Value"]))
  120. {
  121. cmd.NickBlacklist.Add(command.Arguments["Value"]);
  122. mod.SaveConfig();
  123. }
  124. string addMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
  125. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  126. ConfigLock.ExitWriteLock();
  127. break;
  128. case "del":
  129. ConfigLock.EnterWriteLock();
  130. if (cmd.NickBlacklist.Contains(command.Arguments["Value"]))
  131. {
  132. cmd.NickBlacklist.Remove(command.Arguments["Value"]);
  133. mod.SaveConfig();
  134. }
  135. string delMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
  136. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  137. ConfigLock.ExitWriteLock();
  138. break;
  139. case "view":
  140. string viewMessage = string.Format("{0} Nickname Blacklist: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
  141. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  142. break;
  143. }
  144. break;
  145. case "triggers":
  146. switch (action.ToLower())
  147. {
  148. case "add":
  149. ConfigLock.EnterWriteLock();
  150. if (!cmd.Triggers.Contains(command.Arguments["Value"]))
  151. {
  152. cmd.Triggers.Add(command.Arguments["Value"]);
  153. mod.SaveConfig();
  154. }
  155. string addMessage = string.Format("\u0002{0}\u0002 Triggers are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
  156. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  157. ConfigLock.ExitWriteLock();
  158. break;
  159. case "del":
  160. ConfigLock.EnterWriteLock();
  161. if (cmd.Triggers.Contains(command.Arguments["Value"]))
  162. {
  163. cmd.Triggers.Remove(command.Arguments["Value"]);
  164. mod.SaveConfig();
  165. }
  166. string delMessage = string.Format("\u0002{0}\u0002 Triggers are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
  167. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  168. ConfigLock.ExitWriteLock();
  169. break;
  170. case "view":
  171. string viewMessage = string.Format("{0} Triggers: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
  172. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  173. break;
  174. }
  175. break;
  176. case "arguments":
  177. switch (action.ToLower())
  178. {
  179. case "add":
  180. CommandArgument addArg = JsonConvert.DeserializeObject<CommandArgument>(command.Arguments["Value"]);
  181. if (addArg != null)
  182. {
  183. ConfigLock.EnterWriteLock();
  184. if (!cmd.Arguments.Contains(addArg))
  185. {
  186. cmd.Arguments.Add(addArg);
  187. mod.SaveConfig();
  188. }
  189. string addMessage = string.Format("\u0002{0}\u0002 Arguments are now:", cmd.Name);
  190. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  191. foreach (CommandArgument argument in cmd.Arguments)
  192. {
  193. addMessage = string.Format("Argument: \u0002{0}\u0002", JsonConvert.SerializeObject(argument));
  194. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  195. }
  196. ConfigLock.ExitWriteLock();
  197. }
  198. else
  199. {
  200. string notValid = string.Format("\u0002{0}\u000F is not a valid argument.", command.Arguments["Value"]);
  201. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  202. }
  203. break;
  204. case "del":
  205. CommandArgument delArg = JsonConvert.DeserializeObject<CommandArgument>(command.Arguments["Value"]);
  206. if (delArg != null)
  207. {
  208. ConfigLock.EnterWriteLock();
  209. if (cmd.Arguments.Contains(delArg))
  210. {
  211. cmd.Arguments.Remove(delArg);
  212. mod.SaveConfig();
  213. }
  214. string delMessage = string.Format("\u0002{0}\u0002 Arguments are now:", cmd.Name);
  215. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  216. foreach (CommandArgument argument in cmd.Arguments)
  217. {
  218. delMessage = string.Format("Argument: \u0002{0}\u0002", JsonConvert.SerializeObject(argument));
  219. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  220. }
  221. ConfigLock.ExitWriteLock();
  222. }
  223. else
  224. {
  225. string notValid = string.Format("\u0002{0}\u000F is not a valid argument.", command.Arguments["Value"]);
  226. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  227. }
  228. break;
  229. case "view":
  230. foreach (CommandArgument argument in cmd.Arguments)
  231. {
  232. string viewMessage = string.Format("{0} Argument: \u0002{1}\u0002", cmd.Name, JsonConvert.SerializeObject(argument));
  233. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  234. }
  235. break;
  236. }
  237. break;
  238. case "allowedmessagetypes":
  239. switch (action.ToLower())
  240. {
  241. case "add":
  242. MessageType addType;
  243. bool addValid = Enum.TryParse(command.Arguments["Value"], out addType);
  244. if (addValid)
  245. {
  246. ConfigLock.EnterWriteLock();
  247. if (!cmd.AllowedMessageTypes.Contains(addType))
  248. {
  249. cmd.AllowedMessageTypes.Add(addType);
  250. mod.SaveConfig();
  251. }
  252. mod.SaveConfig();
  253. List<string> addAllowedTypes = new List<string>();
  254. cmd.AllowedMessageTypes.ForEach(type => addAllowedTypes.Add(type.ToString()));
  255. string addMessage = string.Format("\u0002{0}\u0002 Allowed Message Types are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", addAllowedTypes));
  256. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  257. ConfigLock.ExitWriteLock();
  258. }
  259. else
  260. {
  261. string notValid = string.Format("\u0002{0}\u000F is not a valid message type.", command.Arguments["Value"]);
  262. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  263. }
  264. break;
  265. case "del":
  266. MessageType delType;
  267. bool delValid = Enum.TryParse(command.Arguments["Value"], out delType);
  268. if (delValid)
  269. {
  270. ConfigLock.EnterWriteLock();
  271. if (cmd.AllowedMessageTypes.Contains(delType))
  272. {
  273. cmd.AllowedMessageTypes.Remove(delType);
  274. mod.SaveConfig();
  275. }
  276. List<string> delAllowedTypes = new List<string>();
  277. cmd.AllowedMessageTypes.ForEach(type => delAllowedTypes.Add(type.ToString()));
  278. string delMessage = string.Format("\u0002{0}\u0002 Allowed Message Types are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", delAllowedTypes));
  279. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  280. ConfigLock.ExitWriteLock();
  281. }
  282. else
  283. {
  284. string notValid = string.Format("\u0002{0}\u000F is not a valid message type.", command.Arguments["Value"]);
  285. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  286. }
  287. break;
  288. case "view":
  289. List<string> allowedTypes = new List<string>();
  290. cmd.AllowedMessageTypes.ForEach(type => allowedTypes.Add(type.ToString()));
  291. string viewMessage = string.Format("{0} Allowed Message Types: \u0002{1}\u0002", cmd.Name, string.Join(", ", allowedTypes));
  292. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  293. break;
  294. }
  295. break;
  296. case "allowedaccess":
  297. switch (action.ToLower())
  298. {
  299. case "add":
  300. AccessType addType;
  301. bool addValid = Enum.TryParse(command.Arguments["Value"], out addType);
  302. if (addValid)
  303. {
  304. ConfigLock.EnterWriteLock();
  305. if (!cmd.AllowedAccess.Contains(addType))
  306. {
  307. cmd.AllowedAccess.Add(addType);
  308. mod.SaveConfig();
  309. }
  310. List<string> addAllowedAccess = new List<string>();
  311. cmd.AllowedAccess.ForEach(access => addAllowedAccess.Add(access.ToString()));
  312. string addMessage = string.Format("\u0002{0}\u0002 Allowed Accesses are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", addAllowedAccess));
  313. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  314. ConfigLock.ExitWriteLock();
  315. }
  316. else
  317. {
  318. string notValid = string.Format("\u0002{0}\u000F is not a valid access level.", command.Arguments["Value"]);
  319. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  320. }
  321. break;
  322. case "del":
  323. AccessType delType;
  324. bool delValid = Enum.TryParse(command.Arguments["Value"], out delType);
  325. if (delValid)
  326. {
  327. ConfigLock.EnterWriteLock();
  328. if (cmd.AllowedAccess.Contains(delType))
  329. {
  330. cmd.AllowedAccess.Remove(delType);
  331. mod.SaveConfig();
  332. }
  333. List<string> delAllowedAccess = new List<string>();
  334. cmd.AllowedAccess.ForEach(access => delAllowedAccess.Add(access.ToString()));
  335. string delMessage = string.Format("\u0002{0}\u0002 Allowed Accesses are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", delAllowedAccess));
  336. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  337. ConfigLock.ExitWriteLock();
  338. }
  339. else
  340. {
  341. string notValid = string.Format("\u0002{0}\u000F is not a valid access level.", command.Arguments["Value"]);
  342. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  343. }
  344. break;
  345. case "view":
  346. List<string> allowedAccess = new List<string>();
  347. cmd.AllowedAccess.ForEach(type => allowedAccess.Add(type.ToString()));
  348. string viewMessage = string.Format("{0} Allowed Accesses: \u0002{1}\u0002", cmd.Name, string.Join(", ", allowedAccess));
  349. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  350. break;
  351. }
  352. break;
  353. case "showhelp":
  354. switch (action.ToLower())
  355. {
  356. case "edit":
  357. ConfigLock.EnterWriteLock();
  358. cmd.ShowHelp = (bool)command.Arguments["Value"];
  359. mod.SaveConfig();
  360. string editMessage = string.Format("\u0002{0}\u0002 Show Help is now: \u0002{1}\u0002", cmd.Name, cmd.ShowHelp);
  361. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  362. ConfigLock.ExitWriteLock();
  363. break;
  364. case "view":
  365. string viewMessage = string.Format("{0} Show Help: \u0002{1}\u0002", cmd.Name, cmd.ShowHelp);
  366. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  367. break;
  368. }
  369. break;
  370. case "spamcheck":
  371. switch (action.ToLower())
  372. {
  373. case "edit":
  374. ConfigLock.EnterWriteLock();
  375. cmd.SpamCheck = (bool)command.Arguments["Value"];
  376. mod.SaveConfig();
  377. string editMessage = string.Format("\u0002{0}\u0002 Spam Check is now: \u0002{1}\u0002", cmd.Name, cmd.SpamCheck);
  378. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  379. ConfigLock.ExitWriteLock();
  380. break;
  381. case "view":
  382. string viewMessage = string.Format("{0} Spam Check: \u0002{1}\u0002", cmd.Name, cmd.SpamCheck);
  383. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  384. break;
  385. }
  386. break;
  387. }
  388. }
  389. else
  390. {
  391. string notFound = string.Format("\u0002{0}\u000F is not a valid command.", command.Arguments["Command"]);
  392. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notFound);
  393. }
  394. break;
  395. case "Module Configuration":
  396. string moduleParameter = command.Arguments["Parameter"];
  397. Module foundModule = Bot.Modules.Find(module => module.Name == command.Arguments["Module"] || module.ClassName == command.Arguments["Module"]);
  398. if (foundModule != null)
  399. {
  400. string action = command.Arguments["Action"];
  401. switch (moduleParameter)
  402. {
  403. case "name":
  404. switch (action.ToLower())
  405. {
  406. case "edit":
  407. ConfigLock.EnterWriteLock();
  408. foundModule.Name = command.Arguments["Value"];
  409. foundModule.SaveConfig();
  410. string editMessage = string.Format("Module Name is now: \u0002{0}\u0002", foundModule.Name);
  411. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  412. ConfigLock.ExitWriteLock();
  413. break;
  414. case "view":
  415. string viewMessage = string.Format("Module Name: \u0002{0}\u0002", foundModule.Name);
  416. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  417. break;
  418. }
  419. break;
  420. case "classname":
  421. switch (action.ToLower())
  422. {
  423. case "edit":
  424. ConfigLock.EnterWriteLock();
  425. foundModule.ClassName = command.Arguments["Value"];
  426. foundModule.SaveConfig();
  427. string editMessage = string.Format("\u0002{0}\u0002 Class Name is now: \u0002{1}\u0002", foundModule.Name, foundModule.ClassName);
  428. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  429. ConfigLock.ExitWriteLock();
  430. break;
  431. case "view":
  432. string viewMessage = string.Format("{0} Description: \u0002{1}\u0002", foundModule.Name, foundModule.ClassName);
  433. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  434. break;
  435. }
  436. break;
  437. case "enabled":
  438. switch (action.ToLower())
  439. {
  440. case "edit":
  441. ConfigLock.EnterWriteLock();
  442. foundModule.Enabled = (bool)command.Arguments["Value"];
  443. foundModule.SaveConfig();
  444. string editMessage = string.Format("\u0002{0}\u0002 Enabled is now: \u0002{1}\u0002", foundModule.Name, foundModule.Enabled);
  445. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
  446. ConfigLock.ExitWriteLock();
  447. break;
  448. case "view":
  449. string viewMessage = string.Format("{0} Enabled: \u0002{1}\u0002", foundModule.Name, foundModule.Enabled);
  450. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  451. break;
  452. }
  453. break;
  454. case "channelblacklist":
  455. switch (action.ToLower())
  456. {
  457. case "add":
  458. ConfigLock.EnterWriteLock();
  459. if (!foundModule.ChannelBlacklist.Contains(command.Arguments["Value"]))
  460. {
  461. foundModule.ChannelBlacklist.Add(command.Arguments["Value"]);
  462. foundModule.SaveConfig();
  463. }
  464. string addMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.ChannelBlacklist));
  465. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  466. ConfigLock.ExitWriteLock();
  467. break;
  468. case "del":
  469. ConfigLock.EnterWriteLock();
  470. if (foundModule.ChannelBlacklist.Contains(command.Arguments["Value"]))
  471. {
  472. foundModule.ChannelBlacklist.Remove(command.Arguments["Value"]);
  473. foundModule.SaveConfig();
  474. }
  475. string delMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.ChannelBlacklist));
  476. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  477. ConfigLock.ExitWriteLock();
  478. break;
  479. case "view":
  480. string viewMessage = string.Format("{0} Channel Blacklist: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.ChannelBlacklist));
  481. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  482. break;
  483. }
  484. break;
  485. case "nickblacklist":
  486. switch (action.ToLower())
  487. {
  488. case "add":
  489. ConfigLock.EnterWriteLock();
  490. if (!foundModule.NickBlacklist.Contains(command.Arguments["Value"]))
  491. {
  492. foundModule.NickBlacklist.Add(command.Arguments["Value"]);
  493. foundModule.SaveConfig();
  494. }
  495. string addMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.NickBlacklist));
  496. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  497. ConfigLock.ExitWriteLock();
  498. break;
  499. case "del":
  500. ConfigLock.EnterWriteLock();
  501. if (foundModule.NickBlacklist.Contains(command.Arguments["Value"]))
  502. {
  503. foundModule.NickBlacklist.Remove(command.Arguments["Value"]);
  504. foundModule.SaveConfig();
  505. }
  506. string delMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.NickBlacklist));
  507. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  508. ConfigLock.ExitWriteLock();
  509. break;
  510. case "view":
  511. string viewMessage = string.Format("{0} Nickname Blacklist: \u0002{1}\u0002", foundModule.Name, string.Join(", ", foundModule.NickBlacklist));
  512. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  513. break;
  514. }
  515. break;
  516. case "commands":
  517. switch (action.ToLower())
  518. {
  519. case "add":
  520. Command addCommand = JsonConvert.DeserializeObject<Command>(command.Arguments["Value"]);
  521. if (addCommand != null)
  522. {
  523. ConfigLock.EnterWriteLock();
  524. if (!foundModule.Commands.Contains(addCommand))
  525. {
  526. foundModule.Commands.Add(addCommand);
  527. foundModule.SaveConfig();
  528. }
  529. string addMessage = string.Format("\u0002{0}\u0002 Commands are now:", foundModule.Name);
  530. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  531. foreach (Command cmd in foundModule.Commands)
  532. {
  533. addMessage = string.Format("Command: \u0002{0}\u0002", JsonConvert.SerializeObject(cmd));
  534. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  535. }
  536. ConfigLock.ExitWriteLock();
  537. }
  538. else
  539. {
  540. string notValid = string.Format("\u0002{0}\u000F is not a valid command.", command.Arguments["Value"]);
  541. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  542. }
  543. break;
  544. case "del":
  545. Command delCommand = JsonConvert.DeserializeObject<Command>(command.Arguments["Value"]);
  546. if (delCommand != null)
  547. {
  548. ConfigLock.EnterWriteLock();
  549. if (foundModule.Commands.Contains(delCommand))
  550. {
  551. foundModule.Commands.Remove(delCommand);
  552. foundModule.SaveConfig();
  553. }
  554. string delMessage = string.Format("\u0002{0}\u0002 Commands are now:", foundModule.Name);
  555. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  556. foreach (Command cmd in foundModule.Commands)
  557. {
  558. delMessage = string.Format("Command: \u0002{0}\u0002", JsonConvert.SerializeObject(cmd));
  559. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  560. }
  561. ConfigLock.ExitWriteLock();
  562. }
  563. else
  564. {
  565. string notValid = string.Format("\u0002{0}\u000F is not a valid command.", command.Arguments["Value"]);
  566. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  567. }
  568. break;
  569. case "view":
  570. foreach (Command cmd in foundModule.Commands)
  571. {
  572. string viewMessage = string.Format("{0} Command: \u0002{1}\u0002", foundModule.Name, JsonConvert.SerializeObject(cmd));
  573. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  574. }
  575. break;
  576. }
  577. break;
  578. case "options":
  579. switch (action.ToLower())
  580. {
  581. case "add":
  582. Option addOption = JsonConvert.DeserializeObject<Option>(command.Arguments["Value"]);
  583. if (addOption != null)
  584. {
  585. ConfigLock.EnterWriteLock();
  586. if (!foundModule.Options.Contains(addOption))
  587. {
  588. foundModule.Options.Add(addOption);
  589. foundModule.SaveConfig();
  590. }
  591. string addMessage = string.Format("\u0002{0}\u0002 Options are now:", foundModule.Name);
  592. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  593. foreach (Option opt in foundModule.Options)
  594. {
  595. addMessage = string.Format("Option: \u0002{0}\u0002", JsonConvert.SerializeObject(opt));
  596. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
  597. }
  598. ConfigLock.ExitWriteLock();
  599. }
  600. else
  601. {
  602. string notValid = string.Format("\u0002{0}\u000F is not a valid option.", command.Arguments["Value"]);
  603. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  604. }
  605. break;
  606. case "del":
  607. Option delOption = JsonConvert.DeserializeObject<Option>(command.Arguments["Value"]);
  608. if (delOption != null)
  609. {
  610. ConfigLock.EnterWriteLock();
  611. if (foundModule.Options.Contains(delOption))
  612. {
  613. foundModule.Options.Remove(delOption);
  614. foundModule.SaveConfig();
  615. }
  616. string delMessage = string.Format("\u0002{0}\u0002 Options are now:", foundModule.Name);
  617. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  618. foreach (Option opt in foundModule.Options)
  619. {
  620. delMessage = string.Format("Option: \u0002{0}\u0002", JsonConvert.SerializeObject(opt));
  621. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
  622. }
  623. ConfigLock.ExitWriteLock();
  624. }
  625. else
  626. {
  627. string notValid = string.Format("\u0002{0}\u000F is not a valid option.", command.Arguments["Value"]);
  628. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
  629. }
  630. break;
  631. case "view":
  632. foreach (Option opt in foundModule.Options)
  633. {
  634. string viewMessage = string.Format("{0} Command: \u0002{1}\u0002", foundModule.Name, JsonConvert.SerializeObject(opt));
  635. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
  636. }
  637. break;
  638. }
  639. break;
  640. }
  641. }
  642. else
  643. {
  644. string notFound = string.Format("\u0002{0}\u000F is not a valid module.", command.Arguments["Module"]);
  645. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notFound);
  646. }
  647. break;
  648. }
  649. }
  650. }
  651. }