blacksmith-hipchat 0.1.1 → 0.1.2
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 -9
- data/lib/blacksmith/config.rb +22 -27
- data/lib/blacksmith/listener.rb +3 -1
- data/lib/blacksmith/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: b4a86ddc466446a6ee015b52b981ded581d31168
|
4
|
+
data.tar.gz: 34d62bdaeaa1a4967f6956da3ea9cbea12636a34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b86bae74e08631eb2a927ed01f095a279b7db21f0a6ad1d574e91c6f719fa9fa5fbb820113087c2f7360b99ef48ba90656925ef36857e7beba307af121dbe9
|
7
|
+
data.tar.gz: 31ea4fb9eb9aa7b518fd8e7bdb576c528b45ee7097f200967b2da5fe60a5acb3ba36f86d0f8db0dbc386f792948bf30da0ddf726d9500956696df3ce1c965191
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ In `Gemfile`:
|
|
10
10
|
gem 'blacksmith-hipchat'
|
11
11
|
```
|
12
12
|
|
13
|
+
run `bundle install` afterwards.
|
14
|
+
|
13
15
|
In `Chatfile`:
|
14
16
|
|
15
17
|
```ruby
|
@@ -19,18 +21,23 @@ Robut::Plugin.plugins << Blacksmith::Listener
|
|
19
21
|
# Select a room
|
20
22
|
Blacksmith::Config.room = "chatbot"
|
21
23
|
|
22
|
-
#
|
23
|
-
Blacksmith::Config.
|
24
|
-
# If you want someone to approve something
|
25
|
-
map /approve/, to: 'http://i.imgur.com/4L8lDAl.png'
|
24
|
+
# custom server_url
|
25
|
+
Blacksmith::Config.server_url = "https://custom_server.com"
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# API token for the account sending all messages
|
28
|
+
# See how to generate a personal token at https://www.hipchat.com/docs/apiv2/method/generate_token
|
29
|
+
Blacksmith::Config.api_token = "..."
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
# Map the Images with Regexp
|
32
|
+
Blacksmith::Config.draw do
|
33
|
+
# map /regexp/, to: 'image_url'
|
34
|
+
map /just do it/, to: 'https://i.imgur.com/4loCJ30.png'
|
32
35
|
end
|
36
|
+
```
|
33
37
|
|
34
|
-
|
38
|
+
Optional setup:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Add a title to the message sender
|
35
42
|
Blacksmith::Config.title = "Memebot"
|
36
43
|
```
|
data/lib/blacksmith/config.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
module Blacksmith
|
2
2
|
class Config
|
3
|
-
SERVER_URL = ENV["HIPCHAT_SERVER_URL"]
|
4
|
-
API_TOKEN = ENV["HIPCHAT_API_TOKEN"]
|
5
|
-
|
6
3
|
class << self
|
4
|
+
|
5
|
+
attr_accessor :title, :room, :patterns, :server_url, :api_token
|
6
|
+
|
7
7
|
def connection
|
8
|
-
@client
|
8
|
+
return @client if @client
|
9
|
+
|
10
|
+
["room", "api_token"].each do |attr|
|
11
|
+
if eval(attr).nil?
|
12
|
+
raise ConfigError, "Missing configuration: #{attr}. Check README to setup."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@client = if server_url
|
17
|
+
HipChat::Client.new(api_token, server_url: server_url)
|
18
|
+
else
|
19
|
+
HipChat::Client.new(api_token)
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
def establish_connection!
|
@@ -17,34 +29,17 @@ module Blacksmith
|
|
17
29
|
end
|
18
30
|
|
19
31
|
def map(pattern = nil, options = {})
|
20
|
-
|
21
|
-
raise MappingError, "Pattern cannot be blank" if pattern == //
|
22
|
-
raise MappingError, "Pattern should be a Regexp" unless pattern.is_a? Regexp
|
23
|
-
raise MappingError, "Missing target in mapping. Use: to: 'target'" if options.is_a?(Hash).! || options[:to].nil?
|
24
|
-
patterns[pattern] = options[:to]
|
25
|
-
end
|
32
|
+
self.patterns ||= {}
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def title
|
32
|
-
@title ||= ""
|
33
|
-
end
|
34
|
-
|
35
|
-
def title=(name)
|
36
|
-
@title = name
|
37
|
-
end
|
38
|
-
|
39
|
-
def room
|
40
|
-
@room ||= ""
|
41
|
-
end
|
34
|
+
raise MappingError, "Pattern can only be a Regexp" unless pattern.is_a? Regexp
|
35
|
+
raise MappingError, "Pattern cannot be blank" if pattern == //
|
36
|
+
raise MappingError, "Missing target in mapping. Use: to: 'image_url'" if options.is_a?(Hash).! || options[:to].nil?
|
42
37
|
|
43
|
-
|
44
|
-
@room = name
|
38
|
+
self.patterns[pattern] = options[:to]
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
48
42
|
|
43
|
+
class ConfigError < StandardError; end
|
49
44
|
class MappingError < StandardError; end
|
50
45
|
end
|
data/lib/blacksmith/listener.rb
CHANGED
@@ -5,11 +5,13 @@ module Blacksmith
|
|
5
5
|
include Robut::Plugin
|
6
6
|
|
7
7
|
def handle(time, sender, message)
|
8
|
+
# Don't handle messages sent from this plugin
|
8
9
|
return if message.include?("File uploaded")
|
10
|
+
|
9
11
|
Config.patterns.each do |pattern, url|
|
10
12
|
if message[pattern]
|
11
13
|
Hammer.new(url: url).slam
|
12
|
-
|
14
|
+
break
|
13
15
|
end
|
14
16
|
end
|
15
17
|
rescue => err
|
data/lib/blacksmith/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacksmith-hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adler Hsieh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: robut
|