cinch-reddit 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -4
- data/cinch-reddit.gemspec +3 -3
- data/lib/cinch/plugins/reddit.rb +52 -8
- metadata +17 -6
data/README.md
CHANGED
@@ -1,7 +1,31 @@
|
|
1
|
-
This is a simple reddit plugin for the [cinch]
|
1
|
+
This is a simple reddit plugin for the [cinch][1] IRC bot framework
|
2
2
|
|
3
3
|
# Commands
|
4
4
|
|
5
|
-
+ `!karma <username>`: returns the karma of
|
6
|
-
+ `!readers <subreddit>`: returns the subscriber count of
|
7
|
-
+ `!mods <subreddit>`: returns the mods of
|
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>`
|
8
|
+
|
9
|
+
# Installing
|
10
|
+
You need to have the [cinch][1] framework installed, but once you have that done the rest is simple.
|
11
|
+
|
12
|
+
+ Write a new bot file, and include `require 'cinch/plugins/reddit'.
|
13
|
+
+ In your configure block, add `Cinch::Plugins::Reddit`, ex: `c.plugins.plugins = [Cinch::Plugins::Reddit]`
|
14
|
+
|
15
|
+
Here is a sample bot:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'cinch'
|
19
|
+
require 'cinch/plugins/reddit'
|
20
|
+
|
21
|
+
bot = Cinch::Bot.new do
|
22
|
+
configure do |c|
|
23
|
+
c.server = "irc.snoonet.com"
|
24
|
+
c.nick = "testborg"
|
25
|
+
c.channels = [ "#bottest" ]
|
26
|
+
c.plugins.plugins = [Cinch::Plugins::Reddit]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
bot.start
|
31
|
+
```
|
data/cinch-reddit.gemspec
CHANGED
@@ -10,13 +10,13 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.summary = %q{A reddit plugin for the cinch irc bot framework}
|
11
11
|
gem.homepage = "http://github.com/paradox460/cinch-reddit"
|
12
12
|
|
13
|
-
|
14
|
-
gem.add_dependency
|
13
|
+
# Clean way to handle add_dependency
|
14
|
+
%w{cinch json actionpack}.each { |x| gem.add_dependency x }
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($\)
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.name = "cinch-reddit"
|
20
20
|
gem.require_paths = ["lib"]
|
21
|
-
gem.version = "1.0
|
21
|
+
gem.version = "1.1.0"
|
22
22
|
end
|
data/lib/cinch/plugins/reddit.rb
CHANGED
@@ -6,11 +6,15 @@ require 'cinch'
|
|
6
6
|
require 'json'
|
7
7
|
require 'open-uri'
|
8
8
|
require 'cgi'
|
9
|
+
require 'uri'
|
10
|
+
require 'action_view'
|
11
|
+
require 'date'
|
9
12
|
|
10
13
|
module Cinch
|
11
14
|
module Plugins
|
12
15
|
class Reddit
|
13
16
|
include Cinch::Plugin
|
17
|
+
include ActionView::Helpers::DateHelper
|
14
18
|
|
15
19
|
RedditBaseUrl = "http://www.reddit.com"
|
16
20
|
# Utilities
|
@@ -49,10 +53,10 @@ module Cinch
|
|
49
53
|
def karma(m, user)
|
50
54
|
url = "%s/user/%s/about.json" % [RedditBaseUrl, user]
|
51
55
|
data = JSON.parse(urlload url)["data"] rescue nil
|
52
|
-
|
53
|
-
m.reply("%s doesn't appear to exist and therefore can't have karma" % user)
|
54
|
-
else
|
56
|
+
if data
|
55
57
|
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"]) ])
|
58
|
+
else
|
59
|
+
m.reply("%s doesn't appear to exist and therefore can't have karma" % user)
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
@@ -61,12 +65,12 @@ module Cinch
|
|
61
65
|
def mods(m, subreddit)
|
62
66
|
url = "%s/r/%s/about/moderators.json" % [RedditBaseUrl, subreddit]
|
63
67
|
data = JSON.parse(urlload url)["data"]["children"] rescue nil
|
64
|
-
|
65
|
-
m.reply("%s doesn't appear to exist and therefore can't have moderators" % subreddit)
|
66
|
-
else
|
68
|
+
if data
|
67
69
|
subMods = []
|
68
70
|
data.each { |mod| subMods << mod["name"] }
|
69
71
|
m.reply("%s has %s: %s" % [Format(:bold, subreddit), pluralize( subMods.length, "moderator"), subMods[0..-2].join(", ") + ", and " + subMods[-1] ])
|
72
|
+
else
|
73
|
+
m.reply("%s doesn't appear to exist and therefore can't have moderators" % subreddit)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
@@ -75,10 +79,50 @@ module Cinch
|
|
75
79
|
def readers(m, subreddit)
|
76
80
|
url = "%s/r/%s/about.json" % [RedditBaseUrl, subreddit]
|
77
81
|
data = JSON.parse(urlload url)["data"]["subscribers"] rescue nil
|
78
|
-
|
82
|
+
if data
|
83
|
+
m.reply("%s has %s" % [Format(:bold, subreddit), pluralize(data, "reader")])
|
84
|
+
else
|
79
85
|
m.reply("%s doesn't appear to exist and therefore can't have subscribers" % subreddit)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
match /lookup (\S+)/, method: :lookup
|
90
|
+
def lookup(m, query)
|
91
|
+
url = "%s/api/info.json?url=%s" % [RedditBaseUrl, query]
|
92
|
+
data = JSON.parse(urlload url)["data"]["children"][0]["data"] rescue nil
|
93
|
+
if data
|
94
|
+
m.reply("%s - \"%.100s\" %s(%s|%s) by %s, %s ago, to /r/%s" % [
|
95
|
+
"http://redd.it/#{data['id']}",
|
96
|
+
Format(:bold, data['title']),
|
97
|
+
Format(:grey, commify(data['score'])),
|
98
|
+
Format(:orange, "+" + commify(data['ups'])),
|
99
|
+
Format(:blue, "-" + commify(data['downs'])),
|
100
|
+
data['author'],
|
101
|
+
time_ago_in_words(DateTime.strptime(data['created'].to_s,'%s')),
|
102
|
+
data['subreddit']
|
103
|
+
])
|
80
104
|
else
|
81
|
-
m.reply("
|
105
|
+
m.reply("I couldn't find that for some reason. It might be my fault, or it might be reddit's")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
match /link (\S+)/, method: :linkLookup
|
110
|
+
def linkLookup(m, query)
|
111
|
+
thing_id = URI.parse(query).path.split('/')[4]
|
112
|
+
url = "%s/api/info.json?id=t3_%s" % [RedditBaseUrl, thing_id]
|
113
|
+
data = JSON.parse(urlload url)["data"]["children"][0]["data"] rescue nil
|
114
|
+
if data
|
115
|
+
m.reply("\"%s\" %s(%s|%s) by %s, %s ago, to /r/%s" % [
|
116
|
+
Format(:bold, data['title']),
|
117
|
+
Format(:grey, commify(data['score'])),
|
118
|
+
Format(:orange, "+" + commify(data['ups'])),
|
119
|
+
Format(:blue, "-" + commify(data['downs'])),
|
120
|
+
data['author'],
|
121
|
+
time_ago_in_words(DateTime.strptime(data['created'].to_s, '%s')),
|
122
|
+
data['subreddit']
|
123
|
+
])
|
124
|
+
else
|
125
|
+
m.reply("I couldn't find that for some reason. It might be my fault, or it might be reddit's")
|
82
126
|
end
|
83
127
|
end
|
84
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-reddit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|
16
|
-
requirement: &
|
16
|
+
requirement: &70309974332900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70309974332900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70309974093780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70309974093780
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: actionpack
|
38
|
+
requirement: &70309974093360 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70309974093360
|
36
47
|
description: ! " This is a simple reddit plugin for the excellent cinch irc bot
|
37
48
|
framework.\n It provides a few simple commands, !karma, !mods, and !readers.\n
|
38
49
|
\ See the github page for more details\n"
|