Class: Plugins::Macros
- Inherits:
-
Object
- Object
- Plugins::Macros
- Includes:
- Cinch::Helpers, Cinch::Plugin
- Defined in:
- lib/Zeta/plugins/macros.rb
Instance Attribute Summary collapse
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
Instance Method Summary collapse
- #execute_macro(m, macro, arguments) ⇒ Object
- #execute_reloadmacros(m) ⇒ Object
-
#initialize(*args) ⇒ Macros
constructor
A new instance of Macros.
Methods included from Cinch::Plugin
Constructor Details
#initialize(*args) ⇒ Macros
Returns a new instance of Macros.
17 18 19 20 21 |
# File 'lib/Zeta/plugins/macros.rb', line 17 def initialize *args super # @macros = YAML::load_file($root_path + '/locales/macros.yml') @macros = load_locale 'macros' end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
11 12 13 |
# File 'lib/Zeta/plugins/macros.rb', line 11 def macros @macros end |
Instance Method Details
#execute_macro(m, macro, arguments) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/Zeta/plugins/macros.rb', line 37 def execute_macro m, macro, arguments return unless @macros.has_key?(macro) parse(arguments.to_s.rstrip, @macros[macro], m.channel, m.user) # Guide to writing macros: # - A macro can be a string, hash, or array # - They can be embedded within each other (as lines, etc.) # To have options for a macro (either globally or within embedded macros:) # => macroname: # => type: (string) ['random'] (optional) # => sent_as: (string) ['reply','action'] (optional) # => sleep: (numeric) a number that represents how many seconds the bot will wait for each line # => lines: (array, string, hash) an object that represents the individual lines. # Guide to writing macros v3 templates: # transform/(default text)[template] # transform/ (optional): # cap (all uppercase) # lc (all lowercase) # (default text) (optional): # Can be anything that you want. May want to watch usage of brackets &c. # [template] (required): # Can be one of these tags: # * in (input/argument, will default to the default text if available, otherwise it will choose a random nick.) # * channel (the current channel that the command is run in.) # * bot (The bot's nick) # * self (the originating user's nick) end |
#execute_reloadmacros(m) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/Zeta/plugins/macros.rb', line 24 def execute_reloadmacros m return unless check_user(m, :admin) # return unless check_channel(m) begin # @macros = YAML::load_file($root_path + '/locales/macros.yml') @macros = load_locale 'macros' m.user.notice "Macros have been reloaded." rescue m.user.notice "Reloading macros has failed: #{$!}" end end |