blacksmith-hipchat 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/blacksmith.gemspec +29 -0
- data/lib/blacksmith/config.rb +50 -0
- data/lib/blacksmith/hammer.rb +26 -0
- data/lib/blacksmith/listener.rb +22 -0
- data/lib/blacksmith/version.rb +3 -0
- data/lib/blacksmith.rb +8 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 290b454dac3d338325f867d593942cb8ffb9b1ee
|
4
|
+
data.tar.gz: f2a0e80fece3b8bc0871bfd17516071eb03eddc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fcb96091bd222ab080fd3b362f692c4447679be971d529ec098731289b6ca8cf3e58c9a2e7d0bce4e84892f5a8e0b4d81f3de6d2fff3ff9d9fc5571298cb9b8
|
7
|
+
data.tar.gz: 53a0e2dad344e56e5f83f05129e67135c5f228e1fedf19219b4cc4fed8f50dd146536d6cd7244ed063ff68a9fecb6411cf7b4d480583d9d1c283a4185e5b73a6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Blacksmith
|
2
|
+
|
3
|
+
Blacksmith is a custom meme plugin for [robut](https://github.com/justinweiss/robut), a HipChat room plugin. It posts image according to the pattern in the room.
|
4
|
+
|
5
|
+
## Configure
|
6
|
+
|
7
|
+
In `Gemfile`:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'blacksmith-hipchat'
|
11
|
+
```
|
12
|
+
|
13
|
+
In `Chatfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# Add the plugin to the list
|
17
|
+
Robut::Plugin.plugins << Blacksmith::Listener
|
18
|
+
|
19
|
+
# Select a room
|
20
|
+
Blacksmith::Config.room = "chatbot"
|
21
|
+
|
22
|
+
# Map the Images with Regexp
|
23
|
+
Blacksmith::Config.draw do
|
24
|
+
# If you want someone to approve something
|
25
|
+
map /approve/, to: 'http://i.imgur.com/4L8lDAl.png'
|
26
|
+
|
27
|
+
# If you want to have faith
|
28
|
+
map /(have|has|had) faith/, to: 'http://i.imgur.com/BGnagT3.png'
|
29
|
+
|
30
|
+
# If you want to tell some one to do it
|
31
|
+
map /do it/, to: 'http://i.imgur.com/4loCJ30.png'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Optional: Add a title
|
35
|
+
Blacksmith::Config.title = "Memebot"
|
36
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "blacksmith"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/blacksmith.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "blacksmith/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "blacksmith-hipchat"
|
8
|
+
spec.version = Blacksmith::VERSION
|
9
|
+
spec.authors = ["Adler Hsieh"]
|
10
|
+
spec.email = ["adler@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A meme plugin for hipchat}
|
13
|
+
spec.description = %q{It posts image according to the pattern in the room}
|
14
|
+
spec.homepage = "https://github.com/adlerhsieh/blacksmith"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'robut', "0.5.2"
|
24
|
+
spec.add_runtime_dependency 'hipchat', "~> 1.6"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Blacksmith
|
2
|
+
class Config
|
3
|
+
SERVER_URL = ENV["HIPCHAT_SERVER_URL"]
|
4
|
+
API_TOKEN = ENV["HIPCHAT_API_TOKEN"]
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def connection
|
8
|
+
@client ||= HipChat::Client.new(API_TOKEN, server_url: SERVER_URL)
|
9
|
+
end
|
10
|
+
|
11
|
+
def establish_connection!
|
12
|
+
connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def draw(&block)
|
16
|
+
class_eval(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def map(pattern = nil, options = {})
|
20
|
+
raise MappingError, "No pattern is given" if pattern.nil?
|
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
|
26
|
+
|
27
|
+
def patterns
|
28
|
+
@patterns ||= {}
|
29
|
+
end
|
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
|
42
|
+
|
43
|
+
def room=(name)
|
44
|
+
@room = name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class MappingError < StandardError; end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'hipchat'
|
2
|
+
|
3
|
+
module Blacksmith
|
4
|
+
class Hammer
|
5
|
+
def initialize(url: nil)
|
6
|
+
@target_room = Blacksmith::Config.room
|
7
|
+
@url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
def connection
|
11
|
+
Blacksmith::Config.connection
|
12
|
+
end
|
13
|
+
|
14
|
+
def slam
|
15
|
+
options = {
|
16
|
+
message_format: "html",
|
17
|
+
}
|
18
|
+
|
19
|
+
connection[@target_room].send(
|
20
|
+
Blacksmith::Config.title,
|
21
|
+
"<img src=\"#{@url}\" />",
|
22
|
+
options
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'robut'
|
2
|
+
|
3
|
+
module Blacksmith
|
4
|
+
class Listener
|
5
|
+
include Robut::Plugin
|
6
|
+
|
7
|
+
def handle(time, sender, message)
|
8
|
+
return if message.include?("File uploaded")
|
9
|
+
Config.patterns.each do |pattern, url|
|
10
|
+
if message[pattern]
|
11
|
+
Hammer.new(url: url).slam
|
12
|
+
return
|
13
|
+
end
|
14
|
+
end
|
15
|
+
rescue => err
|
16
|
+
puts "#{err.class}: #{err.message}"
|
17
|
+
err.backtrace.each do |b|
|
18
|
+
puts b
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/blacksmith.rb
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacksmith-hipchat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adler Hsieh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: robut
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hipchat
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.15'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.15'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: It posts image according to the pattern in the room
|
84
|
+
email:
|
85
|
+
- adler@hotmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- blacksmith.gemspec
|
99
|
+
- lib/blacksmith.rb
|
100
|
+
- lib/blacksmith/config.rb
|
101
|
+
- lib/blacksmith/hammer.rb
|
102
|
+
- lib/blacksmith/listener.rb
|
103
|
+
- lib/blacksmith/version.rb
|
104
|
+
homepage: https://github.com/adlerhsieh/blacksmith
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.12
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A meme plugin for hipchat
|
127
|
+
test_files: []
|