slackbotsy 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31f24d009fd5353c55c4770a11199e72024d66a2
4
- data.tar.gz: 33499607ad383af24785d7ebf5692c095bb64ca6
3
+ metadata.gz: d7dc66aaddae9bf1414f43fcc6cb8b6d3fd760cd
4
+ data.tar.gz: 1d9104a7ac7f98daa480faaa81d1b9b3e5841c77
5
5
  SHA512:
6
- metadata.gz: 4434d540a6c80966dfe3a17ca4bf800c6081955f2a629f5c7bcc979e65334aa7c7c1c63112e6b4e98eb982d1cdad698213f964fa9e024ffb73fe92a2af2cea3b
7
- data.tar.gz: 8b244f0a94af60e551c9fa227d29e330cc17891e9bc1ac62d6b7ae9c0c0e0a745a2f5ee19984dac2646be83a8f1df21b0530736969589ebe4f90701adee7b74a
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
- ## Usage
20
-
21
- TODO
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
+ ```
@@ -7,11 +7,11 @@ module Slackbotsy
7
7
 
8
8
  class Bot
9
9
 
10
- def initialize(options, &block)
10
+ def initialize(options)
11
11
  @options = options
12
12
  @regexes = {}
13
13
  setup_incoming_webhook # http connection for async replies
14
- instance_eval &block if block # eval any hear statements in block
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
- proc.call(msg, mdata)
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
@@ -1,3 +1,3 @@
1
1
  module Slackbotsy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/slackbotsy.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "slackbotsy/version"
2
2
  require "slackbotsy/bot"
3
+ require "slackbotsy/message"
3
4
 
4
5
  module Slackbotsy
5
6
 
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.2
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-02-18 00:00:00.000000000 Z
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