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.

Command.cs 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections.Generic;
  2. namespace Combot.Modules
  3. {
  4. public class Command
  5. {
  6. public string Name { get; set; }
  7. public string Description { get; set; }
  8. public bool Enabled { get; set; }
  9. public List<string> ChannelBlacklist { get; set; }
  10. public List<string> NickBlacklist { get; set; }
  11. public List<string> Triggers { get; set; }
  12. public List<CommandArgument> Arguments { get; set; }
  13. public List<MessageType> AllowedMessageTypes { get; set; }
  14. public List<AccessType> AllowedAccess { get; set; }
  15. public bool ShowHelp { get; set; }
  16. public bool SpamCheck { get; set; }
  17. public bool ShouldSerializeValue()
  18. {
  19. return false;
  20. }
  21. public Command()
  22. {
  23. SetDefaults();
  24. }
  25. public void SetDefaults()
  26. {
  27. Name = string.Empty;
  28. Description = string.Empty;
  29. Enabled = true;
  30. Triggers = new List<string>();
  31. ChannelBlacklist = new List<string>();
  32. NickBlacklist = new List<string>();
  33. Arguments = new List<CommandArgument>();
  34. AllowedMessageTypes = new List<MessageType>();
  35. AllowedAccess = new List<AccessType>();
  36. ShowHelp = true;
  37. SpamCheck = true;
  38. }
  39. public void Copy(Command command)
  40. {
  41. Name = command.Name;
  42. Description = command.Description;
  43. Enabled = command.Enabled;
  44. Triggers = new List<string>();
  45. foreach (string trigger in command.Triggers)
  46. {
  47. Triggers.Add(trigger);
  48. }
  49. ChannelBlacklist = new List<string>();
  50. foreach (string channel in command.ChannelBlacklist)
  51. {
  52. ChannelBlacklist.Add(channel);
  53. }
  54. NickBlacklist = new List<string>();
  55. foreach (string nick in command.NickBlacklist)
  56. {
  57. NickBlacklist.Add(nick);
  58. }
  59. Arguments = new List<CommandArgument>();
  60. foreach (CommandArgument arg in command.Arguments)
  61. {
  62. CommandArgument newArg = new CommandArgument();
  63. newArg.Copy(arg);
  64. Arguments.Add(newArg);
  65. }
  66. AllowedMessageTypes = new List<MessageType>();
  67. foreach (MessageType messageType in command.AllowedMessageTypes)
  68. {
  69. AllowedMessageTypes.Add(messageType);
  70. }
  71. AllowedAccess = new List<AccessType>();
  72. foreach (AccessType accessType in command.AllowedAccess)
  73. {
  74. AllowedAccess.Add(accessType);
  75. }
  76. ShowHelp = command.ShowHelp;
  77. SpamCheck = command.SpamCheck;
  78. }
  79. public List<CommandArgument> GetValidArguments(List<string> passedArgs, MessageType messageType)
  80. {
  81. List<CommandArgument> validArguments = new List<CommandArgument>();
  82. for (int i = 0; i < Arguments.Count; i++)
  83. {
  84. if (Arguments[i].MessageTypes.Contains(messageType))
  85. {
  86. if (Arguments[i].DependentArguments.Count > 0)
  87. {
  88. if (Arguments[i].DependentArguments.Exists(arg => Arguments.Exists(val => val.Name == arg.Name)))
  89. {
  90. CommandArgument.DependentArgumentInfo checkedArgument = Arguments[i].DependentArguments.Find(dep => Arguments.Exists(val => val.Name == dep.Name));
  91. int argIndex = validArguments.FindIndex(arg => arg.Name == checkedArgument.Name);
  92. if (passedArgs.Count > argIndex && argIndex >= 0)
  93. {
  94. if (checkedArgument.Values.Exists(check => check.ToLower() == passedArgs[argIndex].ToLower()))
  95. {
  96. CommandArgument newArgument = new CommandArgument();
  97. newArgument.Copy(Arguments[i]);
  98. validArguments.Add(newArgument);
  99. }
  100. }
  101. }
  102. }
  103. else
  104. {
  105. CommandArgument newArgument = new CommandArgument();
  106. newArgument.Copy(Arguments[i]);
  107. validArguments.Add(newArgument);
  108. }
  109. }
  110. }
  111. return validArguments;
  112. }
  113. }
  114. }