Class: SlackBot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_slack_bot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
# File 'lib/simple_slack_bot/client.rb', line 9

def initialize
  @commands = []
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



6
7
8
# File 'lib/simple_slack_bot/client.rb', line 6

def commands
  @commands
end

#slack_realtime_clientObject

Returns the value of attribute slack_realtime_client.



5
6
7
# File 'lib/simple_slack_bot/client.rb', line 5

def slack_realtime_client
  @slack_realtime_client
end

#slack_web_clientObject

Returns the value of attribute slack_web_client.



5
6
7
# File 'lib/simple_slack_bot/client.rb', line 5

def slack_web_client
  @slack_web_client
end

Instance Method Details

#add_command(regex) ⇒ Object



13
14
15
16
17
18
# File 'lib/simple_slack_bot/client.rb', line 13

def add_command(regex)
  command = Command.new(self)
  command.regex = regex
  command.action = -> (data) { yield(data) }
  @commands << command
end

#configObject



34
35
36
# File 'lib/simple_slack_bot/client.rb', line 34

def config
  Config
end

#configureObject



38
39
40
# File 'lib/simple_slack_bot/client.rb', line 38

def configure
  block_given? ? yield(Config) : Config
end

#message(channel, text) ⇒ Object



46
47
48
# File 'lib/simple_slack_bot/client.rb', line 46

def message(channel, text)
  @slack_realtime_client.message channel: channel, text: text
end

#start!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/simple_slack_bot/client.rb', line 20

def start!
  if config.token.nil?
    puts 'You must setting a token.'
    return
  end

  slack_init
  message_event_init

  EM.run do
    @slack_realtime_client.start!
  end
end

#web_message(channel, text) ⇒ Object



42
43
44
# File 'lib/simple_slack_bot/client.rb', line 42

def web_message(channel, text)
  @slack_web_client.chat_postMessage(channel: channel, text: text, as_user: true)
end