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

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