sentry-reddit 0.1.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: d7b18b373f62a399c861a4656baf79c616d2ac8a
4
+ data.tar.gz: 9e2e571563512afed6202785a5ef229741e104e8
5
+ SHA512:
6
+ metadata.gz: a22645b92dde0f55cf8b695aed66f4743236626bca3a67f1f9e7b2a5765ca76b1321c3de12a3b732786e04addbff430bc11fa6af3849ffcdbc4bf5410dbf68cb
7
+ data.tar.gz: 1980e8d54aec14b939efbb2bf137dd6893eb63bcb77f2daf6e02a34b5bdda229235d7649ea5246aa691bcc586c184b89da52a6642246347886a0434352fc3404
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ pkg/
3
+ vendor/cache/*.gem
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2015-01-28
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 jRiddick
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,39 @@
1
+ = sentry-reddit
2
+
3
+ Parses messages for Reddit links then replies with information about it.
4
+
5
+ == Features
6
+
7
+ * Replies with information about posted links
8
+
9
+ == Examples
10
+
11
+ require 'cinch'
12
+ require 'cinch/plugins/sentry/reddit'
13
+
14
+ bot = Cinch::Bot.new do
15
+ configure do |c|
16
+ c.nick = "Raknet"
17
+ c.server = "irc.oftc.net"
18
+ c.channels = ["#cinchdev"]
19
+ c.plugins.plugins = [Cinch::Plugins::Sentry::Reddit]
20
+ c.plugins.options = {
21
+ Cinch::Plugins::Sentry::Reddit => {
22
+ "username" => "hello",
23
+ "password" => "hello"
24
+ }
25
+ }
26
+ end
27
+ end
28
+
29
+ bot.start
30
+
31
+ == Install
32
+
33
+ $ gem install sentry-reddit
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2015 Alexander Persson
38
+
39
+ See LICENSE.txt for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,126 @@
1
+ require 'cinch'
2
+ require 'redditkit'
3
+ require 'twitter-text'
4
+ require 'uri'
5
+ require "sentry/helper"
6
+
7
+ module Cinch
8
+ module Plugins
9
+ module Sentry
10
+ class Reddit
11
+ include Cinch::Plugin
12
+ include Twitter::Extractor
13
+
14
+ # Fetch all github links
15
+ listen_to :channel
16
+
17
+ def initialize(*)
18
+ super
19
+
20
+ # Sign in
21
+ RedditKit.sign_in config['username'], config['password']
22
+ end
23
+
24
+ def listen(m)
25
+ # Make sure we are logged in
26
+ if not RedditKit.signed_in?
27
+ # Sign in again
28
+ RedditKit.sign_in config['username'], config['password']
29
+ end
30
+
31
+ # Exctract urls
32
+ urls = extract_urls(m.message)
33
+
34
+ # Go through all links
35
+ urls.each do |url|
36
+ # Parse the url
37
+ uri = URI.parse(URI.escape(url.to_url))
38
+
39
+ # We only handle GitHub links
40
+ case uri.host
41
+ when "www.reddit.com", "reddit.com", "redd.it", "www.redd.it"
42
+ begin
43
+ if not uri.path.to_s.empty?
44
+ # Split the path by forward slash
45
+ split = uri.path.split "/"
46
+
47
+ # Check if we have a link to a sub-reddit or a user
48
+ case split[1]
49
+ when "r", "tb"
50
+ # We have a link to a sub-reddit
51
+ if split[3].nil? and not split[2].nil?
52
+ # Fetch the information about the subreddit
53
+ subreddit = RedditKit.subreddit(split[2])
54
+
55
+ # Reply with the information
56
+ m.reply("[%s] %s (subscribers: %s) (%s)" % [
57
+ Format(:green, "Reddit"),
58
+ Format(:bold, subreddit.title),
59
+ Format(:teal, subreddit.subscribers.to_s),
60
+ Format(if not subreddit.nsfw? then :green else :red end,
61
+ if not subreddit.nsfw? then "SFW" else "NSFW" end)])
62
+
63
+ # We have a link to a thread
64
+ elsif (split[3] == "comments" and not split[4].nil?) or (split[3] != "comments" and split[4].nil?)
65
+ # Fetch the thread id
66
+ id = if split[4].nil? then split[3] else split[4] end
67
+
68
+ # Fetch the information about the thread
69
+ thread = RedditKit.link("t3_" + id)
70
+
71
+ # Reply with the information
72
+ m.reply("[%s][%s] %s (upvotes: %s) (comments: %s) (link: %s) (%s)" % [
73
+ Format(:green, "Reddit"),
74
+ Format(:blue, thread.author),
75
+ Format(:bold, thread.title),
76
+ Format(:orange, thread.upvotes.to_s),
77
+ Format(:teal, thread.total_comments.to_s),
78
+ Format(:underline, thread.short_link),
79
+ Format(if not thread.nsfw? then :green else :red end,
80
+ if not thread.nsfw? then "SFW" else "NSFW" end)])
81
+ end
82
+ when "u"
83
+ # Fetch the information about the user
84
+ user = RedditKit.user(split[2])
85
+
86
+ # Reply with the information
87
+ m.reply("[%s] %s (comment karma: %s) (link karma: %s)" % [
88
+ Format(:green, "Reddit"),
89
+ Format(:bold, user.name),
90
+ Format(:orange, user.comment_karma.to_s),
91
+ Format(:orange, user.link_karma.to_s)])
92
+ else
93
+ # We have a short-link for a thread
94
+
95
+ # Fetch the information about the thread
96
+ thread = RedditKit.link("t3_" + split[1])
97
+
98
+ # Reply with the information
99
+ m.reply("[%s][%s] %s (upvotes: %s) (comments: %s) (link: %s) (%s)" % [
100
+ Format(:green, "Reddit"),
101
+ Format(:blue, thread.author),
102
+ Format(:bold, thread.title),
103
+ Format(:orange, thread.upvotes.to_s),
104
+ Format(:teal, thread.total_comments.to_s),
105
+ Format(:underline, thread.short_link),
106
+ Format(if not thread.nsfw? then :green else :red end,
107
+ if not thread.nsfw? then "SFW" else "NSFW" end)])
108
+ end
109
+ end
110
+ rescue Exception => e
111
+ # Log the exception
112
+ puts e
113
+
114
+ # Send back error message
115
+ m.reply("[%s] %s" % [
116
+ Format(:green, "LINK"),
117
+ Format(:bold, "reddit: the frontpage of the internet")
118
+ ])
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "sentry-reddit"
5
+ gem.version = File.new("VERSION", 'r').read.chomp
6
+ gem.summary = %q{Parses messages for reddit links then replies with information about the link}
7
+ gem.license = "MIT"
8
+ gem.authors = ["jRiddick"]
9
+ gem.email = "apersson.93@gmail.com"
10
+ gem.homepage = "https://rubygems.org/gems/sentry-reddit"
11
+
12
+ gem.files = `git ls-files`.split($/)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ['lib']
16
+
17
+ gem.add_development_dependency 'bundler', '~> 1.0'
18
+ gem.add_development_dependency 'rake', '~> 0.8'
19
+
20
+ gem.add_dependency "cinch", "~> 2.0"
21
+ gem.add_dependency "redditkit", "~> 1.0"
22
+ gem.add_dependency "twitter-text", "~> 1.13"
23
+ gem.add_dependency "sentry-helper", "~> 0.1.0"
24
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentry-reddit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jRiddick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cinch
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redditkit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: twitter-text
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sentry-helper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ description:
98
+ email: apersson.93@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ChangeLog.rdoc
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - VERSION
109
+ - lib/cinch/plugins/sentry/reddit.rb
110
+ - sentry-reddit.gemspec
111
+ homepage: https://rubygems.org/gems/sentry-reddit
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Parses messages for reddit links then replies with information about the
135
+ link
136
+ test_files: []