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
- #execute_action(action) ⇒ Object
- #execute_command ⇒ Object
- #execute_on_every_message ⇒ Object
- #execute_on_mention ⇒ Object
- #skip_task(**kwargs) ⇒ Object
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_command ⇒ Object
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_message ⇒ Object
106 107 108 109 110 111 |
# File 'lib/rubydium/mixins/command_macros.rb', line 106 def self.class..each do |action| next if action[:ignore_forwarded] && @msg.forward_date execute_action(action[:action]) end end |
#execute_on_mention ⇒ Object
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 |