slackbotsy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -3
- data/lib/slackbotsy/bot.rb +4 -6
- data/lib/slackbotsy/message.rb +20 -0
- data/lib/slackbotsy/version.rb +1 -1
- data/lib/slackbotsy.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7dc66aaddae9bf1414f43fcc6cb8b6d3fd760cd
|
4
|
+
data.tar.gz: 1d9104a7ac7f98daa480faaa81d1b9b3e5841c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b77d7cf74a57fe85d941d0cfd77f3b8a7ab65d68349c43a24ddc925b7b68b3444abc9c6c9893ee30255636795e9b76de907da246e365e3a9ebc2006fc3ec737c
|
7
|
+
data.tar.gz: 623b80a4ad3a7c5146d0aa1cb82fd99240bf6dffa3b94f64b33f3967b87fd4e69ddc266a7ec3dc97dcdde2eed83e751b7a034d5919386e477c0a72d012deb5f6
|
data/README.md
CHANGED
@@ -16,6 +16,35 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install slackbotsy
|
18
18
|
|
19
|
-
##
|
20
|
-
|
21
|
-
|
19
|
+
## Example usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'slackbotsy'
|
23
|
+
require 'sinatra'
|
24
|
+
|
25
|
+
config = {
|
26
|
+
'team' => 'your_team',
|
27
|
+
'channel' => '#default',
|
28
|
+
'name' => 'botsy',
|
29
|
+
'incoming_token' => 'secret',
|
30
|
+
'outgoing_token' => 'secret'
|
31
|
+
}
|
32
|
+
|
33
|
+
bot = Slackbotsy::Bot.new(config) do
|
34
|
+
|
35
|
+
hear /echo\s+(.+)/ do |data, mdata|
|
36
|
+
"I heard #{data['user_name']} say '#{mdata[1]}' in #{data['channel_name']}"
|
37
|
+
end
|
38
|
+
|
39
|
+
hear /flip out/i do
|
40
|
+
open('http://tableflipper.com/gif') do |f|
|
41
|
+
"<#{f.read}>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
post '/' do
|
48
|
+
bot.handle_item(params)
|
49
|
+
end
|
50
|
+
```
|
data/lib/slackbotsy/bot.rb
CHANGED
@@ -7,11 +7,11 @@ module Slackbotsy
|
|
7
7
|
|
8
8
|
class Bot
|
9
9
|
|
10
|
-
def initialize(options
|
10
|
+
def initialize(options)
|
11
11
|
@options = options
|
12
12
|
@regexes = {}
|
13
13
|
setup_incoming_webhook # http connection for async replies
|
14
|
-
|
14
|
+
yield if block_given? # run any hear statements in block
|
15
15
|
end
|
16
16
|
|
17
17
|
## setup http connection for sending async incoming webhook messages to slack
|
@@ -45,7 +45,7 @@ module Slackbotsy
|
|
45
45
|
options = { attachments: [ attachment ] }.merge(options)
|
46
46
|
say(text, options)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
## add regex to things to hear
|
50
50
|
def hear(regex, &block)
|
51
51
|
@regexes[regex] = block
|
@@ -60,14 +60,12 @@ module Slackbotsy
|
|
60
60
|
## loop things to look for and collect immediate responses
|
61
61
|
responses = @regexes.map do |regex, proc|
|
62
62
|
if mdata = msg[:text].strip.match(regex)
|
63
|
-
|
63
|
+
Slackbotsy::Message.new(self, msg).instance_exec(mdata, &proc)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
## format any replies for http response
|
68
68
|
if responses
|
69
|
-
# text = responses.compact.join('\n')
|
70
|
-
# %Q[{"text": "#{text}"}]
|
71
69
|
{ text: responses.compact.join("\n") }.to_json
|
72
70
|
end
|
73
71
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Slackbotsy
|
2
|
+
|
3
|
+
class Message < Hash
|
4
|
+
|
5
|
+
## convert message from a Hash obj to a Message obj
|
6
|
+
def initialize(caller, msg)
|
7
|
+
super()
|
8
|
+
self.update(msg)
|
9
|
+
@caller = caller # bot object
|
10
|
+
end
|
11
|
+
|
12
|
+
## call say without bot object
|
13
|
+
def say(text, options = {})
|
14
|
+
options[:channel] ||= self['channel_name'] # default to same channel as msg
|
15
|
+
@caller.say(text, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/slackbotsy/version.rb
CHANGED
data/lib/slackbotsy.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.0.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/slackbotsy.rb
|
82
82
|
- lib/slackbotsy/bot.rb
|
83
|
+
- lib/slackbotsy/message.rb
|
83
84
|
- lib/slackbotsy/version.rb
|
84
85
|
- slackbotsy.gemspec
|
85
86
|
homepage: https://github.com/rlister/slackbotsy
|