Class: SlackBotServer::RemoteControl

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_bot_server/remote_control.rb

Overview

Send commands to a running SlackBotServer::Server instance

This should be initialized with a queue that is shared with the targetted server (e.g. the same local queue instance, or a redis queue instance that points at the same redis server).

Instance Method Summary collapse

Constructor Details

#initialize(queue:) ⇒ RemoteControl

Create a new instance of a remote control

Parameters:

  • queue (Object)

    any Object conforming to the queue API (i.e. with #push and #pop methods)



10
11
12
# File 'lib/slack_bot_server/remote_control.rb', line 10

def initialize(queue:)
  @queue = queue
end

Instance Method Details

#add_bot(*args) ⇒ Object

Sends an add_bot command to the server. See Server#add_bot for arguments.



16
17
18
# File 'lib/slack_bot_server/remote_control.rb', line 16

def add_bot(*args)
  @queue.push([:add_bot, *args])
end

#broadcast(key, message_data) ⇒ Object

Sends an broadcast command to the server.

Parameters:

  • key (String)

    the key of the bot which should send the message

  • message_data (Hash)

    passed directly to Bot#broadcast; see there for argument details.



30
31
32
# File 'lib/slack_bot_server/remote_control.rb', line 30

def broadcast(key, message_data)
  @queue.push([:broadcast, key, message_data])
end

#call(key, method, args) ⇒ Object

Sends a message to be called directly on the slack web API. Generally for debugging only.

Parameters:

  • key (String)

    the key of the bot which should send the message.

  • method (String, Symbol)

    the name of the method to call

  • args (Array)

    the arguments for the method to call



57
58
59
# File 'lib/slack_bot_server/remote_control.rb', line 57

def call(key, method, args)
  @queue.push([:call, [key, method, args]])
end

#remove_bot(key) ⇒ Object

Sends a remove_bot command to the server.

Parameters:

  • key (String)

    the key of the bot to remove.



22
23
24
# File 'lib/slack_bot_server/remote_control.rb', line 22

def remove_bot(key)
  @queue.push([:remove_bot, key])
end

#say(key, message_data) ⇒ Object

Sends an say command to the server.

Parameters:

  • key (String)

    the key of the bot which should send the message.

  • message_data (Hash)

    passed directly to Bot#say; see there for argument details.



38
39
40
# File 'lib/slack_bot_server/remote_control.rb', line 38

def say(key, message_data)
  @queue.push([:say, key, message_data])
end

#say_to(key, user_id, message_data) ⇒ Object

Sends an say_to command to the server.

Parameters:

  • key (String)

    the key of the bot which should send the message.

  • user_id (String)

    the Slack user ID of the person who should receive the message.

  • message_data (Hash)

    passed directly to Bot#say_to; see there for argument details.



48
49
50
# File 'lib/slack_bot_server/remote_control.rb', line 48

def say_to(key, user_id, message_data)
  @queue.push([:say_to, key, user_id, message_data])
end