Class: Botiasloop::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/botiasloop/commands/base.rb

Overview

Base class for all slash commands Provides DSL for defining command metadata

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command(name = nil) ⇒ Symbol? Also known as: command_name

Get or set the command name Automatically registers the command when name is set

Parameters:

  • name (Symbol, nil) (defaults to: nil)

    Command name to set

Returns:

  • (Symbol, nil)

    The command name



14
15
16
17
18
19
20
21
# File 'lib/botiasloop/commands/base.rb', line 14

def command(name = nil)
  if name
    @command_name = name
    # Auto-register when command name is set
    Botiasloop::Commands.registry.register(self)
  end
  @command_name
end

.description(text = nil) ⇒ String?

Get or set the command description

Parameters:

  • text (String, nil) (defaults to: nil)

    Description text to set

Returns:

  • (String, nil)

    The command description



29
30
31
32
33
34
# File 'lib/botiasloop/commands/base.rb', line 29

def description(text = nil)
  if text
    @description = text
  end
  @description
end

.inherited(subclass) ⇒ Object

Called when a subclass is defined No-op - registration happens when command() is called



38
39
40
# File 'lib/botiasloop/commands/base.rb', line 38

def inherited(subclass)
  super
end

Instance Method Details

#execute(context, args = nil) ⇒ String

Execute the command

Parameters:

  • context (Context)

    Execution context

  • args (String, nil) (defaults to: nil)

    Command arguments

Returns:

  • (String)

    Command response

Raises:

  • (NotImplementedError)

    Subclass must implement



49
50
51
# File 'lib/botiasloop/commands/base.rb', line 49

def execute(context, args = nil)
  raise NotImplementedError, "Subclass must implement #execute"
end