The easy to use and full featured Irc Bot everyone is talking about!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Moderation.cs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Combot.IRCServices;
  5. using Combot.IRCServices.Messaging;
  6. namespace Combot.Modules.ModuleClasses
  7. {
  8. public class Moderation : 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. // Privilege Mode Commands
  20. case "Founder":
  21. ModifyUserPrivilege(true, command, ChannelMode.q);
  22. break;
  23. case "Remove Founder":
  24. ModifyUserPrivilege(false, command, ChannelMode.q);
  25. break;
  26. case "SOP":
  27. ModifyUserPrivilege(true, command, ChannelMode.a);
  28. break;
  29. case "Remove SOP":
  30. ModifyUserPrivilege(false, command, ChannelMode.a);
  31. break;
  32. case "OP":
  33. ModifyUserPrivilege(true, command, ChannelMode.o);
  34. break;
  35. case "Remove OP":
  36. ModifyUserPrivilege(false, command, ChannelMode.o);
  37. break;
  38. case "HOP":
  39. ModifyUserPrivilege(true, command, ChannelMode.h);
  40. break;
  41. case "Remove HOP":
  42. ModifyUserPrivilege(false, command, ChannelMode.h);
  43. break;
  44. case "Voice":
  45. ModifyUserPrivilege(true, command, ChannelMode.v);
  46. break;
  47. case "Remove Voice":
  48. ModifyUserPrivilege(false, command, ChannelMode.v);
  49. break;
  50. // Auto Privilege Management
  51. case "ASOP":
  52. ModifyAutoUserPrivilege("SOP", command, ChannelMode.a);
  53. break;
  54. case "AOP":
  55. ModifyAutoUserPrivilege("AOP", command, ChannelMode.o);
  56. break;
  57. case "AHOP":
  58. ModifyAutoUserPrivilege("HOP", command, ChannelMode.h);
  59. break;
  60. case "AVoice":
  61. ModifyAutoUserPrivilege("VOP", command, ChannelMode.v);
  62. break;
  63. case "Mode":
  64. ModifyChannelModes(foundCommand, command);
  65. break;
  66. case "Topic":
  67. ModifyChannelTopic(foundCommand, command);
  68. break;
  69. case "Invite":
  70. InviteNick(foundCommand, command);
  71. break;
  72. case "Ban":
  73. BanNick(true, foundCommand, command);
  74. break;
  75. case "UnBan":
  76. BanNick(false, foundCommand, command);
  77. break;
  78. case "Kick Ban":
  79. BanNick(true, foundCommand, command);
  80. KickNick(foundCommand, command);
  81. break;
  82. case "Timed Ban":
  83. TimedBan(foundCommand, command);
  84. break;
  85. case "Timed Kick Ban":
  86. TimedBan(foundCommand, command);
  87. KickNick(foundCommand, command);
  88. break;
  89. case "Kick":
  90. KickNick(foundCommand, command);
  91. break;
  92. case "Kick Self":
  93. KickSelf(command);
  94. break;
  95. case "Clear":
  96. ClearChannel(foundCommand, command);
  97. break;
  98. }
  99. }
  100. private void ModifyUserPrivilege(bool set, CommandMessage command, ChannelMode mode)
  101. {
  102. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  103. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, Bot.ChannelModeMapping[mode]))
  104. {
  105. SetMode(set, channel, mode, command.Arguments["Nickname"]);
  106. }
  107. else
  108. {
  109. string noAccessMessage = string.Format("You do not have access to set mode \u0002+{0}\u000F for \u0002{1}\u000F on \u0002{2}\u000F.", mode, command.Arguments["Nickname"], channel);
  110. switch (command.MessageType)
  111. {
  112. case MessageType.Channel:
  113. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  114. break;
  115. case MessageType.Query:
  116. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  117. break;
  118. case MessageType.Notice:
  119. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  120. break;
  121. }
  122. }
  123. }
  124. private void ModifyAutoUserPrivilege(string optionCommand, CommandMessage command, ChannelMode mode)
  125. {
  126. bool set = true;
  127. if (command.Arguments["Option"].ToLower() == "del")
  128. {
  129. set = false;
  130. }
  131. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  132. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, Bot.ChannelModeMapping[mode]))
  133. {
  134. SetMode(set, channel, mode, command.Arguments["Nickname"]);
  135. Bot.IRC.SendPrivateMessage("ChanServ", string.Format("{0} {1} {2} {3}", optionCommand, channel, command.Arguments["Option"], command.Arguments["Nickname"]));
  136. }
  137. else
  138. {
  139. string noAccessMessage = string.Format("You do not have access to \u0002{0}\u000F \u0002{1}\u000F to the \u0002{2}\u000F list on \u0002{3}\u000F.", command.Arguments["Option"].ToLower(), command.Arguments["Nickname"], optionCommand, channel);
  140. switch (command.MessageType)
  141. {
  142. case MessageType.Channel:
  143. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  144. break;
  145. case MessageType.Query:
  146. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  147. break;
  148. case MessageType.Notice:
  149. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  150. break;
  151. }
  152. }
  153. }
  154. private void ModifyChannelModes(Command curCommand, CommandMessage command)
  155. {
  156. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  157. bool allowedMode = true;
  158. bool allowedCommand = Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess);
  159. if (allowedCommand)
  160. {
  161. List<ChannelModeInfo> modeList = new List<ChannelModeInfo>();
  162. if (command.Arguments.ContainsKey("Parameters"))
  163. {
  164. modeList = Bot.IRC.ParseChannelModeString(command.Arguments["Modes"],
  165. command.Arguments["Parameters"]);
  166. }
  167. else
  168. {
  169. modeList = Bot.IRC.ParseChannelModeString(command.Arguments["Modes"], string.Empty);
  170. }
  171. ChannelMode mode = ChannelMode.q;
  172. for (int i = 0; i < modeList.Count; i++)
  173. {
  174. switch (modeList[i].Mode)
  175. {
  176. case ChannelMode.v:
  177. case ChannelMode.h:
  178. case ChannelMode.o:
  179. case ChannelMode.a:
  180. case ChannelMode.q:
  181. allowedMode = Bot.CheckChannelAccess(channel, command.Nick.Nickname, Bot.ChannelModeMapping[modeList[i].Mode]);
  182. if (!allowedMode)
  183. {
  184. mode = modeList[i].Mode;
  185. }
  186. break;
  187. }
  188. }
  189. if (allowedMode)
  190. {
  191. Bot.IRC.SendMode(channel, modeList);
  192. }
  193. else
  194. {
  195. string noAccessMessage = string.Format("You do not have access to set mode \u0002+{0}\u000F on \u0002{1}\u000F.", mode, channel);
  196. switch (command.MessageType)
  197. {
  198. case MessageType.Channel:
  199. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  200. break;
  201. case MessageType.Query:
  202. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  203. break;
  204. case MessageType.Notice:
  205. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  206. break;
  207. }
  208. }
  209. }
  210. else
  211. {
  212. string noAccessMessage = string.Format("You do not have access to use \u0002{0}\u000F on \u0002{1}\u000F.", command.Command, channel);
  213. switch (command.MessageType)
  214. {
  215. case MessageType.Channel:
  216. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  217. break;
  218. case MessageType.Query:
  219. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  220. break;
  221. case MessageType.Notice:
  222. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  223. break;
  224. }
  225. }
  226. }
  227. private void SetMode(bool set, string channel, ChannelMode mode, string nickname)
  228. {
  229. ChannelModeInfo modeInfo = new ChannelModeInfo();
  230. modeInfo.Mode = mode;
  231. modeInfo.Parameter = nickname;
  232. modeInfo.Set = set;
  233. Bot.IRC.SendMode(channel, modeInfo);
  234. }
  235. private void ModifyChannelTopic(Command curCommand, CommandMessage command)
  236. {
  237. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  238. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
  239. {
  240. Bot.IRC.SendTopic(channel, command.Arguments["Message"]);
  241. }
  242. else
  243. {
  244. string noAccessMessage = string.Format("You do not have access to change the topic on \u0002{0}\u000F.", channel);
  245. switch (command.MessageType)
  246. {
  247. case MessageType.Channel:
  248. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  249. break;
  250. case MessageType.Query:
  251. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  252. break;
  253. case MessageType.Notice:
  254. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  255. break;
  256. }
  257. }
  258. }
  259. private void InviteNick(Command curCommand, CommandMessage command)
  260. {
  261. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  262. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
  263. {
  264. Bot.IRC.SendInvite(channel, command.Arguments["Nickname"]);
  265. }
  266. else
  267. {
  268. string noAccessMessage = string.Format("You do not have access to invite someone to \u0002{0}\u000F.", channel);
  269. switch (command.MessageType)
  270. {
  271. case MessageType.Channel:
  272. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  273. break;
  274. case MessageType.Query:
  275. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  276. break;
  277. case MessageType.Notice:
  278. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  279. break;
  280. }
  281. }
  282. }
  283. private void BanNick(bool set, Command curCommand, CommandMessage command)
  284. {
  285. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  286. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
  287. {
  288. string banMask = command.Arguments["Nickname"];
  289. Channel foundChannel = Bot.IRC.Channels.Find(chan => chan.Nicks.Exists(nick => nick.Nickname == banMask));
  290. if (foundChannel != null)
  291. {
  292. Nick foundNick = foundChannel.Nicks.Find(nick => nick.Nickname == banMask);
  293. if (foundNick.Host != string.Empty && foundNick.Username != null)
  294. {
  295. banMask = string.Format("{0}!*{1}@{2}", foundNick.Nickname, foundNick.Username, foundNick.Host);
  296. }
  297. else if (foundNick.Host != string.Empty)
  298. {
  299. banMask = string.Format("{0}!*@{1}", foundNick.Nickname, foundNick.Host);
  300. }
  301. else if (foundNick.Username != string.Empty)
  302. {
  303. banMask = string.Format("{0}!*{1}@*", foundNick.Nickname, foundNick.Username);
  304. }
  305. else
  306. {
  307. banMask = string.Format("{0}!*@*", foundNick.Nickname);
  308. }
  309. }
  310. else
  311. {
  312. if (!banMask.Contains("@") || !banMask.Contains("!"))
  313. {
  314. banMask = string.Format("{0}!*@*", banMask);
  315. }
  316. }
  317. SetMode(set, channel, ChannelMode.b, banMask);
  318. }
  319. else
  320. {
  321. string banMessage = "ban";
  322. if (!set)
  323. {
  324. banMessage = "unban";
  325. }
  326. string noAccessMessage = string.Format("You do not have access to {0} \u0002{1}\u000F on \u0002{2}\u000F.", banMessage, command.Arguments["Nickname"], channel);
  327. switch (command.MessageType)
  328. {
  329. case MessageType.Channel:
  330. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  331. break;
  332. case MessageType.Query:
  333. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  334. break;
  335. case MessageType.Notice:
  336. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  337. break;
  338. }
  339. }
  340. }
  341. private void TimedBan(Command curCommand, CommandMessage command)
  342. {
  343. }
  344. private void KickNick(Command curCommand, CommandMessage command)
  345. {
  346. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  347. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
  348. {
  349. Bot.IRC.SendKick(channel, command.Arguments["Nickname"]);
  350. }
  351. else
  352. {
  353. string noAccessMessage = string.Format("You do not have access to kick \u0002{0}\u000F from \u0002{1}\u000F.", command.Arguments["Nickname"], channel);
  354. switch (command.MessageType)
  355. {
  356. case MessageType.Channel:
  357. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  358. break;
  359. case MessageType.Query:
  360. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  361. break;
  362. case MessageType.Notice:
  363. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  364. break;
  365. }
  366. }
  367. }
  368. private void KickSelf(CommandMessage command)
  369. {
  370. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  371. Bot.IRC.SendKick(channel, command.Nick.Nickname);
  372. }
  373. private void ClearChannel(Command curCommand, CommandMessage command)
  374. {
  375. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  376. if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
  377. {
  378. Bot.IRC.SendPrivateMessage("ChanServ", string.Format("CLEAR {0} {1}", channel, command.Arguments["Target"]));
  379. }
  380. else
  381. {
  382. string noAccessMessage = string.Format("You do not have access to clear \u0002{0}\u000F on \u0002{1}\u000F.", command.Arguments["Target"], channel);
  383. switch (command.MessageType)
  384. {
  385. case MessageType.Channel:
  386. Bot.IRC.SendPrivateMessage(command.Location, noAccessMessage);
  387. break;
  388. case MessageType.Query:
  389. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, noAccessMessage);
  390. break;
  391. case MessageType.Notice:
  392. Bot.IRC.SendNotice(command.Nick.Nickname, noAccessMessage);
  393. break;
  394. }
  395. }
  396. }
  397. }
  398. }