cinch-reddit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ *.DS_STORE
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cinch-reddit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeff Sandberg
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,7 @@
1
+ This is a simple reddit plugin for the [cinch](http://cinchrb.org) IRC bot framework
2
+
3
+ # Commands
4
+
5
+ + `!karma <username>`: returns the karma of <username>
6
+ + `!readers <subreddit>`: returns the subscriber count of <subreddit>
7
+ + `!mods <subreddit>`: returns the mods of <subreddit>
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Jeff Sandberg"]
4
+ gem.email = ["paradox460@gmail.com"]
5
+ gem.description = <<-EOF
6
+ This is a simple reddit plugin for the excellent cinch irc bot framework.
7
+ It provides a few simple commands, !karma, !mods, and !readers.
8
+ + !karma <user> returns the karma of a reddit.com user account
9
+ + !mods <subreddit> returns the moderators of a reddit.com subreddit
10
+ + !readers <subreddit> returns the subscriber count of a subreddit.
11
+ EOF
12
+ gem.summary = %q{A reddit plugin for the cinch irc bot framework}
13
+ gem.homepage = "http://paradox.gd"
14
+
15
+ gem.add_dependency "cinch"
16
+ gem.add_dependency "json"
17
+
18
+ gem.files = `git ls-files`.split($\)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.name = "cinch-reddit"
22
+ gem.require_paths = ["lib"]
23
+ gem.version = "1.0.0"
24
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2012 Jeff Sandberg
3
+ # This program is made avalible under the terms of the MIT license.
4
+
5
+ require 'cinch'
6
+ require 'json'
7
+ require 'open-uri'
8
+ require 'cgi'
9
+
10
+ module Cinch
11
+ module Plugins
12
+ class Reddit
13
+ include Cinch::Plugin
14
+
15
+ RedditBaseUrl = "http://www.reddit.com"
16
+ # Utilities
17
+
18
+ # Takes an ingeger, puts commas in appropriate places, and returns a string
19
+ def commify(n)
20
+ n.to_s =~ /([^\.]*)(\..*)?/
21
+ int, dec = $1.reverse, $2 ? $2 : ""
22
+ while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3')
23
+ end
24
+ int.reverse + dec
25
+ end
26
+
27
+ # Loads a URL from the reddit API
28
+ # This saves time, as well as providing our own unique user-agent
29
+ def urlload(url)
30
+ open(url, "User-Agent" => "reddit-irc-bot").read
31
+ end
32
+
33
+ # Plugin code
34
+
35
+ # Karma Lookup
36
+ match /karma (\w+)/, method: :karma
37
+ def karma(m, user)
38
+ url = "%s/user/%s/about.json" % [RedditBaseUrl, user]
39
+ data = JSON.parse(urlload url)["data"] rescue nil
40
+ unless data
41
+ m.reply("%s doesn't appear to exist and therefore can't have karma" % user)
42
+ else
43
+ m.reply("%s has a link karma of %s and comment karma of %s" % [ Format(:bold, data["name"]), commify(data["link_karma"]), commify(data["comment_karma"]) ])
44
+ end
45
+ end
46
+
47
+ # Subreddit mods
48
+ match /mods (\w+)/, method: :mods
49
+ def mods(m, subreddit)
50
+ url = "%s/r/%s/about/moderators.json" % [RedditBaseUrl, subreddit]
51
+ data = JSON.parse(urlload url)["data"]["children"] rescue nil
52
+ unless data
53
+ m.reply("%s doesn't appear to exist and therefore can't have moderators" % subreddit)
54
+ else
55
+ subMods = []
56
+ data.each { |mod| subMods << mod["name"] }
57
+ m.reply("%s has moderators: %s" % [Format(:bold, subreddit), subMods.join(", ")])
58
+ end
59
+ end
60
+
61
+ # Subreddit readers
62
+ match /readers (\w+)/, method: :readers
63
+ def readers(m, subreddit)
64
+ url = "%s/r/%s/about.json" % [RedditBaseUrl, subreddit]
65
+ data = JSON.parse(urlload url)["data"]["subscribers"] rescue nil
66
+ unless data
67
+ m.reply("%s doesn't appear to exist and therefore can't have subscribers" % subreddit)
68
+ else
69
+ m.reply("%s has %s readers" % [Format(:bold, subreddit), commify(data)])
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-reddit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Sandberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: &70093075066960 !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: *70093075066960
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70093075065420 !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: *70093075065420
36
+ description: ! " This is a simple reddit plugin for the excellent cinch irc bot
37
+ framework.\n It provides a few simple commands, !karma, !mods, and !readers.\n
38
+ \ + !karma <user> returns the karma of a reddit.com user account\n + !mods
39
+ <subreddit> returns the moderators of a reddit.com subreddit\n + !readers <subreddit>
40
+ returns the subscriber count of a subreddit.\n"
41
+ email:
42
+ - paradox460@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.md
51
+ - cinch-reddit.gemspec
52
+ - lib/cinch/plugins/reddit.rb
53
+ homepage: http://paradox.gd
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.11
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: A reddit plugin for the cinch irc bot framework
77
+ test_files: []