hipbot-plugins 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hipbot-plugins.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomasz Pewiński
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # hipbot-plugins
2
+
3
+ This is a collection of open-source plugins for https://github.com/pewniak747/hipbot, initially developped at http://netguru.co
4
+
5
+ ## Installation
6
+
7
+ Add this line to your hipbot's Gemfile:
8
+
9
+ gem 'hipbot-plugins'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ To include a plugin, use hipbot's configuration (https://github.com/pewniak747/hipbot#customize)
18
+
19
+ ``` ruby
20
+ require 'hipbot'
21
+ require 'hipbot-plugins'
22
+
23
+ class MyCompanyBot < Hipbot::Bot
24
+ configure do |c|
25
+ c.name = 'robot'
26
+ c.jid = 'changeme@chat.hipchat.com'
27
+ c.password = 'secret'
28
+ c.plugins = [ Hipbot::Plugins::Human, Hipbot::Plugins::Google ]
29
+ end
30
+ end
31
+ ```
32
+
33
+ ## Plugins
34
+
35
+ ### Hipbot::Plugins::Human
36
+
37
+ By including this plugin, hipbot gains human traits! It can also reply using Cleverbot, when it does not understand.
38
+
39
+ Hipbot responds to:
40
+
41
+ * hello
42
+ * open the pod bay door
43
+ * make me a sandwich
44
+ * slap @someone
45
+ * insult @someone
46
+ * choose
47
+ * comfort me
48
+ * (AI simulation with Cleverbot)
49
+
50
+ ### Hipbot::Plugins::Google
51
+
52
+ Adds various responses for searching the Interwebs
53
+
54
+ Hipbot responds to:
55
+
56
+ * google something I want to know
57
+ * image something I want to see
58
+ * youtube something I want to watch
59
+ * something vs somethingelse vs someoranother vs ...
60
+ * translate en:pl something I want to translate
61
+
62
+ ### Github
63
+
64
+ Can generate links to github
65
+
66
+ Hipbot responds to:
67
+
68
+ * github some_method_i_want_to_search_in_my_organization
69
+ * compare master to production
70
+
71
+ ( For this to work you need to define `project` and `organization` methods as a response helpers: https://github.com/pewniak747/hipbot#response-helpers )
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hipbot-plugins/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hipbot-plugins"
8
+ gem.version = Hipbot::Plugins::VERSION
9
+ gem.authors = ["Bartosz Kopiński", "Tomasz Pewiński"]
10
+ gem.email = ["bartosz.kopinski@netguru.pl", "pewniak747@gmail.com"]
11
+ gem.description = %q{A collection of plugins to use in your hipbot installation}
12
+ gem.summary = %q{A collection of plugins to use in your hipbot installation}
13
+ gem.homepage = "https://github.com/netguru/hipbot-plugins"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_runtime_dependency "hipbot"
20
+ gem.add_runtime_dependency 'cleverbot'
21
+ gem.add_runtime_dependency 'htmlentities'
22
+ end
@@ -0,0 +1,10 @@
1
+ require "hipbot-plugins/version"
2
+ require "hipbot-plugins/human"
3
+ require "hipbot-plugins/github"
4
+ require "hipbot-plugins/google"
5
+
6
+ module Hipbot
7
+ module Plugins
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Hipbot
2
+ module Plugins
3
+ class Github < Hipbot::Plugin
4
+ on /^compare (\w+)(?: to)? (\w+)$/, room: true do |stage1, stage2|
5
+ reply "https://github.com/#{organization}/#{project.name}/compare/#{stage1}...#{stage2}" if project
6
+ end
7
+
8
+ on /^github (.+)/ do |query|
9
+ query = URI::encode query
10
+ reply "https://github.com/search?q=#{query}+%40#{organization}&ref=searchresults&type=Code&s=indexed"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,70 @@
1
+ module Hipbot
2
+ module Plugins
3
+ class Google < Hipbot::Plugin
4
+ on /^google (.+)/ do |search|
5
+ get('http://ajax.googleapis.com/ajax/services/search/web', { q: URI::encode(search), safe: 'off', v: '1.0' }) do |http|
6
+ http.json['responseData']['results'].each do |page|
7
+ reply("#{page['url']} - #{page['titleNoFormatting']}")
8
+ end
9
+ end
10
+ end
11
+
12
+ on /^(.+ vs?\.? .+)/i do |battle|
13
+ winner = { score: 0 }
14
+ objects = battle.split(/ vs?\.? /i)
15
+ left = objects.count
16
+ objects.each do |obj|
17
+ get('http://ajax.googleapis.com/ajax/services/search/web', { q: URI::encode(obj), safe: 'off', v: '1.0' }) do |http|
18
+ score = http.json['responseData']['cursor']['resultCount'].delete(' ').to_i
19
+ winner = { name: obj, score: score } if score > winner[:score]
20
+ left -= 1
21
+ end
22
+ end
23
+ sleep(1) until left == 0
24
+ notify("...and the winner is #{winner[:name]}!", 'Google')
25
+ end
26
+
27
+ on /^image (.+)/ do |search|
28
+ get('http://ajax.googleapis.com/ajax/services/search/images', { q: URI::encode(search), safe: 'moderate', v: '1.0', hl: 'pl', imgsz: 'large', rsz: 1 }) do |http|
29
+ reply http.json['responseData']['results'].sample['url']
30
+ end
31
+ end
32
+
33
+ on /^youtube (.+)/, /^yt (.+)/ do |query|
34
+ get('http://gdata.youtube.com/feeds/api/videos', { q: URI::encode(query), alt: 'json', :'max-results' => 3, orderBy: 'relevance'}) do |http|
35
+ reply http.json['feed']['entry'].sample['link'][0]['href']
36
+ end
37
+ end
38
+
39
+ on /^translate (.+)/ do |query|
40
+ params, text = query.split(' ', 2)
41
+ from, to = params.split(':')
42
+ if to.nil?
43
+ to = from
44
+ from = 'pl'
45
+ end
46
+
47
+ params = {
48
+ client: 't',
49
+ text: text,
50
+ hl: from,
51
+ sl: 'auto',
52
+ tl: to,
53
+ multires: '1',
54
+ prev: 'btn',
55
+ ssel: '0',
56
+ tsel: '4',
57
+ uptl: to,
58
+ alttl: from,
59
+ sc: '1',
60
+ ie: 'UTF-8',
61
+ oe: 'UTF-8',
62
+ }
63
+ get('http://translate.google.com/translate_a/t', params) do |http|
64
+ response = JSON.parse(http.body.gsub(/,+/, ','))
65
+ reply(response[0][0][0])
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,51 @@
1
+ require 'cleverbot'
2
+ require 'htmlentities'
3
+
4
+ module Hipbot
5
+ module Plugins
6
+ class Human < Hipbot::Plugin
7
+ on /^hello/ do
8
+ reply("hello #{sender.first_name}!")
9
+ end
10
+
11
+ on /open the pod bay door[s]?/ do
12
+ reply("I'm afraid I can't do that, #{sender.first_name}")
13
+ end
14
+
15
+ on /make me a (.+)/ do |thing|
16
+ reply("/me hands #{sender} a #{thing}")
17
+ end
18
+
19
+ on /slap (.+)/ do
20
+ message.mentions.each do |mention|
21
+ reply("/me slaps #{mention} around a bit with a large trout.")
22
+ end
23
+ end
24
+
25
+ on /insult (.+)/ do
26
+ message.mentions.each do |mention|
27
+ get('http://programmerinsults.com/') do |http|
28
+ insult = http.body.scan(/color: #333;">(.+?)<\/a>/mi).flatten
29
+ reply("#{mention}, #{insult.first}")
30
+ end
31
+ end
32
+ end
33
+
34
+ on /^choose( ([0-9]+))?/, room: true do |_, number|
35
+ number ||= 1
36
+ reply("/me chooses #{room.users.sample(number.to_i).map(&:name).to_sentence}") if room.present?
37
+ end
38
+
39
+ on /^(comfort|i haz a sad|i have a sad)/ do
40
+ reply("/me pats #{message.sender.first_name} on the head")
41
+ reply("#{message.sender.first_name}, everything is going to be alright!")
42
+ end
43
+
44
+ default do |message|
45
+ cleverbot = Cleverbot::Client.new
46
+ coder = HTMLEntities.new
47
+ reply(coder.decode(cleverbot.write(message)) || 'I don\'t undersand you')
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Hipbot
2
+ module Plugins
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hipbot-plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bartosz Kopiński
9
+ - Tomasz Pewiński
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hipbot
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: cleverbot
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: htmlentities
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ description: A collection of plugins to use in your hipbot installation
64
+ email:
65
+ - bartosz.kopinski@netguru.pl
66
+ - pewniak747@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - hipbot-plugins.gemspec
77
+ - lib/hipbot-plugins.rb
78
+ - lib/hipbot-plugins/github.rb
79
+ - lib/hipbot-plugins/google.rb
80
+ - lib/hipbot-plugins/human.rb
81
+ - lib/hipbot-plugins/version.rb
82
+ homepage: https://github.com/netguru/hipbot-plugins
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.23
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A collection of plugins to use in your hipbot installation
106
+ test_files: []
107
+ has_rdoc: