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 +4 -4
- data/lib/bot_mob/bot.rb +5 -5
- data/lib/bot_mob/inbound_message.rb +34 -7
- data/lib/bot_mob/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83ed3ccf1a952e7cf93cdd80b6494ef87cac8c2b
|
4
|
+
data.tar.gz: 87ebbd02f253d73b6f7f4deb50d16eea869f3405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
63
|
+
def handle(message)
|
64
64
|
# noop
|
65
65
|
end
|
66
66
|
|
67
|
-
def respond?(
|
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
|
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
|
14
|
-
|
16
|
+
def arguments
|
17
|
+
@arguments ||= text[%r{\/[\w'_-]+\s*[\w'_-]+\s*(.*)}, 1]
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def command?
|
21
|
+
!command.nil?
|
19
22
|
end
|
20
23
|
|
21
24
|
def human?
|
22
|
-
|
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
|
data/lib/bot_mob/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|