Module: ESM::Command::Base::Lifecycle
- Extended by:
- ActiveSupport::Concern
- Included in:
- ESM::Command::Base
- Defined in:
- lib/esm/command/base/lifecycle.rb
Instance Method Summary collapse
-
#from_discord! ⇒ Object
Called internally by #execute, this method handles when a command has been executed on Discord.
- #from_request(request) ⇒ Object
- #on_execute ⇒ Object
- #on_request_accepted ⇒ Object
- #on_request_declined ⇒ Object
Instance Method Details
#from_discord! ⇒ Object
Called internally by #execute, this method handles when a command has been executed on Discord.
28 29 30 31 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 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/esm/command/base/lifecycle.rb', line 28 def from_discord! # Check for these BEFORE validating the arguments so even if an argument was invalid, it doesn't matter since these take priority timers.time!(:access_checks) do check_for_dev_only! check_for_registered! check_for_text_only! check_for_dm_only! check_for_player_mode! end # Now ensure the user hasn't smoked too much lead timers.time!(:argument_validation) do arguments.validate! end # Adding a comment to make this look better is always a weird idea info!(to_h) # Finish up the checks timers.time!(:before_execute) do check_for_nil_target_community! unless skipped_actions.nil_target_community? check_for_nil_target_server! unless skipped_actions.nil_target_server? check_for_nil_target_user! unless skipped_actions.nil_target_user? check_for_connected_server! unless skipped_actions.connected_server? check_for_cooldown! unless skipped_actions.cooldown? check_for_different_community! unless skipped_actions.different_community? end # Now execute the command result = nil timers.time!(:on_execute) do load_v1_code! if v1_code_needed? # V1 result = on_execute end timers.time!(:after_execute) do # Update the cooldown after the command has ran just in case there are issues create_or_update_cooldown unless skipped_actions.cooldown? end result end |
#from_request(request) ⇒ Object
Note:
Don't load target_user from the request. If the arguments contain a target, it will handle it
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/esm/command/base/lifecycle.rb', line 75 def from_request(request) @request = request @current_channel = ESM.bot.channel(request.requested_from_channel_id) @current_user = request.requestor # Initialize our command from the request arguments.merge!(request.command_arguments.symbolize_keys) if request.command_arguments.present? timers.time!(:from_request) do load_v1_code! if v1_code_needed? # V1 if @request.accepted on_request_accepted else # Reset the cooldown since the request was declined. current_cooldown.reset! if current_cooldown.present? on_request_declined end end end |
#on_execute ⇒ Object
97 98 |
# File 'lib/esm/command/base/lifecycle.rb', line 97 def on_execute end |
#on_request_accepted ⇒ Object
100 101 |
# File 'lib/esm/command/base/lifecycle.rb', line 100 def on_request_accepted end |
#on_request_declined ⇒ Object
103 104 |
# File 'lib/esm/command/base/lifecycle.rb', line 103 def on_request_declined end |