bot_mob 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06931f3388ebdfe67f7457368c871dbab52471d8
4
- data.tar.gz: 22bf96d21900c9f7ad9a1295b0d2de505d1c9b8c
3
+ metadata.gz: 83ed3ccf1a952e7cf93cdd80b6494ef87cac8c2b
4
+ data.tar.gz: 87ebbd02f253d73b6f7f4deb50d16eea869f3405
5
5
  SHA512:
6
- metadata.gz: 26ec6266478293e6dd4ed4b78972255e7b0c968bb002794a9294dab499918615d6702ffbe0400ec9c1946425740da493812d29af5d62833e6ca905bb6a823ee1
7
- data.tar.gz: 282eecbcd50a76b887c2cb628bb07a972ae7e3c7b1e456f23d6dc97da7c186e62973ed8fed7e4210df8b00c8f844058b73dc621ce46214c1e42606c9d9398415
6
+ metadata.gz: 2252550d04e0dab068f2b6c3af6ea1bb240aafc4929ef53e6cfd250ded4c5775ae7e55f43794bd1a861fcceefe679de2cea9d3fd92e5e2279d51fa6624ef7946
7
+ data.tar.gz: ecc324ba9be6ebc2a68ba86d3e1e8e16b580161b7216fd0b2e27449f5a5a2acf60017b95373c770c22f6bc25db2786a34a665bc4a6165eae3b9926a34a3a1c37
data/lib/bot_mob/bot.rb CHANGED
@@ -4,7 +4,7 @@ module BotMob
4
4
  # This is the base for all bots that will connect
5
5
  # to Slack.
6
6
  class Bot
7
- attr_reader :user_id, :state
7
+ attr_reader :user_id, :state, :message
8
8
 
9
9
  def initialize(user_id, token)
10
10
  @user_id = user_id
@@ -60,11 +60,11 @@ module BotMob
60
60
  end
61
61
  end
62
62
 
63
- def handle(_message)
63
+ def handle(message)
64
64
  # noop
65
65
  end
66
66
 
67
- def respond?(_message)
67
+ def respond?(message)
68
68
  false
69
69
  end
70
70
 
@@ -100,12 +100,12 @@ module BotMob
100
100
  end
101
101
 
102
102
  client.on :message do |data|
103
- message = BotMob::InboundMessage.new(data)
103
+ message = BotMob::InboundMessage.new(:websocket, data)
104
104
 
105
105
  if respond?(message)
106
106
  logger.info("Received message at #{Time.now}")
107
107
  logger.info(" Message: \"#{message.text}\"")
108
- handle message
108
+ handle(message)
109
109
  end
110
110
  end
111
111
 
@@ -4,22 +4,49 @@ module BotMob
4
4
  # The InboundMessage class provides easy access to
5
5
  # messages received from Slack's Real Time API
6
6
  class InboundMessage
7
- attr_reader :source, :data
7
+ attr_reader :source, :data, :token, :team_id, :team_domain,
8
+ :channel_id, :channel_name, :user_id, :user_name,
9
+ :command, :text, :bot_id, :response_url, :ts
8
10
 
9
- def initialize(data)
11
+ def initialize(source, data)
10
12
  @data = data
13
+ send("parse_#{source}".to_sym, data)
11
14
  end
12
15
 
13
- def text
14
- data[:text] || ''
16
+ def arguments
17
+ @arguments ||= text[%r{\/[\w'_-]+\s*[\w'_-]+\s*(.*)}, 1]
15
18
  end
16
19
 
17
- def channel_id
18
- data[:channel] || data[:channel_id]
20
+ def command?
21
+ !command.nil?
19
22
  end
20
23
 
21
24
  def human?
22
- data[:bot_id].nil?
25
+ bot_id.nil?
26
+ end
27
+
28
+ private
29
+
30
+ def parse_websocket(data)
31
+ @text = data[:text]
32
+ @channel_id = data[:channel_id]
33
+ @bot_id = data[:bot_id]
34
+ @team = data[:team]
35
+ @ts = data[:ts]
36
+ @user_id = data[:user_id]
37
+ end
38
+
39
+ def parse_webhook(data)
40
+ @token = data['token']
41
+ @team_id = data['team_id']
42
+ @team_domain = data['team_domain']
43
+ @channel_id = data['channel_id']
44
+ @channel_name = data['channel_name']
45
+ @user_id = data['user_id']
46
+ @user_name = data['user_name']
47
+ @command = data['command']
48
+ @text = data['text']
49
+ @response_url = data['response_url']
23
50
  end
24
51
  end
25
52
  end
@@ -1,3 +1,3 @@
1
1
  module BotMob
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bot_mob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Werner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny