reddit_bot 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/reddit_bot.rb +63 -21
- data/reddit_bot.gemspec +9 -13
- metadata +12 -74
- data/Gemfile +0 -5
- data/README.md +0 -101
- data/Rakefile +0 -6
- data/examples/.bashrc +0 -2
- data/examples/.gitignore +0 -2
- data/examples/Gemfile.lock +0 -17
- data/examples/boilerplate.rb +0 -12
- data/examples/councilofricks/Gemfile +0 -4
- data/examples/councilofricks/Gemfile.lock +0 -17
- data/examples/councilofricks/main.rb +0 -58
- data/examples/cptflairbot3/.bashrc +0 -1
- data/examples/cptflairbot3/Code.gs +0 -13
- data/examples/cptflairbot3/Gemfile +0 -5
- data/examples/cptflairbot3/Gemfile.lock +0 -74
- data/examples/cptflairbot3/app.js +0 -40
- data/examples/cptflairbot3/casual/casualpokemontrades.htm +0 -910
- data/examples/cptflairbot3/casual/script.js +0 -55
- data/examples/cptflairbot3/casual/style.css +0 -1099
- data/examples/cptflairbot3/log.htm +0 -1
- data/examples/cptflairbot3/main.rb +0 -62
- data/examples/cptflairbot3/package.json +0 -6
- data/examples/cptflairbot3/pubsub.rb +0 -30
- data/examples/cptflairbot3/update_gas_hook_secret.rb +0 -4
- data/examples/devflairbot/Gemfile +0 -6
- data/examples/devflairbot/Gemfile.lock +0 -74
- data/examples/devflairbot/main.rb +0 -81
- data/examples/get_dimensions.rb +0 -212
- data/examples/iostroubleshooting/Gemfile +0 -5
- data/examples/iostroubleshooting/Gemfile.lock +0 -16
- data/examples/iostroubleshooting/main.rb +0 -36
- data/examples/johnnymarr/Gemfile +0 -3
- data/examples/johnnymarr/Gemfile.lock +0 -17
- data/examples/johnnymarr/main.rb +0 -54
- data/examples/johnnymarr/twitter.rb +0 -80
- data/examples/largeimages/Gemfile +0 -11
- data/examples/largeimages/Gemfile.lock +0 -107
- data/examples/largeimages/main.rb +0 -167
- data/examples/largeimagesreview/Gemfile +0 -4
- data/examples/largeimagesreview/Gemfile.lock +0 -15
- data/examples/largeimagesreview/main.rb +0 -43
- data/examples/mlgtv/Gemfile +0 -4
- data/examples/mlgtv/Gemfile.lock +0 -23
- data/examples/mlgtv/channels.txt +0 -127
- data/examples/mlgtv/main.rb +0 -160
- data/examples/net_http_utils.rb +0 -148
- data/examples/oneplus/Gemfile +0 -5
- data/examples/oneplus/Gemfile.lock +0 -26
- data/examples/oneplus/main.rb +0 -43
- data/examples/realtimeww2/.bashrc +0 -1
- data/examples/realtimeww2/Gemfile +0 -3
- data/examples/realtimeww2/Gemfile.lock +0 -17
- data/examples/realtimeww2/main.rb +0 -129
- data/examples/sexypizza/Gemfile +0 -3
- data/examples/sexypizza/Gemfile.lock +0 -15
- data/examples/sexypizza/main.rb +0 -33
- data/examples/wallpaper/Gemfile +0 -5
- data/examples/wallpaper/Gemfile.lock +0 -33
- data/examples/wallpaper/main.rb +0 -27
- data/examples/yayornay/Gemfile +0 -3
- data/examples/yayornay/Gemfile.lock +0 -15
- data/examples/yayornay/main.rb +0 -33
- data/lib/reddit_bot/version.rb +0 -3
data/examples/oneplus/Gemfile
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://gist.github.com/97549ceb58d21e1fcbc0e6cdaf92fce8.git
|
3
|
-
revision: 54c47ab3f9665f3e35a8e94fdd267e3743c736a9
|
4
|
-
specs:
|
5
|
-
net_http_utils (0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
addressable (2.4.0)
|
11
|
-
fastimage (1.7.0)
|
12
|
-
addressable (~> 2.3, >= 2.3.5)
|
13
|
-
json (2.0.2)
|
14
|
-
reddit_bot (1.1.8)
|
15
|
-
json
|
16
|
-
|
17
|
-
PLATFORMS
|
18
|
-
ruby
|
19
|
-
|
20
|
-
DEPENDENCIES
|
21
|
-
fastimage (= 1.7.0)
|
22
|
-
net_http_utils (= 0)!
|
23
|
-
reddit_bot (~> 1.1.5)
|
24
|
-
|
25
|
-
BUNDLED WITH
|
26
|
-
1.13.1
|
data/examples/oneplus/main.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
|
3
|
-
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
|
4
|
-
SUBREDDIT = "oneplus"
|
5
|
-
|
6
|
-
if Gem::Platform.local.os == "darwin"
|
7
|
-
require_relative "../../../../dimensioner/get_dimensions"
|
8
|
-
else
|
9
|
-
require_relative "#{Dir.home}/get_dimensions"
|
10
|
-
end
|
11
|
-
|
12
|
-
checked = []
|
13
|
-
loop do
|
14
|
-
Hearthbeat.beat "u_oneplus_mod_r_oneplus", 310 unless Gem::Platform.local.os == "darwin"
|
15
|
-
puts "LOOP #{Time.now}"
|
16
|
-
|
17
|
-
BOT.json(:get, "/r/#{SUBREDDIT}/new")["data"]["children"].each do |post|
|
18
|
-
id, url, title, subreddit = post["data"].values_at(*%w{ id url title subreddit })
|
19
|
-
next if checked.include? id
|
20
|
-
checked.push id
|
21
|
-
redd_it = "https://redd.it/#{id}"
|
22
|
-
next puts "skipped #{url} from #{redd_it}" if :skipped == _ = GetDimensions::get_dimensions(url)
|
23
|
-
next puts "unable #{url} from #{redd_it}" unless _
|
24
|
-
width, height, * = _
|
25
|
-
result = ([1080, 1920] != resolution = [width, height])
|
26
|
-
puts "#{result} #{id} [#{resolution}] #{title} #{url}"
|
27
|
-
next if result
|
28
|
-
|
29
|
-
### delete
|
30
|
-
BOT.json :post, "/api/remove",
|
31
|
-
id: "t3_#{id}",
|
32
|
-
spam: false
|
33
|
-
### modmail
|
34
|
-
BOT.json :post, "/api/compose",
|
35
|
-
subject: "possible screenshot detected",
|
36
|
-
text: "please, investigate: #{redd_it}",
|
37
|
-
to: "/r/#{SUBREDDIT}"
|
38
|
-
|
39
|
-
end or puts "/r/#{SUBREDDIT} seems to be 403-ed"
|
40
|
-
|
41
|
-
puts "END LOOP #{Time.now}"
|
42
|
-
sleep 300
|
43
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
echo "TEST=_ bundle exec ruby main.rb"
|
@@ -1,129 +0,0 @@
|
|
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
|
-
TWITTER = "RealTimeWWII"
|
13
|
-
|
14
|
-
tweet2titleNtext = lambda do |tweet|
|
15
|
-
pp tweet if ENV["TEST"]
|
16
|
-
text = ""
|
17
|
-
contains_media = false
|
18
|
-
up = ->s{ s.split.map{ |w| "^#{w}" }.join " " }
|
19
|
-
if tweet["extended_entities"] && !tweet["extended_entities"]["media"].empty?
|
20
|
-
contains_media = true
|
21
|
-
tweet["extended_entities"]["media"].each_with_index do |media, i|
|
22
|
-
text.concat "* [Image #{i + 1}](#{media["media_url_https"]})\n\n"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
if !tweet["entities"]["urls"].empty?
|
26
|
-
contains_media = true
|
27
|
-
tweet["entities"]["urls"].each_with_index do |url, i|
|
28
|
-
text.concat "* [Link #{i + 1}](#{url["expanded_url"]})\n\n"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
text.concat "^- #{
|
32
|
-
up[tweet["user"]["name"]]
|
33
|
-
} [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [#{
|
34
|
-
up[Date.parse(tweet["created_at"]).strftime "%B %-d, %Y"]
|
35
|
-
}](https://twitter.com/#{TWITTER}/status/#{tweet["id"]})"
|
36
|
-
require "cgi"
|
37
|
-
[CGI::unescapeHTML(tweet["full_text"]).sub(/( https:\/\/t\.co\/[0-9a-zA-Z]{10})*\z/, ""), text, contains_media]
|
38
|
-
end
|
39
|
-
[
|
40
|
-
[905764294687633408, true, "The Polish government & military high command is now evacuating Warsaw for Brest, 120 miles east: German armies are too close to the capital", "* [Image 1](https://pbs.twimg.com/media/DJHq71BXYAA6KJ0.jpg)\n\n" "^- ^WW2 ^Tweets ^from ^1941 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^""September ^7, ^2017](https://twitter.com/#{TWITTER}/status/905764294687633408)"],
|
41
|
-
[915534673471733760, true, "In east Poland (now Soviet Ukraine) industry & farms to be collectivised, political parties banned, aristocrats & capitalists \"re-educated\".", "* [Image 1](https://pbs.twimg.com/media/DLSh2J9W4AACcOG.jpg)\n\n* [Image 2](https://pbs.twimg.com/media/DLSh4sKX0AEBaXq.jpg)\n\n^- ^WW2 ^Tweets ^from ^1941 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^" "October ^4, ^2017](https://twitter.com/#{TWITTER}/status/915534673471733760)"],
|
42
|
-
[915208866408824832, true, "For 1st time, RAF planes dropping propaganda leaflets on Berlin itself, entitled \"Germans: these are your leaders!\"", "* [Image 1](https://pbs.twimg.com/media/DLN5jJ-XkAEUz9M.jpg)\n\n* [Link 1](https://www.psywar.org/product_1939EH158.php)\n\n" "^- ^WW2 ^Tweets ^from ^1941 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^" "October ^3, ^2017](https://twitter.com/#{TWITTER}/status/915208866408824832)"],
|
43
|
-
[914577848891006978, true, "\"In Poland, Russia pursued a cold policy of selfinterest. But clearly necessary for Russia… against Nazi menace.\"", "* [Link 1](https://www.youtube.com/watch?v=ygmP5A3n2JA)\n\n" "^- ^WW2 ^Tweets ^from ^1941 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^" "October ^1, ^2017](https://twitter.com/#{TWITTER}/status/914577848891006978)"],
|
44
|
-
[926581977372942336, false, "Finland rejects Soviet demand to surrender land near Leningrad & give Red Navy base in Hanko; Soviets now claim Finns' manner \"warlike\".", "^- ^WW2 ^Tweets ^from ^1941 [^\\(@#{TWITTER}\\)](https://twitter.com/#{TWITTER}) ^| [^" "November ^3, ^2017](https://twitter.com/#{TWITTER}/status/926581977372942336)"],
|
45
|
-
].each do |id, contains_media_, title_, text_|
|
46
|
-
title, text, contains_media = tweet2titleNtext[ JSON.load NetHTTPUtils.request_data(
|
47
|
-
"https://api.twitter.com/1.1/statuses/show.json",
|
48
|
-
form: { id: id, tweet_mode: "extended" },
|
49
|
-
header: { Authorization: "Bearer #{TWITTER_ACCESS_TOKEN}" },
|
50
|
-
) ]
|
51
|
-
unless contains_media_ == contains_media
|
52
|
-
puts "expected: #{contains_media_}"
|
53
|
-
puts "got: #{contains_media}"
|
54
|
-
abort "CONTAINS_MEDIA ERROR"
|
55
|
-
end
|
56
|
-
unless title_ == title
|
57
|
-
puts "expected:\n#{title_.inspect}"
|
58
|
-
puts "got:\n#{title.inspect}"
|
59
|
-
abort "TITLE FORMATTING ERROR"
|
60
|
-
end
|
61
|
-
unless text_ == text
|
62
|
-
puts "expected:\n#{text_.inspect}"
|
63
|
-
puts "got:\n#{text.inspect}"
|
64
|
-
abort "TEXT FORMATTING ERROR"
|
65
|
-
end
|
66
|
-
if ENV["TEST_POST"]
|
67
|
-
pp BOT.json :post, "/api/submit", {
|
68
|
-
sr: "RealTimeWW2_TEST",
|
69
|
-
kind: "self",
|
70
|
-
title: title,
|
71
|
-
text: text,
|
72
|
-
}.tap{ |h| h.merge!({ flair_id: BOT.json(:get, "/r/RealTimeWW2_TEST/api/link_flair").find{ |flair|
|
73
|
-
flair["text"] == "Contains Media"
|
74
|
-
}["id"] }) if contains_media }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
abort "OK" if ENV["TEST"]
|
78
|
-
|
79
|
-
loop do
|
80
|
-
id = BOT.new_posts.find do |post|
|
81
|
-
/\(https:\/\/twitter\.com\/#{TWITTER}\/status\/(\d{18,})\)/i =~ post["selftext"] and break $1
|
82
|
-
end.to_i
|
83
|
-
fail "no tweets found in subreddit" if id.zero? unless %w{ RealTimeWW2_TEST }.include? SUBREDDIT
|
84
|
-
|
85
|
-
fail unless flair = BOT.json(:get, "/r/#{SUBREDDIT}/api/link_flair").find do |flair|
|
86
|
-
flair["text"] == "Contains Media"
|
87
|
-
end
|
88
|
-
|
89
|
-
timeout = 1
|
90
|
-
JSON.load( begin
|
91
|
-
NetHTTPUtils.request_data(
|
92
|
-
"https://api.twitter.com/1.1/statuses/user_timeline.json",
|
93
|
-
form: { screen_name: TWITTER, count: 200, tweet_mode: "extended" },
|
94
|
-
header: { Authorization: "Bearer #{TWITTER_ACCESS_TOKEN}" }
|
95
|
-
) do |res|
|
96
|
-
next unless res.key? "x-rate-limit-remaining"
|
97
|
-
remaining = res.fetch("x-rate-limit-remaining").to_i
|
98
|
-
next if 100 < remaining
|
99
|
-
t = (res.fetch("x-rate-limit-reset").to_i - Time.now.to_i + 1).fdiv remaining
|
100
|
-
puts "sleep #{t}"
|
101
|
-
sleep t
|
102
|
-
end
|
103
|
-
rescue NetHTTPUtils::Error => e
|
104
|
-
fail if e.code != 503
|
105
|
-
sleep timeout
|
106
|
-
timeout *= 2
|
107
|
-
retry
|
108
|
-
end ).reverse_each do |tweet|
|
109
|
-
next if tweet["id"] <= id
|
110
|
-
# next unless tweet["id"] == 905724018996772865 # two media files
|
111
|
-
title, text, contains_media = tweet2titleNtext[tweet]
|
112
|
-
result = BOT.json :post, "/api/submit", {
|
113
|
-
sr: SUBREDDIT,
|
114
|
-
kind: "self",
|
115
|
-
title: title,
|
116
|
-
text: text,
|
117
|
-
}.tap{ |h| h.merge!({ flair_id: flair["id"] }) if contains_media }
|
118
|
-
pp result
|
119
|
-
if result["json"]["errors"].empty?
|
120
|
-
abort if ENV["ONCE"]
|
121
|
-
next
|
122
|
-
end
|
123
|
-
fail unless result["json"]["errors"].map(&:first) == ["ALREADY_SUB"]
|
124
|
-
puts "ALREADY_SUB error for #{tweet["id"]}"
|
125
|
-
end
|
126
|
-
|
127
|
-
puts "END LOOP #{Time.now}"
|
128
|
-
sleep 300
|
129
|
-
end
|
data/examples/sexypizza/Gemfile
DELETED
data/examples/sexypizza/main.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
|
3
|
-
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
|
4
|
-
SUBREDDIT = "sexypizza"
|
5
|
-
|
6
|
-
loop do
|
7
|
-
puts "LOOP #{Time.now}"
|
8
|
-
|
9
|
-
flairs = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", {limit: 1000})["users"]
|
10
|
-
|
11
|
-
text = \
|
12
|
-
"**Vote with your flair!**\n\n" +
|
13
|
-
"Type of pizza | Number of lovers\n" +
|
14
|
-
"--------------|-----------------\n" +
|
15
|
-
flairs.
|
16
|
-
group_by{ |flair| flair["flair_text"] }.
|
17
|
-
sort_by{ |_, group| -group.size }.
|
18
|
-
map{ |flair, group| "#{flair} | #{group.size}" }.
|
19
|
-
join("\n")
|
20
|
-
|
21
|
-
if text != BOT.json(:get, "/r/#{SUBREDDIT}/wiki/toppings")["data"]["content_md"]
|
22
|
-
puts "editing wiki page '/r/#{SUBREDDIT}/wiki/toppings'"
|
23
|
-
pp text
|
24
|
-
p BOT.json :post,
|
25
|
-
"/r/#{SUBREDDIT}/api/wiki/edit",
|
26
|
-
page: "toppings",
|
27
|
-
content: text
|
28
|
-
else
|
29
|
-
puts "nothing to change"
|
30
|
-
end
|
31
|
-
|
32
|
-
sleep 3600
|
33
|
-
end
|
data/examples/wallpaper/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.5.2)
|
5
|
-
public_suffix (>= 2.0.2, < 4.0)
|
6
|
-
directlink (0.0.4.7)
|
7
|
-
addressable
|
8
|
-
fastimage (~> 2.1.3)
|
9
|
-
kramdown
|
10
|
-
nokogiri
|
11
|
-
reddit_bot (~> 1.6.13)
|
12
|
-
fastimage (2.1.5)
|
13
|
-
json (2.1.0)
|
14
|
-
kramdown (1.17.0)
|
15
|
-
mini_portile2 (2.4.0)
|
16
|
-
nethttputils (0.2.5.1)
|
17
|
-
nokogiri (1.10.4)
|
18
|
-
mini_portile2 (~> 2.4.0)
|
19
|
-
public_suffix (2.0.5)
|
20
|
-
reddit_bot (1.6.13)
|
21
|
-
json
|
22
|
-
nethttputils (~> 0.2.5.1)
|
23
|
-
|
24
|
-
PLATFORMS
|
25
|
-
ruby
|
26
|
-
|
27
|
-
DEPENDENCIES
|
28
|
-
directlink
|
29
|
-
nokogiri (~> 1.10.4)
|
30
|
-
public_suffix (< 3.0)
|
31
|
-
|
32
|
-
BUNDLED WITH
|
33
|
-
2.0.2
|
data/examples/wallpaper/main.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
|
3
|
-
BOT = RedditBot::Bot.new YAML.load_file "secrets.yaml"
|
4
|
-
SUBREDDIT = "wallpaper"
|
5
|
-
|
6
|
-
require "directlink"
|
7
|
-
|
8
|
-
checked = []
|
9
|
-
loop do
|
10
|
-
puts "LOOP #{Time.now}"
|
11
|
-
|
12
|
-
BOT.json(:get, "/r/#{SUBREDDIT}/new")["data"]["children"].each do |post|
|
13
|
-
id, url, title, subreddit = post["data"].values_at(*%w{ id url title subreddit })
|
14
|
-
next if checked.include? id
|
15
|
-
checked.push id
|
16
|
-
t = DirectLink url
|
17
|
-
(t.is_a?(Array) ? t : [t]).each do |s|
|
18
|
-
resolution = "#{s.width}x#{s.height}"
|
19
|
-
result = title[/\s*\[?#{s.width}\s*[*x×]\s*#{s.height}\]?\s*/i]
|
20
|
-
puts "#{!!result} #{id} [#{resolution}] #{title} #{s.url}"
|
21
|
-
BOT.report "true resolution is #{resolution}", "t3_#{id}" unless result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
puts "END LOOP #{Time.now}"
|
26
|
-
sleep 60
|
27
|
-
end
|
data/examples/yayornay/Gemfile
DELETED
data/examples/yayornay/main.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative "../boilerplate"
|
2
|
-
|
3
|
-
SUBREDDIT = "yayornay"
|
4
|
-
BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), subreddit: SUBREDDIT
|
5
|
-
|
6
|
-
loop do
|
7
|
-
puts "LOOP #{Time.now}"
|
8
|
-
|
9
|
-
BOT.each_new_post_with_top_level_comments do |post, comments|
|
10
|
-
yay = []
|
11
|
-
nay = []
|
12
|
-
comments.each do |comment|
|
13
|
-
yay |= [comment["author"]] if comment["body"][/\A\s*yay/i]
|
14
|
-
yay |= [comment["author"]] if comment["body"][/\A\s*yea/i]
|
15
|
-
nay |= [comment["author"]] if comment["body"][/\A\s*nay/i]
|
16
|
-
end
|
17
|
-
p [post["id"], yay, nay] if Gem::Platform.local.os == "darwin"
|
18
|
-
yay, nay = [(yay - nay).size, (nay - yay).size]
|
19
|
-
next if 0 == total = yay + nay
|
20
|
-
proper_class = yay > nay ? "yay" : yay < nay ? "nay" : "none"
|
21
|
-
proper_text = "#{(100 * yay / total).round}% Yay"
|
22
|
-
next if [proper_class, proper_text] == [post["link_flair_css_class"], post["link_flair_text"]]
|
23
|
-
puts "setting #{[proper_class, proper_text]} to #{post["name"]}"
|
24
|
-
if _ = BOT.set_post_flair(post, proper_class, proper_text)
|
25
|
-
fail _.inspect unless _ = {"json"=>{"errors"=>[]}}
|
26
|
-
else
|
27
|
-
# 403
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
puts "END LOOP #{Time.now}"
|
32
|
-
sleep 300
|
33
|
-
end
|
data/lib/reddit_bot/version.rb
DELETED