slackbotsy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slackbotsy/bot.rb +14 -6
- data/lib/slackbotsy/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: 85ec438cfe6832c6fdb513d9275cd55897e397ea
|
4
|
+
data.tar.gz: 4e145b2b2af60fbd7b49c03c58b6816fd33af0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c55304f276ccc1f6781b4e7c163f32625c25f0d6aa3997245d3050cc37d182aab98efab24facd7467b7012ba6cf2c50405fdb51a5a2a49eacb065123622ffbde
|
7
|
+
data.tar.gz: 1df7f43e2e750958436e0ea035d2fa593a392c00ece000c032c0dc419a8dc32bd2dfafba68fbf4b7071e19879f3c14c7d1c8a004fa6cd6c260a01c44ded07e11
|
data/lib/slackbotsy/bot.rb
CHANGED
@@ -2,18 +2,20 @@ require 'net/http'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'uri'
|
4
4
|
require 'json'
|
5
|
-
require 'set'
|
5
|
+
# require 'set'
|
6
6
|
|
7
7
|
module Slackbotsy
|
8
8
|
|
9
9
|
class Bot
|
10
10
|
|
11
|
+
attr_accessor :listeners, :last_description
|
12
|
+
|
11
13
|
def initialize(options)
|
12
14
|
@options = options
|
13
15
|
|
14
16
|
## use set of tokens for (more or less) O(1) lookup on multiple channels
|
15
17
|
@options['outgoing_token'] = Array(@options['outgoing_token']).to_set
|
16
|
-
@
|
18
|
+
@listeners = []
|
17
19
|
setup_incoming_webhook # http connection for async replies
|
18
20
|
yield if block_given? # run any hear statements in block
|
19
21
|
end
|
@@ -50,9 +52,15 @@ module Slackbotsy
|
|
50
52
|
post({ attachments: attachments }.merge(options))
|
51
53
|
end
|
52
54
|
|
55
|
+
## record a description of the next hear block, for use in help
|
56
|
+
def desc(command, description = nil)
|
57
|
+
@last_desc = [ command, description ]
|
58
|
+
end
|
59
|
+
|
53
60
|
## add regex to things to hear
|
54
61
|
def hear(regex, &block)
|
55
|
-
@
|
62
|
+
@listeners << OpenStruct.new(regex: regex, desc: @last_desc, proc: block)
|
63
|
+
@last_desc = nil
|
56
64
|
end
|
57
65
|
|
58
66
|
## pass list of files containing hear statements, to be opened and evaled
|
@@ -70,10 +78,10 @@ module Slackbotsy
|
|
70
78
|
|
71
79
|
## loop things to look for and collect immediate responses
|
72
80
|
## rescue everything here so the bot keeps running even with a broken script
|
73
|
-
responses = @
|
74
|
-
if mdata = msg[:text].strip.match(regex)
|
81
|
+
responses = @listeners.map do |hear|
|
82
|
+
if mdata = msg[:text].strip.match(hear.regex)
|
75
83
|
begin
|
76
|
-
Slackbotsy::Message.new(self, msg).instance_exec(mdata, &proc)
|
84
|
+
Slackbotsy::Message.new(self, msg).instance_exec(mdata, &hear.proc)
|
77
85
|
rescue => err
|
78
86
|
err
|
79
87
|
end
|
data/lib/slackbotsy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackbotsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|