isis-plugin-xkcd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6704ce6bece44612a6f95c9ffb58f00c22a5561
4
+ data.tar.gz: c83d50bd4630d5ecd085c31270e7526a5c0f7002
5
+ SHA512:
6
+ metadata.gz: eae2700ea0cc2aeedd5a1cb98405876bfe5286d79909528532d867c8f0618c2acc35451c7f3257dbe00de1285d7402bf8c1263951841ec3c0d75ca71ac727bf8
7
+ data.tar.gz: d3cdd2089239c6c204986f586f180614e930c10d74df959d1d8c5d9dbccdd7e516a683147cfcee3dc2367bbb227ca246c3e3813bfb148acf55f9dde281fe78a7
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ tags
11
+ *.gem
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in isis-plugin-xkcd.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ # Isis plugin: xkcd
2
+
3
+ This plugin adds an [xkcd](http://xkcd.com) command to the [Isis chatbot](https://github.com/silentgrowl/isis)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Isis installation's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'isis-plugin-xkcd'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ To post the newest xkcd comic into a room, type ```!xkcd``` in chat.
20
+
21
+ To post a random xkcd comic, type ```!xkcd random``` in chat.
22
+
23
+ ## Links
24
+
25
+ * [isis-plugin-xkcd on RubyGems](https://rubygems.org/gems/isis-plugin-xkcd)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "isis/plugin/xkcd"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "isis-plugin-xkcd"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["Brendon Rapp"]
9
+ spec.email = ["brendon@silentgrowl.com"]
10
+ spec.license = 'MIT'
11
+
12
+ spec.summary = %q{Isis plugin: xkcd}
13
+ spec.description = %q{Isis plugin: xkcd}
14
+ spec.homepage = "https://github.com/silentgrowl/isis-plugin-xkcd"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "xkcd"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,70 @@
1
+ require "nokogiri"
2
+
3
+ module Isis
4
+ module Plugin
5
+ class XKCD < Isis::Plugin::Base
6
+ def respond_to_msg?(msg, speaker)
7
+ @commands = msg.split
8
+ @commands[0] == '!xkcd'
9
+ end
10
+
11
+ private
12
+
13
+ def response_html
14
+ comic = parse_command
15
+ if comic.is_a?(Hash)
16
+ %Q(#{comic[:title]}<br><img src="http:#{comic[:image]['src']}"><br>#{comic[:image]['title']})
17
+ else
18
+ comic
19
+ end
20
+ end
21
+
22
+ def response_md
23
+ comic = parse_command
24
+ if comic.is_a?(Hash)
25
+ %Q(#{comic[:title]}\nhttp:#{comic[:image]['src']}\n#{comic[:image]['title']})
26
+ else
27
+ comic
28
+ end
29
+ end
30
+
31
+ def response_text
32
+ comic = parse_command
33
+ if comic.is_a?(Hash)
34
+ [comic[:title], comic[:image]['src'], comic[:image]['title']]
35
+ else
36
+ comic
37
+ end
38
+ end
39
+
40
+ def parse_command
41
+ return new_comic if @commands[1].nil?
42
+
43
+ case @commands[1].downcase
44
+ when 'random'
45
+ random_comic
46
+ when 'new'
47
+ new_comic
48
+ when 'commands'
49
+ 'Understood command arguments for !xkcd: new, random'
50
+ else
51
+ "I have no idea what #{@commands[1]} means. No comic for you"
52
+ end
53
+ end
54
+
55
+ def new_comic
56
+ scrape(Nokogiri.HTML(open('http://xkcd.com/')))
57
+ end
58
+
59
+ def random_comic
60
+ scrape(Nokogiri.HTML(open('http://dynamic.xkcd.com/random/comic/')))
61
+ end
62
+
63
+ def scrape(page)
64
+ image = page.css('#comic img').first
65
+ title = page.css('#ctitle').text
66
+ { image: image, title: title }
67
+ end
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isis-plugin-xkcd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendon Rapp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xkcd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: 'Isis plugin: xkcd'
56
+ email:
57
+ - brendon@silentgrowl.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - isis-plugin-xkcd.gemspec
70
+ - lib/isis/plugin/xkcd.rb
71
+ homepage: https://github.com/silentgrowl/isis-plugin-xkcd
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: 'Isis plugin: xkcd'
95
+ test_files: []
96
+ has_rdoc: