Module: Rubydium::Mixins::CommandMacros

Defined in:
lib/rubydium/mixins/command_macros.rb

Overview

Macro-like definitions that describe what actions bot takes in reaction to messages.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/rubydium/mixins/command_macros.rb', line 8

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#execute_action(action) ⇒ Object



163
164
165
166
167
168
169
170
# File 'lib/rubydium/mixins/command_macros.rb', line 163

def execute_action(action)
  case action
  when Symbol
    public_send action
  when Proc
    instance_exec(&action)
  end
end

#execute_commandObject



153
154
155
156
157
158
159
160
161
# File 'lib/rubydium/mixins/command_macros.rb', line 153

def execute_command
  command = self.class.registered_commands[@command]
  return unless command
  return if command[:ignore_forwarded] && @msg.forward_origin

  action = command[:action]

  execute_action(action)
end

#execute_on_every_messageObject



137
138
139
140
141
142
143
# File 'lib/rubydium/mixins/command_macros.rb', line 137

def execute_on_every_message
  self.class.registered_on_every_message.each do |action|
    next if action[:ignore_forwarded] && @msg.forward_origin

    execute_action(action[:action])
  end
end

#execute_on_mentionObject



145
146
147
148
149
150
151
# File 'lib/rubydium/mixins/command_macros.rb', line 145

def execute_on_mention
  self.class.registered_on_mention.each do |action|
    next if action[:ignore_forwarded] && @msg.forward_origin

    execute_action(action[:action])
  end
end

#execute_on_shutdownObject



131
132
133
134
135
# File 'lib/rubydium/mixins/command_macros.rb', line 131

def execute_on_shutdown
  self.class.registered_on_shutdown.each do |action|
    execute_action(action)
  end
end

#execute_on_startupObject



125
126
127
128
129
# File 'lib/rubydium/mixins/command_macros.rb', line 125

def execute_on_startup
  self.class.registered_on_startup.each do |action|
    execute_action(action)
  end
end