Class: SlackBot::Command

Inherits:
Object
  • Object
show all
Includes:
SlackBot::Concerns::InteractionKlass, SlackBot::Concerns::ViewKlass
Defined in:
lib/slack_bot/command.rb,
sig/slack_bot.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SlackBot::Concerns::ViewKlass

included

Methods included from SlackBot::Concerns::InteractionKlass

included

Constructor Details

#initialize(current_user:, params:, args:, config: nil) ⇒ Command

Returns a new instance of Command.

Parameters:

  • current_user: (Object)
  • params: (Hash[String, untyped])
  • args: (String)
  • config: (Config) (defaults to: nil)


10
11
12
13
14
15
16
17
# File 'lib/slack_bot/command.rb', line 10

def initialize(current_user:, params:, args:, config: nil)
  @current_user = current_user
  @params = params
  @config = config || SlackBot::Config.current_instance

  @args = SlackBot::Args.new
  @args.raw_args = args
end

Instance Attribute Details

#argsArgs (readonly)

Returns the value of attribute args.

Returns:



9
10
11
# File 'lib/slack_bot/command.rb', line 9

def args
  @args
end

#configConfig (readonly)

Returns the value of attribute config.

Returns:



9
10
11
# File 'lib/slack_bot/command.rb', line 9

def config
  @config
end

#current_userObject (readonly)

Returns the value of attribute current_user.

Returns:

  • (Object)


9
10
11
# File 'lib/slack_bot/command.rb', line 9

def current_user
  @current_user
end

#paramsHash[String, untyped] (readonly)

Returns the value of attribute params.

Returns:

  • (Hash[String, untyped])


9
10
11
# File 'lib/slack_bot/command.rb', line 9

def params
  @params
end

Instance Method Details

#commandString

Returns:

  • (String)


19
20
21
# File 'lib/slack_bot/command.rb', line 19

def command
  params[:command]
end

#only_direct_message?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/slack_bot/command.rb', line 31

def only_direct_message?
  true
end

#only_slack_team?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/slack_bot/command.rb', line 35

def only_slack_team?
  true
end

#only_user?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/slack_bot/command.rb', line 27

def only_user?
  true
end

#render_response(response_type = nil, **kwargs) ⇒ Hash[String, untyped]?

Parameters:

  • response_type (String) (defaults to: nil)
  • kwargs (Object)

Returns:

  • (Hash[String, untyped], nil)


39
40
41
42
43
44
45
# File 'lib/slack_bot/command.rb', line 39

def render_response(response_type = nil, **kwargs)
  return if !response_type

  {
    response_type: response_type
  }.merge(kwargs)
end

#textString

Returns:

  • (String)


23
24
25
# File 'lib/slack_bot/command.rb', line 23

def text
  params[:text]
end