vrobot3 is a chat bot for IRC and Discord.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
6.5KB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright © 2016 Project Golan
  4. //
  5. // See "LICENSE" for more information.
  6. //
  7. //-----------------------------------------------------------------------------
  8. //
  9. // Utility commands.
  10. // .rand, .help, .decide, .eightball, .mystery
  11. //
  12. //-----------------------------------------------------------------------------
  13. using System;
  14. using System.Linq;
  15. namespace ProjectGolan.Vrobot3.Modules
  16. {
  17. //
  18. // Mod_Utils
  19. //
  20. public class Mod_Utils : IBotModule
  21. {
  22. private readonly Random rnd = Utils.GetRND();
  23. //
  24. // Mod_Utils constructor
  25. //
  26. public Mod_Utils(Bot bot) :
  27. base(bot)
  28. {
  29. commands["rand"] = new BotCommandStructure{
  30. cmd = cmdRand,
  31. help = "Random number device.\n" +
  32. "Syntax: .rand maximum [minimum]\n" +
  33. "Example: .rand 100"
  34. };
  35. commands["help"] = new BotCommandStructure{
  36. cmd = cmdHelp,
  37. help = "Shows help or a list of commands.\n" +
  38. "Syntax: .help [topic]\n" +
  39. "Example: .help\n" +
  40. "Example: .help eightball"
  41. };
  42. commands["decide"] = new BotCommandStructure{
  43. cmd = cmdDecide,
  44. help = "Decides between 2 or more choices.\n" +
  45. "Syntax: .decide x, y[, ...]\n" +
  46. "Example: .decide apples, oranges, bananas"
  47. };
  48. commands["eightball"] = new BotCommandStructure{
  49. cmd = cmdEightball,
  50. help = "Peer into the magic 8-ball.\n" +
  51. "Example: .eightball If I take the mask off, will you die?"
  52. };
  53. commands["mystery"] = new BotCommandStructure{
  54. cmd = cmdMystery,
  55. help = @"Does nothing. \o/"
  56. };
  57. postSetup();
  58. }
  59. //
  60. // cmdMystery
  61. //
  62. public void cmdMystery(User usr, Channel channel, String msg) {}
  63. //
  64. // cmdRand
  65. //
  66. public void cmdRand(User usr, Channel channel, String msg)
  67. {
  68. var args = Utils.GetArguments(msg, commands["rand"].help, 1, 2, ' ');
  69. double max = 0.0, min = 0.0;
  70. Utils.TryParse(args[0].Trim(), "Invalid maximum.", out max);
  71. if(args.Length == 2)
  72. Utils.TryParse(args[1].Trim(), "Invalid minimum.", out min);
  73. bot.reply(usr, channel,
  74. Utils.SetRange(rnd.NextDouble(), min, max).ToString());
  75. }
  76. //
  77. // cmdHelp
  78. //
  79. public void cmdHelp(User usr, Channel channel, String msg)
  80. {
  81. msg = msg.Trim();
  82. if(msg == String.Empty || msg == "admin")
  83. helpList(channel, msg == "admin");
  84. else
  85. helpCommand(channel, msg);
  86. }
  87. //
  88. // cmdDecide
  89. //
  90. public void cmdDecide(User usr, Channel channel, String msg)
  91. {
  92. var args = Utils.GetArguments(msg, commands["decide"].help, 2);
  93. bot.reply(usr, channel, args[rnd.Next(args.Length)].Trim());
  94. }
  95. //
  96. // helpList
  97. //
  98. private void helpList(Channel channel, bool admin)
  99. {
  100. var outp = String.Empty;
  101. var en =
  102. from kvp in bot.cmdfuncs
  103. let fhidden = kvp.Value.Item2.hidden
  104. let fadmin = kvp.Value.Item2.role != BotRole.User
  105. where
  106. bot.checkModPermissions(channel, kvp.Value.Item2.mod) &&
  107. ((admin && fadmin) || (!admin && !fadmin)) &&
  108. !fhidden
  109. orderby kvp.Key
  110. select kvp.Key;
  111. outp += "Available commands: ";
  112. foreach(var key in en)
  113. {
  114. outp += key;
  115. if(key != en.Last())
  116. outp += ", ";
  117. }
  118. bot.message(channel, outp);
  119. }
  120. //
  121. // helpCommand
  122. //
  123. private void helpCommand(Channel channel, String cmdname)
  124. {
  125. if(bot.cmdfuncs.ContainsKey(cmdname))
  126. {
  127. var str = bot.cmdfuncs[cmdname].Item2.help;
  128. if(!bot.clientInfo.hasNewlines) str = str.Replace("\n", " || ");
  129. bot.message(channel, str ?? "No help available for this command.");
  130. }
  131. else
  132. bot.message(channel, "Invalid command, for a list do \".help\".");
  133. }
  134. //
  135. // cmdEightball
  136. //
  137. public void cmdEightball(User usr, Channel channel, String msg)
  138. {
  139. String[] answers = {
  140. "Yes.",
  141. "No.",
  142. "Try again later.",
  143. "Reply hazy.",
  144. "Perhaps...",
  145. "Maybe not...",
  146. "Definitely.",
  147. "Never.",
  148. "system error [0xfded] try again later",
  149. "Can you repeat the question?",
  150. "Most certainly.",
  151. "Nope.",
  152. "Without a doubt.",
  153. "Not at all.",
  154. "Better not tell you now.",
  155. "Concentrate and ask again.",
  156. "It is decidedly so.",
  157. "My reply is \"no\".",
  158. "You may rely on it.",
  159. "Don't count on it.",
  160. "The answer is uncertain.",
  161. "Sorry, I wasn't paying attention. What'd you say?",
  162. "As I see it, yes.",
  163. "My sources say \"no\".",
  164. "Most likely.",
  165. "Very doubtful.",
  166. "I don't know. Ask your mom.",
  167. "The demon runes are quaking again. One moment.",
  168. "Outlook good.",
  169. "Outlook is not so good.",
  170. "Indeed.",
  171. "Absolutely not.",
  172. "Yeah, we'll go with that.",
  173. "That works.",
  174. "Of course. What are you, stupid?",
  175. "No. Hell no.",
  176. "Signs say yes.",
  177. "Aren't you a little too old to be believing that?",
  178. "Looks good to me.",
  179. "Sure, why not?",
  180. "It is certain.",
  181. "pls no",
  182. "Yes, please.",
  183. "Nah.",
  184. "Go for it!",
  185. "Negative.",
  186. "Obviously, dumbass.",
  187. "I doubt it.",
  188. "Eeeh...it's likely?",
  189. "Forget about it.",
  190. "Chances aren't good.",
  191. "Ahahahahahahaha no.",
  192. "Maybe? I think.",
  193. "No. Die.",
  194. "Huh? Oh, sure.",
  195. "Yeah, right...",
  196. "How about no.",
  197. "Doesn't look good to me.",
  198. "Probably.",
  199. "Obviously not, dumbass."
  200. };
  201. bot.reply(usr, channel, answers[rnd.Next(0, answers.Length)]);
  202. }
  203. }
  204. }
  205. // EOF