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.

Owner_Control.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading;
  7. using Combot.IRCServices;
  8. namespace Combot.Modules.Plugins
  9. {
  10. public class Owner_Control : Module
  11. {
  12. public override void Initialize()
  13. {
  14. Bot.CommandReceivedEvent += HandleCommandEvent;
  15. }
  16. public override void ParseCommand(CommandMessage command)
  17. {
  18. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  19. switch (foundCommand.Name)
  20. {
  21. case "Owner Identify":
  22. if (command.Arguments["Password"] == Bot.ServerConfig.Password)
  23. {
  24. if (!Bot.ServerConfig.Owners.Contains(command.Nick.Nickname))
  25. {
  26. Bot.ServerConfig.Owners.Add(command.Nick.Nickname);
  27. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "You are now identified as an owner.");
  28. }
  29. else
  30. {
  31. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "You are already identified as an owner.");
  32. }
  33. foreach (Channel chan in Bot.IRC.Channels)
  34. {
  35. Nick foundNick = chan.Nicks.Find(nick => nick.Nickname == command.Nick.Nickname);
  36. if (foundNick != null)
  37. {
  38. foundNick.AddMode(UserMode.r);
  39. }
  40. }
  41. }
  42. break;
  43. case "Change Nick":
  44. Bot.IRC.Command.SendNick(command.Arguments["Nickname"]);
  45. break;
  46. case "Identify":
  47. Bot.IRC.Command.SendPrivateMessage("NickServ", string.Format("Identify {0}", Bot.ServerConfig.Password));
  48. break;
  49. case "Join Channel":
  50. if (!Bot.IRC.Channels.Exists(chan => chan.Name == command.Arguments["Channel"]))
  51. {
  52. Bot.IRC.Command.SendJoin(command.Arguments["Channel"]);
  53. }
  54. else
  55. {
  56. string message = string.Format("I am already in \u0002{0}\u000F.", command.Arguments["Channel"]);
  57. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
  58. }
  59. break;
  60. case "Part Channel":
  61. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  62. if (Bot.IRC.Channels.Exists(chan => chan.Name == channel))
  63. {
  64. Bot.IRC.Command.SendPart(channel);
  65. }
  66. else
  67. {
  68. string message = string.Format("I am not in \u0002{0}\u000F.", channel);
  69. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
  70. }
  71. break;
  72. case "Speak":
  73. string location = command.Arguments.ContainsKey("Target") ? command.Arguments["Target"] : command.Location;
  74. Bot.IRC.Command.SendPrivateMessage(location, command.Arguments["Message"]);
  75. break;
  76. case "Action":
  77. string actionLocation = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  78. Bot.IRC.Command.SendCTCPMessage(actionLocation, "ACTION", command.Arguments["Message"]);
  79. break;
  80. case "Quit":
  81. string quitType = command.Arguments["Type"].ToString();
  82. switch (quitType.ToLower())
  83. {
  84. case "server":
  85. Bot.Disconnect();
  86. break;
  87. case "client":
  88. Environment.Exit(0);
  89. break;
  90. }
  91. break;
  92. case "Cycle":
  93. string cycleType = command.Arguments["Type"].ToString();
  94. switch (cycleType.ToLower())
  95. {
  96. case "channel":
  97. string cycleChannel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  98. if (Bot.IRC.Channels.Exists(chan => chan.Name == cycleChannel))
  99. {
  100. Bot.IRC.Command.SendPart(cycleChannel);
  101. Bot.IRC.Command.SendJoin(cycleChannel);
  102. }
  103. else
  104. {
  105. string message = string.Format("I am not in \u0002{0}\u000F.", cycleChannel);
  106. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
  107. }
  108. break;
  109. case "server":
  110. Bot.Disconnect();
  111. Thread.Sleep(1000);
  112. Bot.Connect();
  113. break;
  114. case "client":
  115. Process.Start(Assembly.GetEntryAssembly().Location); // to start new instance of application
  116. Environment.Exit(0);
  117. break;
  118. }
  119. break;
  120. case "List":
  121. string listType = command.Arguments["Type"].ToString();
  122. string listLocation = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  123. switch (listType.ToLower())
  124. {
  125. case "nicks":
  126. if (Bot.IRC.Channels.Exists(chan => chan.Name == listLocation))
  127. {
  128. string nickList = string.Join(", ", Bot.IRC.Channels.Find(chan => chan.Name == listLocation).Nicks.Select(nick => nick.Nickname));
  129. string nickMessage = string.Format("Nicknames in \u0002{0}\u000F: {1}", listLocation, nickList);
  130. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, nickMessage);
  131. }
  132. else
  133. {
  134. string message = string.Format("I do not have nickname information for \u0002{0}\u000F.", listLocation);
  135. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
  136. }
  137. break;
  138. case "channels":
  139. string channelList = string.Join(", ", Bot.IRC.Channels.Select(chan => chan.Name));
  140. string channelMessage = string.Format("I am in the following channels: \u0002{0}\u000F", channelList);
  141. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, channelMessage);
  142. break;
  143. case "servers":
  144. string serverList = string.Empty;
  145. foreach (Bot bot in Controller.Instance.Bots)
  146. {
  147. if (bot.Connected)
  148. {
  149. serverList = string.Join(", ", serverList, bot.ServerConfig.Name);
  150. }
  151. }
  152. if (string.IsNullOrEmpty(serverList))
  153. {
  154. serverList = "None Connected";
  155. }
  156. string serverMessage = string.Format("I am connected to the following servers: \u0002{0}\u000F", serverList.TrimStart(',').Trim());
  157. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, serverMessage);
  158. break;
  159. case "modules":
  160. string moduleList = string.Join(", ", Bot.Modules.Select(module => module.Name));
  161. string moduleMessage = string.Format("I have the following modules loaded: \u0002{0}\u000F", moduleList);
  162. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  163. break;
  164. }
  165. break;
  166. case "Load Module":
  167. string loadModuleName = command.Arguments["Module"].ToString();
  168. if (!Bot.Modules.Exists(mod => mod.Name.ToLower() == loadModuleName.ToLower()))
  169. {
  170. string modulePath = Path.Combine(Bot.ServerConfig.ModuleLocation, loadModuleName);
  171. bool loaded = Bot.LoadModule(modulePath);
  172. if (loaded)
  173. {
  174. string moduleMessage = string.Format("\u0002{0}\u000F has been loaded.", loadModuleName);
  175. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  176. }
  177. else
  178. {
  179. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be loaded.", loadModuleName);
  180. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  181. }
  182. }
  183. else
  184. {
  185. string moduleInvalid = string.Format("\u0002{0}\u000F is already loaded.", loadModuleName);
  186. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleInvalid);
  187. }
  188. break;
  189. case "Unload Module":
  190. string unloadModuleName = command.Arguments["Module"].ToString();
  191. if (Bot.Modules.Exists(mod => mod.Name.ToLower() == unloadModuleName.ToLower()))
  192. {
  193. bool unloaded = Bot.UnloadModule(unloadModuleName);
  194. if (unloaded)
  195. {
  196. string moduleMessage = string.Format("\u0002{0}\u000F has been unloaded.", unloadModuleName);
  197. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  198. }
  199. else
  200. {
  201. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be unloaded.", unloadModuleName);
  202. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  203. }
  204. }
  205. else
  206. {
  207. string moduleInvalid = string.Format("\u0002{0}\u000F is not loaded.", unloadModuleName);
  208. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleInvalid);
  209. }
  210. break;
  211. case "Update":
  212. Bot.ServerConfig.Load();
  213. for (int i = 0; i < Bot.Modules.Count; i++)
  214. {
  215. Bot.Modules[i].LoadConfig();
  216. }
  217. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "Update Complete");
  218. break;
  219. }
  220. }
  221. }
  222. }