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



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

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

#execute_commandObject



120
121
122
123
124
125
126
127
128
# File 'lib/rubydium/mixins/command_macros.rb', line 120

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

  action = command[:action]

  execute_action(action)
end

#execute_on_every_messageObject



106
107
108
109
110
111
# File 'lib/rubydium/mixins/command_macros.rb', line 106

def execute_on_every_message
  self.class.registered_on_every_message.each do |action|
    next if action[:ignore_forwarded] && @msg.forward_date
    execute_action(action[:action])
  end
end

#execute_on_mentionObject



113
114
115
116
117
118
# File 'lib/rubydium/mixins/command_macros.rb', line 113

def execute_on_mention
  self.class.registered_on_mention.each do |action|
    next if action[:ignore_forwarded] && @msg.forward_date
    execute_action(action[:action])
  end
end

#skip_task(**kwargs) ⇒ Object



100
101
102
103
104
# File 'lib/rubydium/mixins/command_macros.rb', line 100

def skip_task(**kwargs)
  kwargs.each_pair do |task_type, task_name|

  end
end