reddit_bot 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/examples/boilerplate.rb +2 -2
- data/examples/councilofricks/Gemfile +2 -2
- data/examples/councilofricks/Gemfile.lock +8 -7
- data/examples/councilofricks/main.rb +24 -13
- data/examples/cptflairbot3/.bashrc +1 -0
- data/examples/cptflairbot3/Code.gs +13 -0
- data/examples/cptflairbot3/Gemfile +2 -1
- data/examples/cptflairbot3/Gemfile.lock +64 -4
- data/examples/cptflairbot3/app.js +40 -0
- data/examples/cptflairbot3/casual/casualpokemontrades.htm +910 -0
- data/examples/cptflairbot3/casual/script.js +55 -0
- data/examples/cptflairbot3/casual/style.css +1099 -0
- data/examples/cptflairbot3/log.htm +1 -0
- data/examples/cptflairbot3/main.rb +31 -10
- data/examples/cptflairbot3/package.json +6 -0
- data/examples/cptflairbot3/pubsub.rb +30 -0
- data/examples/cptflairbot3/update_gas_hook_secret.rb +4 -0
- data/examples/devflairbot/Gemfile +1 -1
- data/examples/devflairbot/Gemfile.lock +3 -3
- data/examples/devflairbot/main.rb +1 -1
- data/examples/largeimages/Gemfile +5 -0
- data/examples/largeimages/Gemfile.lock +26 -0
- data/examples/largeimages/main.rb +183 -0
- data/examples/mlgtv/Gemfile +1 -1
- data/examples/mlgtv/Gemfile.lock +3 -3
- data/examples/mlgtv/channels.txt +110 -0
- data/examples/mlgtv/main.rb +67 -12
- data/examples/realtimeww2/Gemfile +4 -0
- data/examples/realtimeww2/Gemfile.lock +23 -0
- data/examples/realtimeww2/main.rb +82 -0
- data/examples/sexypizza/Gemfile +1 -1
- data/examples/sexypizza/Gemfile.lock +4 -4
- data/examples/wallpaper/Gemfile +1 -1
- data/examples/wallpaper/Gemfile.lock +3 -3
- data/examples/wallpaper/main.rb +1 -1
- data/examples/yayornay/Gemfile +1 -5
- data/examples/yayornay/Gemfile.lock +3 -3
- data/examples/yayornay/main.rb +1 -1
- data/lib/reddit_bot/version.rb +3 -0
- data/lib/reddit_bot.rb +3 -7
- data/reddit_bot.gemspec +1 -4
- metadata +20 -2
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative "../boilerplate"
|
2
|
+
|
3
|
+
require "nethttputils"
|
4
|
+
TWITTER_ACCESS_TOKEN = JSON.load(
|
5
|
+
NetHTTPUtils.request_data "https://api.twitter.com/oauth2/token", :post,
|
6
|
+
auth: File.read("twitter.token").split,
|
7
|
+
form: {grant_type: :client_credentials}
|
8
|
+
)["access_token"]
|
9
|
+
|
10
|
+
SUBREDDIT = "RealTimeWW2"
|
11
|
+
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: SUBREDDIT
|
12
|
+
|
13
|
+
TWITTER = "RealTimeWWII"
|
14
|
+
tweet2text = lambda do |tweet|
|
15
|
+
text = ""
|
16
|
+
contains_media = false
|
17
|
+
up = ->s{ s.split.map{ |w| "^#{w}" }.join " " }
|
18
|
+
if tweet["entities"]["media"]
|
19
|
+
contains_media = true
|
20
|
+
tweet["entities"]["media"].each_with_index do |media, i|
|
21
|
+
text.concat "* [Image #{i + 1}](#{media["media_url_https"]})\n\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
text.concat "^- #{
|
25
|
+
up[tweet["user"]["name"]]
|
26
|
+
} [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [#{
|
27
|
+
up[Date.parse(tweet["created_at"]).strftime "%B %-d, %Y"]
|
28
|
+
}](https://twitter.com/#{TWITTER}/status/#{tweet["id"]})"
|
29
|
+
[text, contains_media]
|
30
|
+
end
|
31
|
+
test = "* [Image 1](https://pbs.twimg.com/media/DJHq71BXYAA6KJ0.jpg)\n\n^- ^WW2 ^Tweets ^from ^1939 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^September ^7, ^2017](https://twitter.com/#{TWITTER}/status/905764294687633408)"
|
32
|
+
unless test == temp = ( tweet2text.call JSON.load NetHTTPUtils.request_data(
|
33
|
+
"https://api.twitter.com/1.1/statuses/show.json?id=905764294687633408&tweet_mode=extended",
|
34
|
+
header: { Authorization: "Bearer #{TWITTER_ACCESS_TOKEN}" }
|
35
|
+
) ).first
|
36
|
+
puts "expected:\n#{test.inspect}"
|
37
|
+
puts "got:\n#{temp.inspect}"
|
38
|
+
abort "FORMATTING ERROR"
|
39
|
+
end
|
40
|
+
abort "OK" if ENV["TEST"]
|
41
|
+
|
42
|
+
require "cgi"
|
43
|
+
loop do
|
44
|
+
id = BOT.new_posts.find do |post|
|
45
|
+
/\(https:\/\/twitter\.com\/#{TWITTER}\/status\/(\d{18,})\)/i =~ post["selftext"] and break $1
|
46
|
+
end.to_i
|
47
|
+
fail "no tweets found in subreddit" if id.zero? unless %w{ RealTimeWW2_TEST }.include? SUBREDDIT
|
48
|
+
|
49
|
+
fail unless flair = BOT.json(:get, "/r/#{SUBREDDIT}/api/link_flair").find do |flair|
|
50
|
+
flair["text"] == "Contains Media"
|
51
|
+
end
|
52
|
+
|
53
|
+
JSON.load( NetHTTPUtils.request_data(
|
54
|
+
"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=#{TWITTER}&count=200&tweet_mode=extended",
|
55
|
+
header: { Authorization: "Bearer #{TWITTER_ACCESS_TOKEN}" }
|
56
|
+
) do |res|
|
57
|
+
next unless res.key? "x-rate-limit-remaining"
|
58
|
+
remaining = res.fetch("x-rate-limit-remaining").to_i
|
59
|
+
next if 100 < remaining
|
60
|
+
t = (res.fetch("x-rate-limit-reset").to_i - Time.now.to_i + 1).fdiv remaining
|
61
|
+
puts "sleep #{t}"
|
62
|
+
sleep t
|
63
|
+
end ).reverse_each do |tweet|
|
64
|
+
next if tweet["id"] <= id
|
65
|
+
# next unless tweet["id"] == 905724018996772865 # two media files
|
66
|
+
# tweet["entities"]["urls"].first["url"],
|
67
|
+
text, contains_media = tweet2text[tweet]
|
68
|
+
result = BOT.json :post, "/api/submit", {
|
69
|
+
sr: SUBREDDIT,
|
70
|
+
kind: "self",
|
71
|
+
title: CGI::unescapeHTML(tweet["full_text"]).sub(/ https:\/\/t\.co\/[0-9a-zA-Z]{10}\z/, ""),
|
72
|
+
text: text,
|
73
|
+
}.tap{ |h| h.merge!({ flair_id: flair["id"] }) if contains_media }
|
74
|
+
pp result
|
75
|
+
next if result["json"]["errors"].empty?
|
76
|
+
fail unless result["json"]["errors"].map(&:first) == ["ALREADY_SUB"]
|
77
|
+
puts "ALREADY_SUB error for #{tweet["id"]}"
|
78
|
+
end
|
79
|
+
|
80
|
+
puts "END LOOP #{Time.now}"
|
81
|
+
sleep 300
|
82
|
+
end
|
data/examples/sexypizza/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
json (1.
|
5
|
-
reddit_bot (1.
|
4
|
+
json (2.1.0)
|
5
|
+
reddit_bot (1.3.0)
|
6
6
|
json
|
7
7
|
|
8
8
|
PLATFORMS
|
9
9
|
ruby
|
10
10
|
|
11
11
|
DEPENDENCIES
|
12
|
-
reddit_bot (~> 1.
|
12
|
+
reddit_bot (~> 1.3.0)
|
13
13
|
|
14
14
|
BUNDLED WITH
|
15
|
-
1.
|
15
|
+
1.13.1
|
data/examples/wallpaper/Gemfile
CHANGED
@@ -10,8 +10,8 @@ GEM
|
|
10
10
|
addressable (2.3.8)
|
11
11
|
fastimage (1.7.0)
|
12
12
|
addressable (~> 2.3, >= 2.3.5)
|
13
|
-
json (2.0
|
14
|
-
reddit_bot (1.
|
13
|
+
json (2.1.0)
|
14
|
+
reddit_bot (1.3.0)
|
15
15
|
json
|
16
16
|
|
17
17
|
PLATFORMS
|
@@ -20,7 +20,7 @@ PLATFORMS
|
|
20
20
|
DEPENDENCIES
|
21
21
|
fastimage (= 1.7.0)
|
22
22
|
net_http_utils (= 0)!
|
23
|
-
reddit_bot (~> 1.
|
23
|
+
reddit_bot (~> 1.3.0)
|
24
24
|
|
25
25
|
BUNDLED WITH
|
26
26
|
1.13.1
|
data/examples/wallpaper/main.rb
CHANGED
data/examples/yayornay/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
json (2.0
|
5
|
-
reddit_bot (1.
|
4
|
+
json (2.1.0)
|
5
|
+
reddit_bot (1.3.0)
|
6
6
|
json
|
7
7
|
|
8
8
|
PLATFORMS
|
9
9
|
ruby
|
10
10
|
|
11
11
|
DEPENDENCIES
|
12
|
-
reddit_bot (~> 1.
|
12
|
+
reddit_bot (~> 1.3.0)
|
13
13
|
|
14
14
|
BUNDLED WITH
|
15
15
|
1.13.1
|
data/examples/yayornay/main.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "../boilerplate"
|
2
2
|
|
3
3
|
SUBREDDIT = "yayornay"
|
4
|
-
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"),
|
4
|
+
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: SUBREDDIT
|
5
5
|
|
6
6
|
loop do
|
7
7
|
Hearthbeat.beat "u_gotfan247_r_yayornay", 310 unless Gem::Platform.local.os == "darwin"
|
data/lib/reddit_bot.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
STDOUT.sync = true
|
2
|
-
|
3
2
|
require "pp"
|
4
3
|
|
5
4
|
require "net/http"
|
6
5
|
require "openssl"
|
7
6
|
require "json"
|
8
7
|
|
9
|
-
|
8
|
+
require_relative "reddit_bot/version"
|
10
9
|
module RedditBot
|
11
|
-
VERSION = "1.3.0" # :nodoc:
|
12
|
-
|
13
10
|
class Bot
|
14
11
|
|
15
12
|
# bot's Reddit username; set via constructor parameter secrets[:login]
|
@@ -117,7 +114,7 @@ module RedditBot
|
|
117
114
|
result = cache.call(args){ json *args }
|
118
115
|
fail if result.keys != %w{ kind data }
|
119
116
|
fail if result["kind"] != "Listing"
|
120
|
-
fail if result["data"].keys != %w{ modhash children after before }
|
117
|
+
fail if result["data"].keys != %w{ modhash whitelist_status children after before }
|
121
118
|
result["data"]["children"].each do |post|
|
122
119
|
fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
|
123
120
|
e << post["data"]
|
@@ -170,7 +167,7 @@ module RedditBot
|
|
170
167
|
"User-Agent" => "bot/#{@username}/0.0.0 by /u/nakilon",
|
171
168
|
}, [@secrets[0], @secrets[1]]
|
172
169
|
unless @token_cached = response["access_token"]
|
173
|
-
fail "bot isn't a 'developer' of app at https://www.reddit.com/prefs/apps/" if response == {"error"=>"invalid_grant"}
|
170
|
+
fail "bot #{@username} isn't a 'developer' of app at https://www.reddit.com/prefs/apps/" if response == {"error"=>"invalid_grant"}
|
174
171
|
fail response.inspect
|
175
172
|
end
|
176
173
|
puts "new token is: #{@token_cached}"
|
@@ -289,5 +286,4 @@ module RedditBot
|
|
289
286
|
end
|
290
287
|
|
291
288
|
end
|
292
|
-
|
293
289
|
end
|
data/reddit_bot.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -40,25 +40,42 @@ files:
|
|
40
40
|
- examples/councilofricks/Gemfile
|
41
41
|
- examples/councilofricks/Gemfile.lock
|
42
42
|
- examples/councilofricks/main.rb
|
43
|
+
- examples/cptflairbot3/.bashrc
|
44
|
+
- examples/cptflairbot3/Code.gs
|
43
45
|
- examples/cptflairbot3/Gemfile
|
44
46
|
- examples/cptflairbot3/Gemfile.lock
|
47
|
+
- examples/cptflairbot3/app.js
|
48
|
+
- examples/cptflairbot3/casual/casualpokemontrades.htm
|
49
|
+
- examples/cptflairbot3/casual/script.js
|
50
|
+
- examples/cptflairbot3/casual/style.css
|
51
|
+
- examples/cptflairbot3/log.htm
|
45
52
|
- examples/cptflairbot3/main.rb
|
53
|
+
- examples/cptflairbot3/package.json
|
54
|
+
- examples/cptflairbot3/pubsub.rb
|
55
|
+
- examples/cptflairbot3/update_gas_hook_secret.rb
|
46
56
|
- examples/devflairbot/Gemfile
|
47
57
|
- examples/devflairbot/Gemfile.lock
|
48
58
|
- examples/devflairbot/main.rb
|
49
59
|
- examples/iostroubleshooting/Gemfile
|
50
60
|
- examples/iostroubleshooting/Gemfile.lock
|
51
61
|
- examples/iostroubleshooting/main.rb
|
62
|
+
- examples/largeimages/Gemfile
|
63
|
+
- examples/largeimages/Gemfile.lock
|
64
|
+
- examples/largeimages/main.rb
|
52
65
|
- examples/largeimagesreview/Gemfile
|
53
66
|
- examples/largeimagesreview/Gemfile.lock
|
54
67
|
- examples/largeimagesreview/main.rb
|
55
68
|
- examples/mlgtv/Gemfile
|
56
69
|
- examples/mlgtv/Gemfile.lock
|
70
|
+
- examples/mlgtv/channels.txt
|
57
71
|
- examples/mlgtv/main.rb
|
58
72
|
- examples/net_http_utils.rb
|
59
73
|
- examples/oneplus/Gemfile
|
60
74
|
- examples/oneplus/Gemfile.lock
|
61
75
|
- examples/oneplus/main.rb
|
76
|
+
- examples/realtimeww2/Gemfile
|
77
|
+
- examples/realtimeww2/Gemfile.lock
|
78
|
+
- examples/realtimeww2/main.rb
|
62
79
|
- examples/sexypizza/Gemfile
|
63
80
|
- examples/sexypizza/Gemfile.lock
|
64
81
|
- examples/sexypizza/main.rb
|
@@ -69,6 +86,7 @@ files:
|
|
69
86
|
- examples/yayornay/Gemfile.lock
|
70
87
|
- examples/yayornay/main.rb
|
71
88
|
- lib/reddit_bot.rb
|
89
|
+
- lib/reddit_bot/version.rb
|
72
90
|
- reddit_bot.gemspec
|
73
91
|
homepage: https://github.com/Nakilon/reddit_bot
|
74
92
|
licenses:
|