Guest User

Untitled

a guest
Jul 20th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. Extensions
  2. ==========
  3. Introduction
  4. ------------
  5.  
  6. participle extensions are an easy way to add grouped, dynamically loadable commands to the bot. Syntax is simple:
  7.  
  8. class ClassName < Participle::Extension
  9. match :testcommand, "command", :usage => "A test command for the bot."
  10.  
  11. def testcommand msg, params
  12. msg.reply "Tested a new command."
  13. end
  14. end
  15.  
  16. To load an extension, stick the extension class file into /ext, and add the class name to the "extensions" directive in the bot configuration in main.rb. The class name, following Rails conventions, should be in camelCase and the file name itself should be under\_scored.
  17.  
  18. The <code>match</code> Command
  19. ------------------------------
  20.  
  21. <code>match</code> is the basic extension class method: the way to map a command to a subroutine and define its other characteristics. The syntax is:
  22.  
  23. match :function_name, "command string", {other arguments}
  24.  
  25. "other arguments" in this case will be a symbol-keyed hash of extra command characteristics. Valid keys:
  26.  
  27. * <code>:usage [string]</code>: The usage instructions. Default is nil.
  28. * <code>:admin [boolean]</code>: Whether to restrict this function to the bot's admin or not. Default is false.
  29. * <code>:event [symbol, optional]</code>: Event to fire this command on. Default is :message, options are :join and :botjoin.
  30. * <code>:trigger [boolean]</code>: Whether a trigger is necessary to fire this command. Default is true.
  31.  
  32. Command syntax
  33. --------------
  34. Command arguments can be in string or Regexp format. In a Regexp, the capture groups are passed to the matching function. In a string, the syntax is somewhat more advanced. Any normal text can be used; words that are prefixed with semicolons (:), however, will be treated as command arguments. They match greedily (as much of the string as they can). Optional arguments are instead prefixed with a semicolon and a question mark (:?). Example:
  35.  
  36. note :cmd :id :?option
  37.  
  38. Resulting in:
  39.  
  40. "note add 3" #=> {:cmd => "add", :id => "3"}
  41. "note remove" #=> does not match
  42. "note add 5 verbose" #=> {:cmd => "add", :id => "5", :option => "verbose"}
  43. "note add 7 a bunch of extra options" #=> {:cmd => "add", :id => "7", :option => "a bunch of extra options"}
  44.  
  45. The matching parameters are then passed to the command's associated function, along with a Message object.
  46.  
  47. The Message Object
  48. ------------------
  49. Participle::Message is a neat little object that allows easy access to dAmn chat commands. Instance methods involve Message#reply, which merely prints something out in the current room. Message#user is an object which contains basic data about the user who said the line. See lib/message.rb for more information.
  50.  
  51. The <code>load</code> Command
  52. -----------------------------
  53. Participle::Extension.load is just a wrapper around <code>gem</code>, <code>require</code>, and <code>Kernel.load</code> to make errors more manageable and user-friendly. <code>load</code> can be used to load gems or files from /ext/classes.
  54.  
  55. load :rsa # Loads RSA gem
  56. load :hello # Loads hello.rb from /ext/classes/hello
Add Comment
Please, Sign In to add comment