Class: Cinch::Plugins::Macros

Inherits:
Object
  • Object
show all
Includes:
Admin, Cinch::Plugin
Defined in:
lib/cinch/plugins/macros.rb

Constant Summary

Constants included from Admin

Admin::TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Admin

#add_admin, #add_trusted, #delete_admin, #delete_trusted, #each_controlchannel, #each_online_admin, #each_online_trusted, #get_admins, #get_trusted, #is_admin?, #is_trusted?, #no_admins?

Methods included from Helpers

#check_user, #is_channel_disabled?, table_format

Constructor Details

#initialize(*args) ⇒ Macros

Returns a new instance of Macros


15
16
17
18
# File 'lib/cinch/plugins/macros.rb', line 15

def initialize *args
  super
  @macros = YAML::load(open(config[:macro_yaml_path]))
end

Instance Attribute Details

#macrosObject (readonly)

Returns the value of attribute macros


11
12
13
# File 'lib/cinch/plugins/macros.rb', line 11

def macros
  @macros
end

Instance Method Details

#execute_macro(m, macro, arguments) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cinch/plugins/macros.rb', line 32

def execute_macro m, macro, arguments
  return unless @macros.has_key?(macro)
  parse(arguments, @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.
  # NOTE: Attributes/options (type, sent_as, etc.) WILL pass through unless specifically stated.

  # 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


21
22
23
24
25
26
27
28
29
# File 'lib/cinch/plugins/macros.rb', line 21

def execute_reloadmacros m
  return unless is_trusted?(m.user)
  begin
    @macros = YAML::load(open(config[:macro_yaml_path]))
    m.user.notice "Macros have been reloaded."
  rescue
    m.user.notice "Reloading macros has failed: #{$!}"
  end
end