slacks 0.0.1 → 0.2.0
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 +4 -4
- data/README.md +16 -6
- data/lib/slacks/channel.rb +6 -6
- data/lib/slacks/connection.rb +19 -19
- data/lib/slacks/conversation.rb +3 -3
- data/lib/slacks/errors.rb +2 -0
- data/lib/slacks/listener.rb +9 -36
- data/lib/slacks/listener_collection.rb +11 -20
- data/lib/slacks/message.rb +7 -27
- data/lib/slacks/rtm_event.rb +8 -8
- data/lib/slacks/session.rb +23 -97
- data/lib/slacks/user.rb +4 -2
- data/lib/slacks/version.rb +1 -1
- data/lib/slacks.rb +0 -1
- data/slacks.gemspec +3 -0
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40d731ac92fa1fc207c6723ab3986302416c481f
|
4
|
+
data.tar.gz: 3e03fdfdd979b06b9103f4773f59225a0d8dde7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0360f432a06a1cfe599e8e246e87ce26e29f301574a3dc376f498c06a4c126cb6f6a4a1127af7001e37595a9756033665fc9df6433e3172156c07b84f6b0ab2
|
7
|
+
data.tar.gz: d5f46535abe6b9ce02298b41585fe8fe729bf355f910aa251d430d5b22449f4688e2ddf287dd1380ffa626b7d437a72745eb91efb39758d0819e1b0c2c66ab47
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# Slacks
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A library for communicating via Slack
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem
|
10
|
+
gem "slacks"
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -20,9 +18,19 @@ Or install it yourself as:
|
|
20
18
|
|
21
19
|
$ gem install slacks
|
22
20
|
|
21
|
+
|
22
|
+
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
require "slacks"
|
27
|
+
slack = Slacks::Connection.new("xoxb-0123456789-abcdefghijklmnopqrstuvwx")
|
28
|
+
slack.listen! do |message|
|
29
|
+
p message
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
|
26
34
|
|
27
35
|
## Development
|
28
36
|
|
@@ -30,12 +38,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
38
|
|
31
39
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
40
|
|
41
|
+
|
42
|
+
|
33
43
|
## Contributing
|
34
44
|
|
35
45
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slacks.
|
36
46
|
|
37
47
|
|
48
|
+
|
38
49
|
## License
|
39
50
|
|
40
51
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/lib/slacks/channel.rb
CHANGED
@@ -2,8 +2,8 @@ module Slacks
|
|
2
2
|
class Channel
|
3
3
|
attr_reader :id, :name, :type
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(slack, attributes={})
|
6
|
+
@slack = slack
|
7
7
|
@id = attributes["id"]
|
8
8
|
@name = attributes["name"]
|
9
9
|
@type = :channel
|
@@ -18,11 +18,11 @@ module Slacks
|
|
18
18
|
first_message = messages.shift
|
19
19
|
message_options = {}
|
20
20
|
message_options = messages.shift if messages.length == 1 && messages[0].is_a?(Hash)
|
21
|
-
|
21
|
+
slack.send_message(first_message, message_options.merge(channel: id))
|
22
22
|
|
23
23
|
messages.each do |message|
|
24
|
-
sleep message.length /
|
25
|
-
|
24
|
+
sleep message.length / slack.typing_speed
|
25
|
+
slack.send_message(message, channel: id)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
alias :say :reply
|
@@ -74,6 +74,6 @@ module Slacks
|
|
74
74
|
end
|
75
75
|
|
76
76
|
private
|
77
|
-
attr_reader :
|
77
|
+
attr_reader :slack
|
78
78
|
end
|
79
79
|
end
|
data/lib/slacks/connection.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
require "slacks/bot_user"
|
2
|
-
require "slacks/team"
|
3
2
|
require "slacks/channel"
|
4
|
-
require "slacks/guest_channel"
|
5
|
-
require "slacks/conversation"
|
6
3
|
require "slacks/driver"
|
4
|
+
require "slacks/errors"
|
5
|
+
require "slacks/guest_channel"
|
7
6
|
require "slacks/rtm_event"
|
8
|
-
require "slacks/
|
9
|
-
require "slacks/message"
|
7
|
+
require "slacks/team"
|
10
8
|
require "slacks/user"
|
11
|
-
require "slacks/errors"
|
12
9
|
require "faraday"
|
13
10
|
require "faraday/raise_errors"
|
14
11
|
|
15
12
|
module Slacks
|
16
13
|
class Connection
|
17
14
|
attr_reader :team, :bot, :token
|
15
|
+
attr_accessor :typing_speed
|
18
16
|
|
19
17
|
EVENT_MESSAGE = "message".freeze
|
20
18
|
EVENT_GROUP_JOINED = "group_joined".freeze
|
21
19
|
EVENT_USER_JOINED = "team_join".freeze
|
22
20
|
|
23
|
-
def initialize(
|
21
|
+
def initialize(token, options={})
|
22
|
+
@token = token
|
23
|
+
@typing_speed = options.fetch(:typing_speed, 100.0)
|
24
|
+
|
24
25
|
@user_ids_dm_ids = {}
|
25
26
|
@users_by_id = {}
|
26
27
|
@user_id_by_name = {}
|
@@ -28,9 +29,6 @@ module Slacks
|
|
28
29
|
@group_id_by_name = {}
|
29
30
|
@channels_by_id = {}
|
30
31
|
@channel_id_by_name = {}
|
31
|
-
|
32
|
-
@session = session
|
33
|
-
@token = token
|
34
32
|
end
|
35
33
|
|
36
34
|
|
@@ -48,6 +46,7 @@ module Slacks
|
|
48
46
|
:unfurl_links, :unfurl_media, :icon_url, :icon_emoji].member?(key) })
|
49
47
|
api("chat.postMessage", params)
|
50
48
|
end
|
49
|
+
alias :say :send_message
|
51
50
|
|
52
51
|
def add_reaction(emojis, message)
|
53
52
|
Array(emojis).each do |emoji|
|
@@ -60,7 +59,7 @@ module Slacks
|
|
60
59
|
|
61
60
|
|
62
61
|
|
63
|
-
def listen!
|
62
|
+
def listen!(callbacks)
|
64
63
|
response = api("rtm.start")
|
65
64
|
|
66
65
|
unless response["ok"]
|
@@ -70,6 +69,8 @@ module Slacks
|
|
70
69
|
|
71
70
|
store_context!(response)
|
72
71
|
|
72
|
+
callbacks.connected
|
73
|
+
|
73
74
|
client = Slacks::Driver.new
|
74
75
|
client.connect_to websocket_url
|
75
76
|
|
@@ -94,7 +95,7 @@ module Slacks
|
|
94
95
|
next if data["user"] == bot.id
|
95
96
|
# ...or to messages with no text
|
96
97
|
next if data["text"].nil? || data["text"].empty?
|
97
|
-
|
98
|
+
callbacks.message(data)
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
@@ -102,7 +103,7 @@ module Slacks
|
|
102
103
|
|
103
104
|
rescue EOFError
|
104
105
|
# Slack hung up on us, we'll ask for a new WebSocket URL and reconnect.
|
105
|
-
|
106
|
+
callbacks.error "Websocket Driver received EOF; reconnecting"
|
106
107
|
retry
|
107
108
|
end
|
108
109
|
|
@@ -119,23 +120,23 @@ module Slacks
|
|
119
120
|
when /^U/ then find_user(id)
|
120
121
|
when /^D/
|
121
122
|
user = find_user(get_user_id_for_dm(id))
|
122
|
-
Slacks::Channel.new
|
123
|
+
Slacks::Channel.new self, {
|
123
124
|
"id" => id,
|
124
125
|
"is_im" => true,
|
125
126
|
"name" => user.username }
|
126
127
|
when /^G/
|
127
|
-
Slacks::Channel.new
|
128
|
+
Slacks::Channel.new self, groups_by_id.fetch(id) do
|
128
129
|
raise ArgumentError, "Unable to find a group with the ID #{id.inspect}"
|
129
130
|
end
|
130
131
|
else
|
131
|
-
Slacks::Channel.new
|
132
|
+
Slacks::Channel.new self, channels_by_id.fetch(id) do
|
132
133
|
raise ArgumentError, "Unable to find a channel with the ID #{id.inspect}"
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|
136
137
|
|
137
138
|
def find_user(id)
|
138
|
-
Slacks::User.new
|
139
|
+
Slacks::User.new self, users_by_id.fetch(id) do
|
139
140
|
raise ArgumentError, "Unable to find a user with the ID #{id.inspect}"
|
140
141
|
end
|
141
142
|
end
|
@@ -157,8 +158,7 @@ module Slacks
|
|
157
158
|
|
158
159
|
|
159
160
|
private
|
160
|
-
attr_reader :
|
161
|
-
:user_ids_dm_ids,
|
161
|
+
attr_reader :user_ids_dm_ids,
|
162
162
|
:users_by_id,
|
163
163
|
:user_id_by_name,
|
164
164
|
:groups_by_id,
|
data/lib/slacks/conversation.rb
CHANGED
@@ -12,8 +12,8 @@ module Slacks
|
|
12
12
|
@listeners = ThreadSafe::Array.new
|
13
13
|
end
|
14
14
|
|
15
|
-
def listen_for(
|
16
|
-
session.listen_for(
|
15
|
+
def listen_for(*args, &block)
|
16
|
+
session.listen_for(*args, &block).tap do |listener|
|
17
17
|
listener.conversation = self
|
18
18
|
listeners.push listener
|
19
19
|
end
|
@@ -29,7 +29,7 @@ module Slacks
|
|
29
29
|
alias :say :reply
|
30
30
|
|
31
31
|
def ask(question, expect: nil)
|
32
|
-
listen_for(expect) do |e|
|
32
|
+
listen_for(*Array(expect)) do |e|
|
33
33
|
e.stop_listening!
|
34
34
|
yield e
|
35
35
|
end
|
data/lib/slacks/errors.rb
CHANGED
data/lib/slacks/listener.rb
CHANGED
@@ -1,44 +1,17 @@
|
|
1
|
+
require "attentive/listener"
|
2
|
+
|
1
3
|
module Slacks
|
2
|
-
class Listener
|
3
|
-
attr_reader :matcher, :flags
|
4
|
+
class Listener < Attentive::Listener
|
4
5
|
attr_accessor :conversation
|
5
6
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
# raise ArgumentError, "#{flag.inspect} is not a recognized flag"
|
10
|
-
# end
|
11
|
-
# end
|
12
|
-
|
13
|
-
@listeners = listeners
|
14
|
-
@matcher = matcher.freeze
|
15
|
-
@flags = flags.sort.freeze
|
16
|
-
@direct = direct
|
17
|
-
@callback = callback
|
18
|
-
end
|
19
|
-
|
20
|
-
def match(message)
|
21
|
-
matcher.match message.to_s(flags)
|
22
|
-
end
|
23
|
-
|
24
|
-
def direct?
|
25
|
-
@direct
|
26
|
-
end
|
27
|
-
|
28
|
-
def indirect?
|
29
|
-
!direct?
|
30
|
-
end
|
31
|
-
|
32
|
-
def stop_listening!
|
33
|
-
listeners.delete self
|
34
|
-
self
|
35
|
-
end
|
7
|
+
def matches_context?(message)
|
8
|
+
contexts = message.contexts.dup
|
9
|
+
contexts << :conversation if conversation && conversation.includes?(message)
|
36
10
|
|
37
|
-
|
38
|
-
@
|
11
|
+
return false unless contexts.superset? @required_contexts
|
12
|
+
return false unless contexts.disjoint? @prohibited_contexts
|
13
|
+
true
|
39
14
|
end
|
40
15
|
|
41
|
-
private
|
42
|
-
attr_reader :listeners
|
43
16
|
end
|
44
17
|
end
|
@@ -1,31 +1,22 @@
|
|
1
|
-
require "
|
1
|
+
require "attentive/listener_collection"
|
2
|
+
require "slacks/listener"
|
2
3
|
|
3
4
|
module Slacks
|
4
|
-
class ListenerCollection
|
5
|
+
class ListenerCollection < Attentive::ListenerCollection
|
5
6
|
|
6
|
-
def
|
7
|
-
|
7
|
+
def overhear(*args, &block)
|
8
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
9
|
+
options[:context] = { in: :any }
|
10
|
+
listen_for(*args, options, &block)
|
8
11
|
end
|
9
12
|
|
10
|
-
def listen_for(
|
11
|
-
|
12
|
-
@listeners.push listener
|
13
|
-
end
|
14
|
-
end
|
13
|
+
def listen_for(*args, &block)
|
14
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
@listeners.push listener
|
16
|
+
Slacks::Listener.new(self, args, options, block).tap do |listener|
|
17
|
+
push listener
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
def each(&block)
|
23
|
-
@listeners.each(&block)
|
24
|
-
end
|
25
|
-
|
26
|
-
def delete(listener)
|
27
|
-
@listeners.delete listener
|
28
|
-
end
|
29
|
-
|
30
21
|
end
|
31
22
|
end
|
data/lib/slacks/message.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
require "attentive/message"
|
2
|
+
|
1
3
|
module Slacks
|
2
|
-
class Message
|
4
|
+
class Message < ::Attentive::Message
|
3
5
|
|
4
|
-
def initialize(session, data)
|
6
|
+
def initialize(session, data, params={})
|
5
7
|
@session = session
|
6
8
|
@data = data
|
7
|
-
|
8
|
-
|
9
|
-
end
|
9
|
+
super data["text"], params
|
10
|
+
contexts << :conversation if channel.direct_message?
|
10
11
|
end
|
11
12
|
|
12
13
|
|
@@ -28,19 +29,6 @@ module Slacks
|
|
28
29
|
data.fetch("subtype", "message")
|
29
30
|
end
|
30
31
|
|
31
|
-
def text
|
32
|
-
return @text if defined?(@text)
|
33
|
-
@text = self.class.normalize(data["text"])
|
34
|
-
end
|
35
|
-
alias :to_str :text
|
36
|
-
|
37
|
-
def to_s(flags=[])
|
38
|
-
processed_text[flags]
|
39
|
-
end
|
40
|
-
|
41
|
-
def inspect
|
42
|
-
"#{text.inspect} (from: #{sender}, channel: #{channel})"
|
43
|
-
end
|
44
32
|
|
45
33
|
def add_reaction(emoji)
|
46
34
|
session.slack.add_reaction(emoji, self)
|
@@ -57,15 +45,7 @@ module Slacks
|
|
57
45
|
super
|
58
46
|
end
|
59
47
|
|
60
|
-
|
61
|
-
def self.normalize(text)
|
62
|
-
text
|
63
|
-
.gsub(/[“”]/, "\"")
|
64
|
-
.gsub(/[‘’]/, "'")
|
65
|
-
.strip
|
66
|
-
end
|
67
|
-
|
68
48
|
private
|
69
|
-
attr_reader :session, :data
|
49
|
+
attr_reader :session, :data
|
70
50
|
end
|
71
51
|
end
|
data/lib/slacks/rtm_event.rb
CHANGED
@@ -2,17 +2,17 @@ require "slacks/event"
|
|
2
2
|
|
3
3
|
module Slacks
|
4
4
|
class RtmEvent < Event
|
5
|
-
attr_reader :match
|
5
|
+
attr_reader :match
|
6
6
|
|
7
|
-
def initialize(session
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
7
|
+
def initialize(session, match)
|
8
|
+
@match = match
|
9
|
+
@listener = match.listener
|
10
|
+
message = match.message
|
11
|
+
super(session: session, message: message, channel: message.channel, sender: message.sender)
|
12
12
|
end
|
13
13
|
|
14
14
|
def matched?(key)
|
15
|
-
match
|
15
|
+
match.matched?(key)
|
16
16
|
end
|
17
17
|
|
18
18
|
def stop_listening!
|
@@ -20,7 +20,7 @@ module Slacks
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def react(emoji)
|
23
|
-
|
23
|
+
message.add_reaction(emoji)
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
data/lib/slacks/session.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require "slacks/connection"
|
2
2
|
require "slacks/listener_collection"
|
3
|
+
require "slacks/message"
|
4
|
+
require "attentive"
|
3
5
|
|
4
6
|
module Slacks
|
5
7
|
class Session
|
6
|
-
|
8
|
+
include Attentive
|
9
|
+
|
10
|
+
attr_reader :slack
|
7
11
|
|
8
12
|
def initialize(token, &block)
|
9
|
-
@
|
10
|
-
@token = token
|
11
|
-
@listeners = Slacks::ListenerCollection.new
|
13
|
+
@slack = Slacks::Connection.new(token)
|
12
14
|
|
13
15
|
if block_given?
|
14
16
|
listeners.instance_eval(&block)
|
@@ -16,44 +18,30 @@ module Slacks
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
listeners
|
21
|
-
end
|
22
|
-
|
23
|
-
def overhear(matcher, flags=[], &block)
|
24
|
-
listeners.overhear(matcher, flags, &block)
|
21
|
+
def listeners
|
22
|
+
@listeners ||= Slacks::ListenerCollection.new
|
25
23
|
end
|
26
24
|
|
27
|
-
def start!
|
28
|
-
@slack = Slacks::Connection.new(self, token)
|
29
25
|
|
30
|
-
slack.listen! do |message|
|
31
|
-
process_message(message)
|
32
|
-
end
|
33
|
-
end
|
34
26
|
|
35
|
-
def
|
36
|
-
|
37
|
-
puts "\e[33m[slack:error] #{message}\e[0m"
|
27
|
+
def start!
|
28
|
+
slack.listen!(self)
|
38
29
|
end
|
39
30
|
|
40
|
-
def
|
41
|
-
|
31
|
+
def connected
|
32
|
+
Attentive.invocations = [slack.bot.name, slack.bot.to_s]
|
42
33
|
end
|
43
34
|
|
44
|
-
def
|
45
|
-
respond_to? :"_apply_#{flag}", true
|
35
|
+
def error(error_message)
|
46
36
|
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
def process_message(data)
|
38
|
+
def message(data)
|
51
39
|
|
52
40
|
# Don't respond to things that another bot said
|
53
41
|
return if data.fetch("subtype", "message") == "bot_message"
|
54
42
|
|
55
43
|
# Normalize mentions of users
|
56
|
-
data["text"].gsub!(/<@U[^|]+\|([^>]*)>/,
|
44
|
+
data["text"].gsub!(/<@U[^|]+\|([^>]*)>/, %q{@\1})
|
57
45
|
|
58
46
|
# Normalize mentions of channels
|
59
47
|
data["text"].gsub!(/<[@#]?([UC][^>]+)>/) do |match|
|
@@ -65,82 +53,20 @@ module Slacks
|
|
65
53
|
end
|
66
54
|
|
67
55
|
message = Slacks::Message.new(self, data)
|
56
|
+
hear(message).each do |match|
|
68
57
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
# To trigger a direct listener, the but must be directly
|
76
|
-
# spoken to: as when the bot is mentioned or it is in
|
77
|
-
# a conversation with someone.
|
78
|
-
#
|
79
|
-
# An indirect listener is triggered in any context
|
80
|
-
# when it matches.
|
81
|
-
#
|
82
|
-
# We can ignore any listener that definitely doesn't
|
83
|
-
# meet these criteria.
|
84
|
-
next unless listener.indirect? or direct_mention or listener.conversation
|
85
|
-
|
86
|
-
message = Slacks::Message.new(self, data)
|
87
|
-
|
88
|
-
# Does the message match one of our listeners?
|
89
|
-
match_data = listener.match message
|
90
|
-
next unless match_data
|
91
|
-
|
92
|
-
# TODO: Want event.message to be the processed text
|
93
|
-
event = Slacks::RtmEvent.new(
|
94
|
-
session: self,
|
95
|
-
message: message,
|
96
|
-
match_data: match_data,
|
97
|
-
listener: listener)
|
98
|
-
|
99
|
-
# Skip listeners if they are not part of this conversation
|
100
|
-
next unless listener.indirect? or direct_mention or listener.conversation.includes?(event)
|
101
|
-
|
102
|
-
invoke! listener, event
|
58
|
+
event = Slacks::RtmEvent.new(self, match)
|
59
|
+
invoke! match.listener, event
|
60
|
+
|
61
|
+
# Invoke only one listener per message
|
62
|
+
return
|
103
63
|
end
|
104
|
-
# rescue Exception
|
105
|
-
# # TODO
|
106
|
-
# # Houston.report_exception $!
|
107
|
-
# puts "\e[31m[slack:exception] (#{$!.class}) #{$!.message}\n #{$!.backtrace.join("\n ")}\e[0m"
|
108
64
|
end
|
109
65
|
|
110
|
-
|
111
|
-
# # TODO
|
112
|
-
# puts "\e[35m[slack:hear:#{event.message_object.type}] #{event.message_object.inspect}\e[0m"
|
66
|
+
protected
|
113
67
|
|
68
|
+
def invoke!(listener, event)
|
114
69
|
listener.call(event)
|
115
|
-
# Thread.new do
|
116
|
-
# begin
|
117
|
-
# @callback.call(e)
|
118
|
-
# rescue Exception # rescues StandardError by default; but we want to rescue and report all errors
|
119
|
-
# # TODO
|
120
|
-
# # Houston.report_exception $!, parameters: {channel: e.channel, message: e.message, sender: e.sender}
|
121
|
-
# puts "\e[31m[slack:exception] (#{$!.class}) #{$!.message}\n #{$!.backtrace.join("\n ")}\e[0m"
|
122
|
-
# e.reply "An error occurred when I was trying to answer you"
|
123
|
-
# ensure
|
124
|
-
# ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord)
|
125
|
-
# end
|
126
|
-
# end
|
127
|
-
end
|
128
|
-
|
129
|
-
def _apply_downcase(text)
|
130
|
-
text.downcase
|
131
|
-
end
|
132
|
-
|
133
|
-
def _apply_no_punctuation(text)
|
134
|
-
# Need to leave @ and # in @mentions and #channels
|
135
|
-
text.gsub(/[^\w\s@#]/, "")
|
136
|
-
end
|
137
|
-
|
138
|
-
def _apply_no_mentions(text)
|
139
|
-
text.gsub(/(?:^|\W+)#{slack.bot}\b/, "")
|
140
|
-
end
|
141
|
-
|
142
|
-
def _apply_no_emoji(text)
|
143
|
-
text.gsub(/(?::[^:]+:)/, "")
|
144
70
|
end
|
145
71
|
|
146
72
|
end
|
data/lib/slacks/user.rb
CHANGED
@@ -2,8 +2,8 @@ module Slacks
|
|
2
2
|
class User
|
3
3
|
attr_reader :id, :username, :email, :first_name, :last_name
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(slack, attributes={})
|
6
|
+
@slack = slack
|
7
7
|
|
8
8
|
profile = attributes["profile"]
|
9
9
|
@id = attributes["id"]
|
@@ -25,5 +25,7 @@ module Slacks
|
|
25
25
|
"@#{username}"
|
26
26
|
end
|
27
27
|
|
28
|
+
private
|
29
|
+
attr_reader :slack
|
28
30
|
end
|
29
31
|
end
|
data/lib/slacks/version.rb
CHANGED
data/lib/slacks.rb
CHANGED
data/slacks.gemspec
CHANGED
@@ -24,9 +24,12 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "faraday"
|
25
25
|
spec.add_dependency "faraday-raise-errors"
|
26
26
|
spec.add_dependency "thread_safe"
|
27
|
+
spec.add_dependency "attentive"
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.10"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
31
32
|
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "minitest-reporters"
|
34
|
+
spec.add_development_dependency "minitest-reporters-turn_reporter"
|
32
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-driver
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: attentive
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +150,34 @@ dependencies:
|
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: minitest-reporters
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: minitest-reporters-turn_reporter
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
139
181
|
description:
|
140
182
|
email:
|
141
183
|
- bob.lailfamily@gmail.com
|