The easy to use and full featured Irc Bot everyone is talking about!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Runtime.Remoting.Messaging;
  4. namespace Combot.Modules.Plugins
  5. {
  6. public class Help : Module
  7. {
  8. public override void Initialize()
  9. {
  10. Bot.CommandReceivedEvent += HandleCommandEvent;
  11. }
  12. public override void ParseCommand(CommandMessage command)
  13. {
  14. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  15. if (foundCommand.Name == "Help")
  16. {
  17. if (command.Arguments.Count == 0)
  18. {
  19. SendFullHelp(command.Nick.Nickname, command.Access);
  20. }
  21. else if (command.Arguments.ContainsKey("Command"))
  22. {
  23. SendCommandHelp(command);
  24. }
  25. }
  26. }
  27. private void SendFullHelp(string recipient, List<AccessType> access)
  28. {
  29. Bot.IRC.SendNotice(recipient, string.Format("You have the following commands available to use. " +
  30. "To use them either type \u0002{1}\u001Fcommand trigger\u001F\u0002 into a channel, send a private message by typing \u0002/msg {0} \u001Fcommand trigger\u001F\u0002, or send a notice by typing \u0002/notice {0} \u001Fcommand trigger\u001F\u0002. ",
  31. Bot.IRC.Nickname, Bot.ServerConfig.CommandPrefix));
  32. Bot.IRC.SendNotice(recipient, "\u200B");
  33. List<string> commandList = new List<string>();
  34. foreach (Module module in Bot.Modules)
  35. {
  36. module.Commands.ForEach(command =>
  37. {
  38. if (command.AllowedAccess.Exists(allowed => access.Contains(allowed)) && command.ShowHelp)
  39. {
  40. commandList.Add(command.Name);
  41. }
  42. });
  43. }
  44. Bot.IRC.SendNotice(recipient, string.Format("\u0002{0}\u0002", string.Join("\u0002, \u0002", commandList)));
  45. Bot.IRC.SendNotice(recipient, "\u200B");
  46. Bot.IRC.SendNotice(recipient, string.Format("For more information on a specific command, including viewing the triggers, type \u0002{0}help \u001Fcommand\u001F\u0002.", Bot.ServerConfig.CommandPrefix));
  47. }
  48. private void SendCommandHelp(CommandMessage command)
  49. {
  50. string helpCommand = command.Arguments["Command"].ToString();
  51. Module foundModule = Bot.Modules.Find(mod => mod.Commands.Exists(cmd => (cmd.Name.ToLower() == helpCommand.ToLower() || cmd.Triggers.Contains(helpCommand)) && cmd.ShowHelp));
  52. if (foundModule != null)
  53. {
  54. Command foundCommand = foundModule.Commands.Find(cmd => (cmd.Name.ToLower() == helpCommand.ToLower() || cmd.Triggers.Contains(helpCommand)));
  55. if (foundCommand != null)
  56. {
  57. if (foundCommand.AllowedAccess.Exists(allowed => command.Access.Contains(allowed)))
  58. {
  59. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Help information for \u0002{0}\u0002", foundCommand.Name));
  60. if (foundCommand.Description != string.Empty)
  61. {
  62. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("{0}", foundCommand.Description));
  63. }
  64. Bot.IRC.SendNotice(command.Nick.Nickname, "\u200B");
  65. for (int i = 0; i < foundCommand.AllowedMessageTypes.Count; i++)
  66. {
  67. MessageType messageType = foundCommand.AllowedMessageTypes[i];
  68. // Generate Message Syntax
  69. string messageSyntax = string.Empty;
  70. switch (messageType)
  71. {
  72. case MessageType.Channel:
  73. messageSyntax = "\u0002/msg \u001Fchannel\u001F\u0002";
  74. break;
  75. case MessageType.Query:
  76. messageSyntax = string.Format("\u0002/msg {0}\u0002", Bot.IRC.Nickname);
  77. break;
  78. case MessageType.Notice:
  79. messageSyntax = string.Format("\u0002/notice {0}\u0002", Bot.IRC.Nickname);
  80. break;
  81. }
  82. List<CommandArgument> validArguments = foundCommand.Arguments.FindAll(arg => arg.MessageTypes.Contains(messageType));
  83. string argHelp = string.Empty;
  84. if (validArguments.Count > 0)
  85. {
  86. argHelp = string.Format(" \u0002{0}\u0002", string.Join(" ", validArguments.Select(arg =>
  87. {
  88. string argString = string.Empty;
  89. if (arg.DependentArguments.Count > 0)
  90. {
  91. argString = "(";
  92. }
  93. if (arg.Required)
  94. {
  95. argString += "\u001F" + arg.Name + "\u001F";
  96. }
  97. else
  98. {
  99. argString += "[\u001F" + arg.Name + "\u001F]";
  100. }
  101. if (arg.DependentArguments.Count > 0)
  102. {
  103. argString += string.Format("\u0002:When {0}\u0002)", string.Join(" or ", arg.DependentArguments.Select(dep => { return string.Format("\u0002\u001F{0}\u001F\u0002=\u0002{1}\u0002", dep.Name, string.Join(",", dep.Values)); })));
  104. }
  105. return argString;
  106. })));
  107. }
  108. if (foundCommand.Triggers.Any())
  109. {
  110. string triggerString = (foundCommand.Triggers.Count > 1) ? string.Format("({0})", string.Join("|", foundCommand.Triggers)) : foundCommand.Triggers.First();
  111. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Syntax: {0} {1}\u0002{2}\u0002{3}", messageSyntax, Bot.ServerConfig.CommandPrefix, triggerString, argHelp));
  112. }
  113. // Display argument help
  114. if (validArguments.Count > 0)
  115. {
  116. validArguments.ForEach(arg =>
  117. {
  118. string commandDesc = string.Empty;
  119. if (arg.Description != string.Empty)
  120. {
  121. commandDesc = string.Format(" - {0}", arg.Description);
  122. }
  123. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\u0002{0}\u0002{1}", arg.Name, commandDesc));
  124. if (arg.AllowedValues.Count > 0)
  125. {
  126. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\t\tAllowed Values: \u0002{0}\u0002", string.Join(", ", arg.AllowedValues)));
  127. }
  128. });
  129. }
  130. }
  131. }
  132. else
  133. {
  134. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("You do not have access to view help on \u0002{0}\u0002.", helpCommand));
  135. }
  136. }
  137. else
  138. {
  139. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u0002 does not exist.", helpCommand));
  140. }
  141. }
  142. else
  143. {
  144. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u0002 does not exist.", helpCommand));
  145. }
  146. }
  147. }
  148. }