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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Security.Policy;
  4. namespace Combot.Modules.ModuleClasses
  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\u000F into a channel, send a private message by typing \u0002/msg {0} \u001Fcommand trigger\u000F, or send a notice by typing \u0002/notice {0} \u001Fcommand trigger\u000F. ",
  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}\u000F", string.Join(", ", 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\u000F.", 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}\u000F", 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\u000F";
  74. break;
  75. case MessageType.Query:
  76. messageSyntax = string.Format("\u0002/msg {0}\u000F", Bot.IRC.Nickname);
  77. break;
  78. case MessageType.Notice:
  79. messageSyntax = string.Format("\u0002/notice {0}\u000F", 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}\u000F", string.Join(" ", validArguments.Select(arg =>
  87. {
  88. if (arg.Required)
  89. {
  90. return "\u001F" + arg.Name + "\u000F\u0002";
  91. }
  92. return "[\u001F" + arg.Name + "\u000F\u0002]";
  93. })));
  94. }
  95. if (foundCommand.Triggers.Any())
  96. {
  97. string triggerString = (foundCommand.Triggers.Count > 1) ? string.Format("({0})", string.Join("|", foundCommand.Triggers)) : foundCommand.Triggers.First();
  98. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Syntax: {0} {1}\u0002{2}\u000F{3}", messageSyntax, Bot.ServerConfig.CommandPrefix, triggerString, argHelp));
  99. }
  100. // Display argument help
  101. if (validArguments.Count > 0)
  102. {
  103. validArguments.ForEach(arg =>
  104. {
  105. string commandDesc = string.Empty;
  106. if (arg.Description != string.Empty)
  107. {
  108. commandDesc = string.Format(" - {0}", arg.Description);
  109. }
  110. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\u0002{0}\u000F{1}", arg.Name, commandDesc));
  111. if (arg.AllowedValues.Count > 0)
  112. {
  113. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\tAllowed Values: \u0002{0}\u000F", string.Join(", ", arg.AllowedValues)));
  114. }
  115. });
  116. }
  117. }
  118. }
  119. else
  120. {
  121. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("You do not have access to view help on \u0002{0}\u000F.", helpCommand));
  122. }
  123. }
  124. else
  125. {
  126. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u000F does not exist.", helpCommand));
  127. }
  128. }
  129. else
  130. {
  131. Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u000F does not exist.", helpCommand));
  132. }
  133. }
  134. }
  135. }