gifbot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'cinch'
4
+ gem 'nokogiri'
5
+
6
+ # Specify your gem's dependencies in gifbot.gemspec
7
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Travis Dunn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ ## HUH?
2
+ My cute little gif slinging irc bot for [http://whyday.org/](whyday). Gifs courtesy of [http://www.gifbin.com](gifbin)
3
+
4
+ Requires ruby >= 1.9.1
5
+
6
+ ## Usage
7
+
8
+ # start up gifbot
9
+ $ gifbot --server=irc.freenode.net --nick=gifbot --channels=ruby,rails
10
+
11
+
12
+ # ask for some gifs in irc
13
+
14
+ # a dancing gif
15
+ <blahed> ?gifme dancing
16
+ <gifbot> http://www.gifbin.com/bin/11825gh64404673.gif
17
+
18
+ # a random gif
19
+ <blahed> ?randomgif
20
+ <gifbot> http://www.gifbin.com/bin/072009/1246556808_Missile_launch_fail.gif
21
+
22
+
23
+
24
+ ## Installation
25
+ $ gem install gifbot
26
+
27
+
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+
4
+ require 'optparse'
5
+ require 'gifbot'
6
+
7
+ GifBot::CLI.run!
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'gifbot/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'gifbot'
7
+ s.version = GifBot::VERSION
8
+ s.authors = ['blahed']
9
+ s.email = ['tdunn13@gmail.com']
10
+ s.homepage = ''
11
+ s.summary = 'Gif slinging IRC bot'
12
+ s.description = 'Gif slinging IRC bot'
13
+
14
+ s.rubyforge_project = 'gifbot'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_dependency('cinch', ['>= 0'])
22
+ s.add_dependency('nokogiri', ['>= 0'])
23
+ end
@@ -0,0 +1,62 @@
1
+ require 'cgi'
2
+ require 'open-uri'
3
+ require 'cinch'
4
+ require 'nokogiri'
5
+ require 'gifbot/cli'
6
+ require 'gifbot/version'
7
+
8
+ module GifBot
9
+ GIFBIN_URL = 'http://www.gifbin.com'
10
+
11
+ def self.connect(options={})
12
+ bot = Cinch::Bot.new do
13
+ configure do |c|
14
+ c.server = options[:server]
15
+ c.nick = options[:nick]
16
+ c.channels = options[:channels]
17
+ end
18
+
19
+ helpers do
20
+ def search(query)
21
+ query = CGI.escape(query)
22
+ gifs = []
23
+ results = Nokogiri::HTML( open("#{GIFBIN_URL}/search/#{query}/") )
24
+
25
+ results.xpath('//div[@class="thumb-cell"]//a').each do |a|
26
+ gifs << a['href'].sub(/^\//, '')
27
+ end
28
+
29
+ if gifs.empty?
30
+ "damn, no gif for \"#{query}\""
31
+ else
32
+ id = gifs[rand(gifs.length)]
33
+ page = Nokogiri::HTML( open("#{GIFBIN_URL}/#{id}") )
34
+
35
+ image_url_from_page(page)
36
+ end
37
+ end
38
+
39
+ def random
40
+ page = Nokogiri::HTML(open("#{GIFBIN_URL}/random"))
41
+
42
+ image_url_from_page(page)
43
+ end
44
+
45
+ def image_url_from_page(page)
46
+ GIFBIN_URL + page.xpath('//div[@class="box"]//img[@class="gif"]').first['src']
47
+ end
48
+ end
49
+
50
+ on :message, /^?randomgif/ do |m|
51
+ m.reply random
52
+ end
53
+
54
+ on :message, /^?gifme (.+)/ do |m, query|
55
+ m.reply search(query)
56
+ end
57
+
58
+ end
59
+
60
+ bot.start
61
+ end
62
+ end
@@ -0,0 +1,51 @@
1
+ require 'optparse'
2
+
3
+ module GifBot
4
+ class CLI
5
+ class << self
6
+
7
+ def set_options
8
+ @options = {}
9
+
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = "Usage: gifbot [options]\n\nExample: gifbot --server=irc.freenode.net --nick=gifbot --channels=ruby,rails"
12
+
13
+ opts.separator ''
14
+ opts.separator 'Options:'
15
+
16
+ opts.on('--server [HOST]', 'Set the server to connect to') do |server|
17
+ @options[:server] = server unless server.nil?
18
+ end
19
+
20
+ opts.on('--nick [NICK]', 'Set gifbot\'s nickname') do |nick|
21
+ @options[:nick] = nick unless nick.nil?
22
+ end
23
+
24
+ opts.on('--channels [CHANNELS]', 'Tell gifbot what channels to connect to (comma seperated, without hash)') do |channels|
25
+ @options[:channels] = channels.split(',').map{ |c| '#' + c } unless channels.nil?
26
+ end
27
+
28
+ opts.on( '-h', '--help', 'Display this help' ) do
29
+ puts opts
30
+ exit
31
+ end
32
+
33
+ end
34
+
35
+ opts.parse!
36
+
37
+ unless %w[server nick channels].all? { |k| @options.has_key?(k.to_sym) }
38
+ puts opts
39
+ exit
40
+ end
41
+ end
42
+
43
+ def run!
44
+ set_options
45
+
46
+ GifBot.connect(@options)
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module GifBot
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gifbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - blahed
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: &70109800921920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70109800921920
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70109800921400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70109800921400
36
+ description: Gif slinging IRC bot
37
+ email:
38
+ - tdunn13@gmail.com
39
+ executables:
40
+ - gifbot
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - bin/gifbot
50
+ - gifbot.gemspec
51
+ - lib/gifbot.rb
52
+ - lib/gifbot/cli.rb
53
+ - lib/gifbot/version.rb
54
+ homepage: ''
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: gifbot
74
+ rubygems_version: 1.8.6
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Gif slinging IRC bot
78
+ test_files: []