The easy to use and full featured Irc Bot everyone is talking about!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Owner_Control.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. for (int i = 0; i < Bot.IRC.Channels.Count; i++)
  34. {
  35. Nick foundNick = Bot.IRC.Channels[i].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. // TODO Add server list
  145. break;
  146. case "modules":
  147. string moduleList = string.Join(", ", Bot.Modules.Select(module => module.Name));
  148. string moduleMessage = string.Format("I have the following modules loaded: \u0002{0}\u000F", moduleList);
  149. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  150. break;
  151. }
  152. break;
  153. case "Load Module":
  154. string loadModuleName = command.Arguments["Module"].ToString();
  155. if (!Bot.Modules.Exists(mod => mod.Name.ToLower() == loadModuleName.ToLower()))
  156. {
  157. string modulePath = Path.Combine(Bot.ServerConfig.ModuleLocation, loadModuleName);
  158. bool loaded = Bot.LoadModule(modulePath);
  159. if (loaded)
  160. {
  161. string moduleMessage = string.Format("\u0002{0}\u000F has been loaded.", loadModuleName);
  162. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  163. }
  164. else
  165. {
  166. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be loaded.", loadModuleName);
  167. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  168. }
  169. }
  170. else
  171. {
  172. string moduleInvalid = string.Format("\u0002{0}\u000F is already loaded.", loadModuleName);
  173. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleInvalid);
  174. }
  175. break;
  176. case "Unload Module":
  177. string unloadModuleName = command.Arguments["Module"].ToString();
  178. if (Bot.Modules.Exists(mod => mod.Name.ToLower() == unloadModuleName.ToLower()))
  179. {
  180. bool unloaded = Bot.UnloadModule(unloadModuleName);
  181. if (unloaded)
  182. {
  183. string moduleMessage = string.Format("\u0002{0}\u000F has been unloaded.", unloadModuleName);
  184. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  185. }
  186. else
  187. {
  188. string moduleMessage = string.Format("\u0002{0}\u000F was unable to be unloaded.", unloadModuleName);
  189. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleMessage);
  190. }
  191. }
  192. else
  193. {
  194. string moduleInvalid = string.Format("\u0002{0}\u000F is not loaded.", unloadModuleName);
  195. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, moduleInvalid);
  196. }
  197. break;
  198. case "Update":
  199. Bot.ServerConfig.Load();
  200. Bot.Modules.ForEach(module => module.LoadConfig());
  201. break;
  202. }
  203. }
  204. }
  205. }