The easy to use and full featured Irc Bot everyone is talking about!
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. namespace Combot.Modules.Plugins
  7. {
  8. public class Owner_Control : Module
  9. {
  10. public override void Initialize()
  11. {
  12. Bot.CommandReceivedEvent += HandleCommandEvent;
  13. }
  14. public override void ParseCommand(CommandMessage command)
  15. {
  16. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  17. switch (foundCommand.Name)
  18. {
  19. case "Change Nick":
  20. Bot.IRC.SendNick(command.Arguments["Nickname"]);
  21. break;
  22. case "Identify":
  23. Bot.IRC.SendPrivateMessage("NickServ", string.Format("Identify {0}", Bot.ServerConfig.Password));
  24. break;
  25. case "Join Channel":
  26. if (!Bot.IRC.Channels.Exists(chan => chan.Name == command.Arguments["Channel"]))
  27. {
  28. Bot.IRC.SendJoin(command.Arguments["Channel"]);
  29. }
  30. else
  31. {
  32. string message = string.Format("I am already in \u0002{0}\u000F.", command.Arguments["Channel"]);
  33. switch (command.MessageType)
  34. {
  35. case MessageType.Channel:
  36. Bot.IRC.SendPrivateMessage(command.Location, message);
  37. break;
  38. case MessageType.Query:
  39. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, message);
  40. break;
  41. case MessageType.Notice:
  42. Bot.IRC.SendNotice(command.Nick.Nickname, message);
  43. break;
  44. }
  45. }
  46. break;
  47. case "Part Channel":
  48. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  49. if (Bot.IRC.Channels.Exists(chan => chan.Name == channel))
  50. {
  51. Bot.IRC.SendPart(channel);
  52. }
  53. else
  54. {
  55. string message = string.Format("I am not in \u0002{0}\u000F.", channel);
  56. switch (command.MessageType)
  57. {
  58. case MessageType.Channel:
  59. Bot.IRC.SendPrivateMessage(command.Location, message);
  60. break;
  61. case MessageType.Query:
  62. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, message);
  63. break;
  64. case MessageType.Notice:
  65. Bot.IRC.SendNotice(command.Nick.Nickname, message);
  66. break;
  67. }
  68. }
  69. break;
  70. case "Speak":
  71. string location = command.Arguments.ContainsKey("Target") ? command.Arguments["Target"] : command.Location;
  72. Bot.IRC.SendPrivateMessage(location, command.Arguments["Message"]);
  73. break;
  74. case "Action":
  75. string actionLocation = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  76. Bot.IRC.SendCTCPMessage(actionLocation, "ACTION", command.Arguments["Message"]);
  77. break;
  78. case "Quit":
  79. string quitType = command.Arguments["Type"].ToString();
  80. switch (quitType.ToLower())
  81. {
  82. case "server":
  83. Bot.Disconnect();
  84. break;
  85. case "client":
  86. Environment.Exit(0);
  87. break;
  88. }
  89. break;
  90. case "Cycle":
  91. string cycleType = command.Arguments["Type"].ToString();
  92. switch (cycleType.ToLower())
  93. {
  94. case "channel":
  95. string cycleChannel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  96. if (Bot.IRC.Channels.Exists(chan => chan.Name == cycleChannel))
  97. {
  98. Bot.IRC.SendPart(cycleChannel);
  99. Bot.IRC.SendJoin(cycleChannel);
  100. }
  101. else
  102. {
  103. string message = string.Format("I am not in \u0002{0}\u000F.", cycleChannel);
  104. switch (command.MessageType)
  105. {
  106. case MessageType.Channel:
  107. Bot.IRC.SendPrivateMessage(command.Location, message);
  108. break;
  109. case MessageType.Query:
  110. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, message);
  111. break;
  112. case MessageType.Notice:
  113. Bot.IRC.SendNotice(command.Nick.Nickname, message);
  114. break;
  115. }
  116. }
  117. break;
  118. case "server":
  119. Bot.Disconnect();
  120. Bot.Connect();
  121. break;
  122. case "client":
  123. Process.Start(Assembly.GetEntryAssembly().Location); // to start new instance of application
  124. Environment.Exit(0);
  125. break;
  126. }
  127. break;
  128. case "List":
  129. string listType = command.Arguments["Type"].ToString();
  130. string listLocation = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  131. switch (listType.ToLower())
  132. {
  133. case "nicks":
  134. if (Bot.IRC.Channels.Exists(chan => chan.Name == listLocation))
  135. {
  136. string nickList = string.Join(", ", Bot.IRC.Channels.Find(chan => chan.Name == listLocation).Nicks.Select(nick => nick.Nickname));
  137. string nickMessage = string.Format("Nicknames in \u0002{0}\u000F: {1}", listLocation, nickList);
  138. switch (command.MessageType)
  139. {
  140. case MessageType.Channel:
  141. Bot.IRC.SendPrivateMessage(command.Location, nickMessage);
  142. break;
  143. case MessageType.Query:
  144. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, nickMessage);
  145. break;
  146. case MessageType.Notice:
  147. Bot.IRC.SendNotice(command.Nick.Nickname, nickMessage);
  148. break;
  149. }
  150. }
  151. else
  152. {
  153. string message = string.Format("I do not have nickname information for \u0002{0}\u000F.", listLocation);
  154. switch (command.MessageType)
  155. {
  156. case MessageType.Channel:
  157. Bot.IRC.SendPrivateMessage(command.Location, message);
  158. break;
  159. case MessageType.Query:
  160. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, message);
  161. break;
  162. case MessageType.Notice:
  163. Bot.IRC.SendNotice(command.Nick.Nickname, message);
  164. break;
  165. }
  166. }
  167. break;
  168. case "channels":
  169. string channelList = string.Join(", ", Bot.IRC.Channels.Select(chan => chan.Name));
  170. string channelMessage = string.Format("I am in the following channels: \u0002{0}\u000F", channelList);
  171. switch (command.MessageType)
  172. {
  173. case MessageType.Channel:
  174. Bot.IRC.SendPrivateMessage(command.Location, channelMessage);
  175. break;
  176. case MessageType.Query:
  177. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, channelMessage);
  178. break;
  179. case MessageType.Notice:
  180. Bot.IRC.SendNotice(command.Nick.Nickname, channelMessage);
  181. break;
  182. }
  183. break;
  184. case "servers":
  185. // TODO Add server list
  186. break;
  187. case "modules":
  188. string moduleList = string.Join(", ", Bot.Modules.Select(module => module.Name));
  189. string moduleMessage = string.Format("I have the following modules loaded: \u0002{0}\u000F", moduleList);
  190. switch (command.MessageType)
  191. {
  192. case MessageType.Channel:
  193. Bot.IRC.SendPrivateMessage(command.Location, moduleMessage);
  194. break;
  195. case MessageType.Query:
  196. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleMessage);
  197. break;
  198. case MessageType.Notice:
  199. Bot.IRC.SendNotice(command.Nick.Nickname, moduleMessage);
  200. break;
  201. }
  202. break;
  203. }
  204. break;
  205. case "Modules":
  206. string moduleType = command.Arguments["Action"].ToString();
  207. string moduleName = command.Arguments["Module"].ToString();
  208. switch (moduleType.ToLower())
  209. {
  210. case "load":
  211. if (!Bot.Modules.Exists(mod => mod.Name.ToLower() == moduleName.ToLower()))
  212. {
  213. string modulePath = Path.Combine(Bot.ServerConfig.ModuleLocation, moduleName);
  214. bool loaded = Bot.LoadModule(modulePath);
  215. if (loaded)
  216. {
  217. string moduleMessage = string.Format("\u0002{0}\u000F has been loaded.", moduleName);
  218. switch (command.MessageType)
  219. {
  220. case MessageType.Channel:
  221. Bot.IRC.SendPrivateMessage(command.Location, moduleMessage);
  222. break;
  223. case MessageType.Query:
  224. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleMessage);
  225. break;
  226. case MessageType.Notice:
  227. Bot.IRC.SendNotice(command.Nick.Nickname, moduleMessage);
  228. break;
  229. }
  230. }
  231. else
  232. {
  233. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be loaded.", moduleName);
  234. switch (command.MessageType)
  235. {
  236. case MessageType.Channel:
  237. Bot.IRC.SendPrivateMessage(command.Location, moduleMessage);
  238. break;
  239. case MessageType.Query:
  240. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleMessage);
  241. break;
  242. case MessageType.Notice:
  243. Bot.IRC.SendNotice(command.Nick.Nickname, moduleMessage);
  244. break;
  245. }
  246. }
  247. }
  248. else
  249. {
  250. string moduleInvalid = string.Format("\u0002{0}\u000F is already loaded.", moduleName);
  251. switch (command.MessageType)
  252. {
  253. case MessageType.Channel:
  254. Bot.IRC.SendPrivateMessage(command.Location, moduleInvalid);
  255. break;
  256. case MessageType.Query:
  257. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleInvalid);
  258. break;
  259. case MessageType.Notice:
  260. Bot.IRC.SendNotice(command.Nick.Nickname, moduleInvalid);
  261. break;
  262. }
  263. }
  264. break;
  265. case "unload":
  266. if (Bot.Modules.Exists(mod => mod.Name.ToLower() == moduleName.ToLower()))
  267. {
  268. bool unloaded = Bot.UnloadModule(moduleName);
  269. if (unloaded)
  270. {
  271. string moduleMessage = string.Format("\u0002{0}\u000F has been unloaded.", moduleName);
  272. switch (command.MessageType)
  273. {
  274. case MessageType.Channel:
  275. Bot.IRC.SendPrivateMessage(command.Location, moduleMessage);
  276. break;
  277. case MessageType.Query:
  278. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleMessage);
  279. break;
  280. case MessageType.Notice:
  281. Bot.IRC.SendNotice(command.Nick.Nickname, moduleMessage);
  282. break;
  283. }
  284. }
  285. else
  286. {
  287. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be unloaded.", moduleName);
  288. switch (command.MessageType)
  289. {
  290. case MessageType.Channel:
  291. Bot.IRC.SendPrivateMessage(command.Location, moduleMessage);
  292. break;
  293. case MessageType.Query:
  294. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleMessage);
  295. break;
  296. case MessageType.Notice:
  297. Bot.IRC.SendNotice(command.Nick.Nickname, moduleMessage);
  298. break;
  299. }
  300. }
  301. }
  302. else
  303. {
  304. string moduleInvalid = string.Format("\u0002{0}\u000F is not loaded.", moduleName);
  305. switch (command.MessageType)
  306. {
  307. case MessageType.Channel:
  308. Bot.IRC.SendPrivateMessage(command.Location, moduleInvalid);
  309. break;
  310. case MessageType.Query:
  311. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, moduleInvalid);
  312. break;
  313. case MessageType.Notice:
  314. Bot.IRC.SendNotice(command.Nick.Nickname, moduleInvalid);
  315. break;
  316. }
  317. }
  318. break;
  319. }
  320. break;
  321. }
  322. }
  323. }
  324. }