slack-bot-manager 0.1.0pre2 → 0.1.0pre3
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/.gitignore +2 -1
- data/.gitmodules +0 -9
- data/.rubocop_todo.yml +13 -8
- data/CHANGELOG.md +1 -1
- data/README.md +42 -15
- data/examples/botspotting/Gemfile +9 -0
- data/examples/botspotting/README.md +29 -0
- data/examples/botspotting/bot.rb +23 -0
- data/examples/botspotting/sample.env +3 -0
- data/examples/botspotting/slack.rb +35 -0
- data/examples/dm-bot/dm-bot.rb +16 -17
- data/examples/downforeveryone-bot/Gemfile +10 -0
- data/examples/downforeveryone-bot/README.md +23 -0
- data/examples/downforeveryone-bot/bot.rb +24 -0
- data/examples/downforeveryone-bot/lib/slack.rb +39 -0
- data/examples/downforeveryone-bot/lib/status.rb +45 -0
- data/examples/downforeveryone-bot/sample.env +3 -0
- data/examples/emoji-art-bot/Gemfile +9 -0
- data/examples/emoji-art-bot/README.md +43 -0
- data/examples/emoji-art-bot/bot.rb +24 -0
- data/examples/emoji-art-bot/lib/emoji.rb +37 -0
- data/examples/emoji-art-bot/lib/json/emoji.json +1305 -0
- data/examples/emoji-art-bot/lib/slack.rb +58 -0
- data/examples/emoji-art-bot/sample.env +2 -0
- data/lib/slack-bot-manager/client/base.rb +22 -5
- data/lib/slack-bot-manager/config.rb +46 -18
- data/lib/slack-bot-manager/manager/base.rb +3 -4
- data/lib/slack-bot-manager/{manager/storage → storage}/dalli.rb +0 -0
- data/lib/slack-bot-manager/{manager/storage → storage}/redis.rb +0 -0
- data/lib/slack-bot-manager/storage.rb +6 -0
- data/lib/slack-bot-manager/version.rb +1 -1
- data/lib/slack-bot-manager.rb +1 -1
- data/spec/fixtures/slack-bot-manager/web/rtm_start.yml +176 -3
- data/spec/integration/client_spec.rb +6 -2
- data/spec/integration/manager_spec.rb +1 -1
- data/spec/slack-bot-manager/client/base_spec.rb +34 -11
- metadata +22 -5
- data/examples/dm-bot/Gemfile.lock +0 -40
- data/lib/slack-bot-manager/manager/storage.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26bbd6ac7e458ce8eb9c13d0240c1c12c3e20a4c
|
4
|
+
data.tar.gz: 4aca7114fa130ed10f3c8e24aaf3fc071eb2a0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e806d0b5f35997dfc9e2380e32eee0202c4bb60594baab464ba87221dc0a861f6bd0ce1cf189abd5b7be173a3a41911d37d590f0f9acc298600be2f07de58b67
|
7
|
+
data.tar.gz: 8d766dd7907f032619a6673e8f4aaef2f5bc2bbdf45735da7fed18cded5fa2fa8209157d1b11fd17e888062f6d06a5703f1bdd57cef1c7a3e14e8c0cf1e3bf6d
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
@@ -1,9 +0,0 @@
|
|
1
|
-
[submodule "examples/emoji-art-bot"]
|
2
|
-
path = examples/emoji-art-bot
|
3
|
-
url = git@github.com:goosey/emoji-art-bot.git
|
4
|
-
[submodule "examples/downforeveryone-bot"]
|
5
|
-
path = examples/downforeveryone-bot
|
6
|
-
url = https://github.com/goosey/downforeveryone-bot
|
7
|
-
[submodule "examples/botspotting"]
|
8
|
-
path = examples/botspotting
|
9
|
-
url = git@github.com:goosey/botspotting.git
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-02-07
|
3
|
+
# on 2016-02-07 14:23:26 -0500 using RuboCop version 0.36.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -15,22 +15,27 @@ Lint/UselessAssignment:
|
|
15
15
|
Metrics/AbcSize:
|
16
16
|
Max: 90
|
17
17
|
|
18
|
+
# Offense count: 1
|
19
|
+
# Configuration parameters: CountComments.
|
20
|
+
Metrics/ClassLength:
|
21
|
+
Max: 108
|
22
|
+
|
18
23
|
# Offense count: 2
|
19
24
|
Metrics/CyclomaticComplexity:
|
20
25
|
Max: 13
|
21
26
|
|
22
|
-
# Offense count:
|
27
|
+
# Offense count: 17
|
23
28
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
24
29
|
# URISchemes: http, https
|
25
30
|
Metrics/LineLength:
|
26
31
|
Max: 120
|
27
32
|
|
28
|
-
# Offense count:
|
33
|
+
# Offense count: 9
|
29
34
|
# Configuration parameters: CountComments.
|
30
35
|
Metrics/MethodLength:
|
31
36
|
Max: 43
|
32
37
|
|
33
|
-
# Offense count:
|
38
|
+
# Offense count: 2
|
34
39
|
# Configuration parameters: CountComments.
|
35
40
|
Metrics/ModuleLength:
|
36
41
|
Max: 113
|
@@ -52,10 +57,10 @@ Style/Documentation:
|
|
52
57
|
- 'lib/slack-bot-manager/logger.rb'
|
53
58
|
- 'lib/slack-bot-manager/manager/base.rb'
|
54
59
|
- 'lib/slack-bot-manager/manager/connection.rb'
|
55
|
-
- 'lib/slack-bot-manager/manager/storage.rb'
|
56
|
-
- 'lib/slack-bot-manager/manager/storage/dalli.rb'
|
57
|
-
- 'lib/slack-bot-manager/manager/storage/redis.rb'
|
58
60
|
- 'lib/slack-bot-manager/manager/tokens.rb'
|
61
|
+
- 'lib/slack-bot-manager/storage.rb'
|
62
|
+
- 'lib/slack-bot-manager/storage/dalli.rb'
|
63
|
+
- 'lib/slack-bot-manager/storage/redis.rb'
|
59
64
|
|
60
65
|
# Offense count: 1
|
61
66
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
@@ -68,7 +73,7 @@ Style/ModuleFunction:
|
|
68
73
|
Exclude:
|
69
74
|
- 'lib/slack-bot-manager/config.rb'
|
70
75
|
|
71
|
-
# Offense count:
|
76
|
+
# Offense count: 4
|
72
77
|
# Cop supports --auto-correct.
|
73
78
|
Style/RedundantSelf:
|
74
79
|
Exclude:
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -69,7 +69,7 @@ methods | description
|
|
69
69
|
|
70
70
|
### Token Management Methods
|
71
71
|
|
72
|
-
Tokens are managed using
|
72
|
+
Tokens are managed using the defined storage adapter (Redis or Dalli). SlackBotManager will manage and monitor these keys for additions, updates, and removals. New connections will be added into the key `teams_key`, like so:
|
73
73
|
|
74
74
|
```
|
75
75
|
botmanager = SlackBotManager::Manager.new
|
@@ -99,6 +99,20 @@ variable | description
|
|
99
99
|
`id` | Team's Slack ID (ex. `T123ABC`) _(set after successful connection)_
|
100
100
|
`token` | Team's Slack access token (ex. `xoxb-123abc456def`)
|
101
101
|
`status` | Known connection status. (`connected`, `disconnected`, `rate_limited`, `token_revoked`)
|
102
|
+
`storage` | Storage adapter from Config.
|
103
|
+
|
104
|
+
|
105
|
+
### Client Methods
|
106
|
+
|
107
|
+
These are some common client methods you can use to manage incoming events and interact with Slack.
|
108
|
+
|
109
|
+
methods | description
|
110
|
+
-----------------------------|----------------------------------------------------------------------------------------
|
111
|
+
`message(channel, text, {})` | Send a message to channel. Handles both simple RTM message or chat.postMessage if additional options are present.
|
112
|
+
`typing(channel, {})` | Send typing notification.
|
113
|
+
`ping({})` | Send a manual ping to Slack.
|
114
|
+
`on(event, &block)` | Add an event listener. (Same as extending with `on_*` methods.)
|
115
|
+
`off(event, &block)` | Remove an event listener. (Does not remove defined `on_*` methods.)
|
102
116
|
|
103
117
|
|
104
118
|
### Adding Event Listeners
|
@@ -115,7 +129,7 @@ module SlackBotManager
|
|
115
129
|
end
|
116
130
|
|
117
131
|
def on_team_join(data)
|
118
|
-
|
132
|
+
message(data['channel'], "Welcome: %s" % data['user']['username'])
|
119
133
|
end
|
120
134
|
end
|
121
135
|
end
|
@@ -127,14 +141,11 @@ end
|
|
127
141
|
|
128
142
|
## Configuration
|
129
143
|
|
130
|
-
###
|
144
|
+
### Global configuration options
|
131
145
|
|
132
146
|
setting | description
|
133
147
|
------------------|-----------------------------------------------------------------------------------
|
134
|
-
`
|
135
|
-
`teams_key` | Redis key name for where teams' tokens are stored. _(default: tokens:teams)_
|
136
|
-
`check_interval` | Interval (in seconds) for checking connections and tokens status. _(default: 5)_
|
137
|
-
`storage_method` | Token storage method. _(default: nil)_
|
148
|
+
`storage_adapter` | Token storage method. _(default: nil)_
|
138
149
|
`storage_options` | Token storage method options. _(default: {})_
|
139
150
|
`logger` | Define the logger to use. _(default: Rails.logger or ::Logger.new(STDOUT))_
|
140
151
|
`log_level` | Explicity define the logger level. _(default: ::Logger::WARN)_
|
@@ -142,9 +153,29 @@ setting | description
|
|
142
153
|
|
143
154
|
You can define these configuration options as:
|
144
155
|
|
156
|
+
```
|
157
|
+
SlackBotManager.configure do |config|
|
158
|
+
config.storage_adapter = SlackBotManager::Storage::Redis
|
159
|
+
config.storage_options = {host: '0.0.0.0', port: 6379}
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
163
|
+
### Manager configuration options
|
164
|
+
|
165
|
+
Manager configuration options include the global options (`storage_adapter`, `storage_options`, `logger`, `log_level`, & `verbose`), in addition to:
|
166
|
+
|
167
|
+
|
168
|
+
setting | description
|
169
|
+
------------------|-----------------------------------------------------------------------------------
|
170
|
+
`tokens_key` | Redis key name for where tokens' status are stored. _(default: tokens:statuses)_
|
171
|
+
`teams_key` | Redis key name for where teams' tokens are stored. _(default: tokens:teams)_
|
172
|
+
`check_interval` | Interval (in seconds) for checking connections and tokens status. _(default: 5)_
|
173
|
+
|
174
|
+
You can define these configuration options as:
|
175
|
+
|
145
176
|
```
|
146
177
|
SlackBotManager::Manager.configure do |config|
|
147
|
-
config.
|
178
|
+
config.storage_adapter = SlackBotManager::Storage::Redis
|
148
179
|
config.storage_options = {host: '0.0.0.0', port: 6379}
|
149
180
|
config.check_interval = 10 # in seconds
|
150
181
|
end
|
@@ -153,24 +184,20 @@ end
|
|
153
184
|
You can additionally send an existing storage method as the `storage_option`, such as:
|
154
185
|
|
155
186
|
```
|
187
|
+
$redis = Redis.new
|
156
188
|
SlackBotManager::Manager.configure do |config|
|
157
|
-
config.storage_options = $redis
|
189
|
+
config.storage_options = $redis
|
158
190
|
end
|
159
191
|
```
|
160
192
|
|
161
193
|
### Client configuration options
|
162
194
|
|
163
|
-
|
164
|
-
------------------|-----------------------------------------------------------------------------------
|
165
|
-
`logger` | Define the logger to use. _(default: Rails.logger or ::Logger.new(STDOUT))_
|
166
|
-
`log_level` | Explicity define the logger level. _(default: ::Logger::WARN)_
|
167
|
-
`verbose` | When true, set `log_level` to ::Logger::DEBUG. _(default: false)_
|
195
|
+
Client configuration options include the global options (`storage_adapter`, `storage_options`, `logger`, `log_level`, & `verbose`)
|
168
196
|
|
169
197
|
You can define these configuration options as:
|
170
198
|
|
171
199
|
```
|
172
200
|
SlackBotManager::Client.configure do |config|
|
173
|
-
config.check_interval = 10 # in seconds
|
174
201
|
config.log_level = ::Logger::INFO
|
175
202
|
end
|
176
203
|
```
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# botspotting
|
2
|
+
|
3
|
+
emails you (or just hits a webhook endpoint) when a new bot is added to your team
|
4
|
+
|
5
|
+
an example bot using [slack-bot-manager](https://github.com/betaworks/slack-bot-manager) and [dexter](https://rundexter.com/)
|
6
|
+
|
7
|
+
slack-bot-manager depends on `redis` and `slack-ruby-client`
|
8
|
+
|
9
|
+
# setup
|
10
|
+
|
11
|
+
1. make your Dexter app (see below), and get the webhook URL
|
12
|
+
2. `touch .env` and then add your Slackbot token and Dexter webhook URL to `.env`
|
13
|
+
3. `ruby bot.rb`
|
14
|
+
|
15
|
+
# making a dexter app
|
16
|
+
|
17
|
+
you can either build a dexter app from scratch for this or [use one we pre-built](https://rundexter.com/app/botspotting)
|
18
|
+
|
19
|
+
1. [sign up for Dexter](https://rundexter.com/signup)
|
20
|
+
2. in the top right, hit "New App" and name and describe the app 
|
21
|
+
3. drag the "Webhook" trigger from the left and on to the canvas. click on it and, on the right, add two new variables- name them "message" and "subject" 
|
22
|
+
4. back on the left, go to "Modules" and add a module- we're using Dexter Emailer, but you could use Dexter SMS, Twitter Tweeter, or anything else that takes text input
|
23
|
+
5. click on your new module and hit "Configure", and drag the "message" and "subject" variables from the Webhook to the Module. for the email module, that looks like this: 
|
24
|
+
6. for the other inputs, you can either choose to prompt the user (we use this for the To field) or enter it manually. for Reply To, HTML Body, CC, and BCC, we choose to enter it manually but leave it blank
|
25
|
+
7. click Use App in the upper right to configure the app and get your webhook URL
|
26
|
+
|
27
|
+
# credit
|
28
|
+
|
29
|
+
created by [Alex Balwdin](https://github.com/goosey)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Initialize
|
2
|
+
require 'dotenv'
|
3
|
+
Dotenv.load
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
require './slack.rb'
|
9
|
+
|
10
|
+
APP_ENV = ENV['APP_ENV'] if !defined?(APP_ENV) && ENV['APP_ENV']
|
11
|
+
APP_ENV = 'development' if !defined?(APP_ENV)
|
12
|
+
|
13
|
+
Bundler.require(:default, APP_ENV.to_sym)
|
14
|
+
|
15
|
+
# Create bot manager
|
16
|
+
botmanager = SlackBotManager::Manager.new
|
17
|
+
|
18
|
+
# Add Slack token
|
19
|
+
botmanager.add_token(ENV['SLACK_TOKEN'])
|
20
|
+
|
21
|
+
# Start manager
|
22
|
+
botmanager.start
|
23
|
+
botmanager.monitor
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SlackBotManager
|
6
|
+
module Commands
|
7
|
+
|
8
|
+
attr_accessor :team_name, :team_domain
|
9
|
+
|
10
|
+
def on_hello(data)
|
11
|
+
debug(data)
|
12
|
+
@team_name = self.client_team['name']
|
13
|
+
@team_domain = self.client_team['domain']
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_bot_added(data)
|
17
|
+
return if data['bot']['deleted'] == true
|
18
|
+
|
19
|
+
subject = "someone added a bot to your team #{self.team_name}"
|
20
|
+
message = "someone added the bot #{data['bot']['name']} to #{self.team_name}. \n
|
21
|
+
find out more at https://#{self.team_domain}.slack.com/apps/manage \n
|
22
|
+
[sent by botspotting]"
|
23
|
+
|
24
|
+
# Send to Dexter webhook
|
25
|
+
uri = URI(ENV['DEXTER_WEBHOOK'])
|
26
|
+
req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
|
27
|
+
req.body = {message: message, subject: subject}.to_json
|
28
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
|
29
|
+
http.request(req)
|
30
|
+
end
|
31
|
+
|
32
|
+
info(res.body)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/examples/dm-bot/dm-bot.rb
CHANGED
@@ -23,9 +23,8 @@ require 'bundler/setup'
|
|
23
23
|
Bundler.require
|
24
24
|
|
25
25
|
# Use Redis and configure slack-bot-manager
|
26
|
-
$redis = Redis.new
|
27
26
|
SlackBotManager.configure do |config|
|
28
|
-
config.storage_options =
|
27
|
+
config.storage_options = Redis.new # Set entire instance as option
|
29
28
|
end
|
30
29
|
|
31
30
|
# Extend commands to handle what we want done
|
@@ -38,38 +37,38 @@ module SlackBotManager
|
|
38
37
|
|
39
38
|
# Get user info
|
40
39
|
user_key = ['users', self.id, data['user']].join(':')
|
41
|
-
|
42
|
-
unless
|
40
|
+
storage.connection.del user_key
|
41
|
+
unless storage.connection.exists user_key
|
43
42
|
# Get user info from Slack
|
44
43
|
user_info = self.connection.web_client.users_info(user: data['user'])['user']
|
45
44
|
|
46
45
|
# Store the basics into redis for quicker lookups
|
47
|
-
|
46
|
+
storage.connection.hmset user_key, *{ id: user_info['id'], name: user_info['name'], real_name: user_info['real_name'], is_bot: user_info['is_bot'] ? 1 : 0 }.flatten
|
48
47
|
# Expire this redis key weekly so that we do regular updates
|
49
|
-
|
48
|
+
storage.connection.expire user_key, 604800 # 1 week in seconds
|
50
49
|
end
|
51
|
-
user_info =
|
50
|
+
user_info = storage.connection.hgetall user_key
|
52
51
|
|
53
52
|
return if [1,'1','true'].include?(user_info['is_bot'])
|
54
53
|
|
55
54
|
# Get IM info, send hello message if first time
|
56
55
|
im_key = ['ims', self.id, data['channel']].join(':')
|
57
|
-
|
58
|
-
unless
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
storage.connection.del im_key
|
57
|
+
unless storage.connection.exists im_key
|
58
|
+
storage.connection.hmset im_key, *{ id: data['channel'], user: user_info['id'], started: Time.now.to_i, messages_sent: 0, messages_received: 0 }.flatten
|
59
|
+
send_message(data['channel'], "Hello there <@#{user_info['id']}>! I'm happy to listen to what you have to say. :simple_smile:")
|
60
|
+
storage.connection.hincrby im_key, 'messages_sent', 1
|
62
61
|
end
|
63
|
-
im_info =
|
62
|
+
im_info = storage.connection.hgetall im_key
|
64
63
|
|
65
64
|
# Increment message count
|
66
|
-
|
65
|
+
storage.connection.hincrby im_key, 'messages_received', 1
|
67
66
|
|
68
67
|
# Parse message contents
|
69
|
-
|
68
|
+
msg = 'If i was smarter, I would respond with something witty.'
|
70
69
|
|
71
|
-
|
72
|
-
|
70
|
+
send_message(data['channel'], msg)
|
71
|
+
storage.connection.hincrby im_key, 'messages_sent', 1
|
73
72
|
end
|
74
73
|
|
75
74
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# "down for everyone or just me" bot
|
2
|
+
|
3
|
+
an example bot using [slack-bot-manager](https://github.com/betaworks/slack-bot-manager)
|
4
|
+
|
5
|
+
slack-bot-manager depends on `redis` and `slack-ruby-client`
|
6
|
+
|
7
|
+
# setup
|
8
|
+
|
9
|
+
1. get a free key for the [Bing Web-Only Search API](https://datamarket.azure.com/dataset/bing/searchweb)
|
10
|
+
2. your key will be under "My Account > Account Keys"
|
11
|
+
3. `touch .env` and then add the Bing key and your Slackbot token to `.env`
|
12
|
+
4. `ruby bot.rb`
|
13
|
+
|
14
|
+
# usage
|
15
|
+
|
16
|
+
`is [site] up` or `is [site] down`
|
17
|
+
|
18
|
+
site can be a url (like `google.com`) or a word (like `facebook`). using a word can be more time intensive and potentially less accurate, since it queries the [DuckDuckGo API
|
19
|
+
](https://api.duckduckgo.com/api) and Bing as a backup.
|
20
|
+
|
21
|
+
# credit
|
22
|
+
|
23
|
+
created by [Alex Baldwin](https://github.com/goosey)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Initialize
|
2
|
+
require 'dotenv'
|
3
|
+
Dotenv.load
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
require './lib/status.rb'
|
9
|
+
require './lib/slack.rb'
|
10
|
+
|
11
|
+
APP_ENV = ENV['APP_ENV'] if !defined?(APP_ENV) && ENV['APP_ENV']
|
12
|
+
APP_ENV = 'development' if !defined?(APP_ENV)
|
13
|
+
|
14
|
+
Bundler.require(:default, APP_ENV.to_sym)
|
15
|
+
|
16
|
+
# Create bot manager
|
17
|
+
botmanager = SlackBotManager::Manager.new
|
18
|
+
|
19
|
+
# Add Slack token
|
20
|
+
botmanager.add_token(ENV['SLACK_TOKEN'])
|
21
|
+
|
22
|
+
# Start manager
|
23
|
+
botmanager.start
|
24
|
+
botmanager.monitor
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SlackBotManager
|
2
|
+
module Commands
|
3
|
+
|
4
|
+
def on_hello(data)
|
5
|
+
debug(data)
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_message(data)
|
9
|
+
debug(data)
|
10
|
+
|
11
|
+
message = data['text'].downcase
|
12
|
+
|
13
|
+
site_by_word = /is (\w{2,}) (?:down|up)/
|
14
|
+
site_by_url = /is (\w{2,}\.\w{1,}) (?:down|up)/
|
15
|
+
site_by_link = /is <https?:\/\/[a-zA-Z\.]+\|((?:www.)\w{2,}\.\w\w{1,})> (?:down|up)/
|
16
|
+
|
17
|
+
if message =~ site_by_word
|
18
|
+
typing(data['channel'])
|
19
|
+
word = site_by_word.match(message)[1]
|
20
|
+
url = Status.find_url(word)
|
21
|
+
if (url)
|
22
|
+
message(data['channel'], Status.isitdown(url), icon_emoji: ":ok:")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if message =~ site_by_url
|
27
|
+
typing(data['channel'])
|
28
|
+
url = site_by_url.match(message)[1]
|
29
|
+
message(data['channel'], Status.isitdown(url), icon_emoji: ":ok:")
|
30
|
+
end
|
31
|
+
|
32
|
+
if message =~ site_by_link
|
33
|
+
typing(data['channel'])
|
34
|
+
url = site_by_link.match(message)[1]
|
35
|
+
message(data['channel'], Status.isitdown(url), icon_emoji: ":ok:")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#require 'dotenv'
|
2
|
+
#Dotenv.load
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
require 'bing-search'
|
7
|
+
|
8
|
+
BingSearch.account_key = ENV['BING_SEARCH_KEY']
|
9
|
+
BingSearch.web_only = true
|
10
|
+
|
11
|
+
class Status
|
12
|
+
|
13
|
+
def self.isitdown(url) # e.g. google.com
|
14
|
+
uri = URI('http://downforeveryoneorjustme.com/' + url)
|
15
|
+
output = Net::HTTP.get(uri)
|
16
|
+
if output =~ /It's just you/i
|
17
|
+
if url == 'encrypted.google.com'
|
18
|
+
return "google.com is up :ok_hand:"
|
19
|
+
else
|
20
|
+
return "#{url} is up :ok_hand:"
|
21
|
+
end
|
22
|
+
else
|
23
|
+
return "#{url} is down :warning:"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_url(word)
|
28
|
+
uri = URI('http://api.duckduckgo.com/?q=!' + word + '&format=json&t=downforeveryone-bot')
|
29
|
+
output = Net::HTTP.get(uri)
|
30
|
+
hash = JSON.parse(output)
|
31
|
+
if hash['Redirect'] != ""
|
32
|
+
return /https?:\/\/([\w{2,}\.]+)/.match(hash['Redirect'])[1]
|
33
|
+
else
|
34
|
+
return Status.search_url(word)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.search_url(word)
|
39
|
+
results = BingSearch.web(word, {:limit => 1})
|
40
|
+
if results[0] and results[0].display_url
|
41
|
+
return /(?:https?:\/\/)?([\w{2,}\.]+)/.match(results[0].display_url)[1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# emoji art bot
|
2
|
+
|
3
|
+
an example bot using [slack-bot-manager](https://github.com/betaworks/slack-bot-manager) :sparkles:
|
4
|
+
|
5
|
+
slack-bot-manager depends on `redis` and `slack-ruby-client`
|
6
|
+
|
7
|
+
## usage
|
8
|
+
`emoji art [set] [size]`
|
9
|
+
`set` and `size` are optional
|
10
|
+
|
11
|
+
to get a list of available emoji sets, do `emoji help`
|
12
|
+
|
13
|
+
around the 28-40 size range, messages may be too large to send back to Slack- if you get no response, try a smaller request.
|
14
|
+
|
15
|
+
examples:
|
16
|
+
`emoji art shapes 20`
|
17
|
+
`emoji artist, make me art`
|
18
|
+
`make emoji art that's 10x10 and made of nature`
|
19
|
+
|
20
|
+

|
21
|
+
|
22
|
+
## get started
|
23
|
+
|
24
|
+
1. `touch .env`
|
25
|
+
2. add your Slackbot's token to `.env`
|
26
|
+
3. `bundle install`
|
27
|
+
4. `ruby bot.rb`
|
28
|
+
|
29
|
+
## custom emoji sets
|
30
|
+
|
31
|
+
1. add your set to `lib/json/emoji.json`
|
32
|
+
2. near line 26 of `lib/slack.rb`, there's a case statement- add your keywords and set here (make sure you place it before the else statement)
|
33
|
+
|
34
|
+
for example, to add a set called "buildings" that is used when the user says "buildings" or "city":
|
35
|
+
```
|
36
|
+
when message.include?("buildings") || message.include?("city")
|
37
|
+
group = "buildings"
|
38
|
+
```
|
39
|
+
|
40
|
+
## todo
|
41
|
+
- add an `emoji again` command to do the last command again
|
42
|
+
|
43
|
+

|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Initialize
|
2
|
+
require 'dotenv'
|
3
|
+
Dotenv.load
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
|
8
|
+
require './lib/emoji.rb'
|
9
|
+
require './lib/slack.rb'
|
10
|
+
|
11
|
+
APP_ENV = ENV['APP_ENV'] if !defined?(APP_ENV) && ENV['APP_ENV']
|
12
|
+
APP_ENV = 'development' if !defined?(APP_ENV)
|
13
|
+
|
14
|
+
Bundler.require(:default, APP_ENV.to_sym)
|
15
|
+
|
16
|
+
# Create bot manager
|
17
|
+
botmanager = SlackBotManager::Manager.new
|
18
|
+
|
19
|
+
# Add Slack token
|
20
|
+
botmanager.add_token(ENV['SLACK_TOKEN'])
|
21
|
+
|
22
|
+
# Start manager
|
23
|
+
botmanager.start
|
24
|
+
botmanager.monitor
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class Emoji
|
4
|
+
|
5
|
+
@@emoji = {}
|
6
|
+
|
7
|
+
@@current_list = "all"
|
8
|
+
|
9
|
+
def self.square(size)
|
10
|
+
list = @@emoji[@@current_list]
|
11
|
+
square = ""
|
12
|
+
(0...(size ** 2)).each do |i|
|
13
|
+
square << list.sample
|
14
|
+
if ((i + 1) % size) == 0
|
15
|
+
square << "\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return square
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.choose(list)
|
22
|
+
@@current_list = list
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.list
|
26
|
+
@@emoji.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.load(path)
|
30
|
+
file = File.read(path)
|
31
|
+
@@emoji = JSON.parse(file)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Load emoji sets
|
37
|
+
Emoji.load('./lib/json/emoji.json')
|