Module: Rubot::ApplicationCommand
- Included in:
- Client
- Defined in:
- lib/rubot/modules/application_command.rb
Instance Method Summary collapse
- #add_application_command(command:, subcommand: nil, group: nil, options: ->(option_builder) { option_builder }, type: :chat_input, &block) ⇒ Object
- #launch_application_commands ⇒ Object
Instance Method Details
#add_application_command(command:, subcommand: nil, group: nil, options: ->(option_builder) { option_builder }, type: :chat_input, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rubot/modules/application_command.rb', line 7 def add_application_command(command:, subcommand: nil, group: nil, options: ->(option_builder) { option_builder }, type: :chat_input, &block) @application_commands_queue ||= Array[] @application_commands_queue << Hash[ :command => command, :subcommand => subcommand, :group => group, :type => type, :options => , :run => block ] end |
#launch_application_commands ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubot/modules/application_command.rb', line 19 def launch_application_commands @application_commands_queue.each do |command| command.transform_keys!(&:to_sym) register_application_command(command[:command][:name].to_s, command[:command][:description].to_s, :type => command[:type] || :chat_input) do |option_builder| if command[:subcommand] @application_commands_queue.each do |subcommand| next unless subcommand[:command][:name] == command[:command][:name] && subcommand[:subcommand] option_builder.subcommand(subcommand[:subcommand][:name].to_s, subcommand[:subcommand][:description].to_s) do |sub_option_builder| command[:options].call(sub_option_builder) end @application_commands_queue.delete(subcommand) end else command[:options].call(option_builder) @application_commands_queue.delete(command) end cmd = application_command(command[:command][:name].to_sym) do |event| command[:run].call(event) unless command[:subcommand] end next unless command[:subcommand] cmd.subcommand(command[:subcommand][:name].to_sym) do |event| command[:run].call(event) if command[:subcommand] end end end end |