reddit_bot 1.3.0 → 1.3.1
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/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 @@
|
|
1
|
+
<body style="margin: 0"><iframe style="width: 100vw; height: 100vh" src="https://docs.google.com/spreadsheets/d/1CmO0cxd4z1_37Fvo4WpPdyTqmd_HmCF_nD6PgeHuCAA/pubhtml?gid=0&single=true&widget=false&headers=false&chrome=false"></iframe></body>
|
@@ -1,20 +1,27 @@
|
|
1
|
-
require_relative
|
2
|
-
BOT = RedditBot::Bot.new YAML.load
|
1
|
+
require_relative "../boilerplate"
|
2
|
+
BOT = RedditBot::Bot.new YAML.load File.read "secrets.yaml"
|
3
|
+
|
4
|
+
require "gcplogger"
|
5
|
+
logger = GCPLogger.logger "cptflairbot3"
|
3
6
|
|
4
7
|
loop do
|
5
|
-
Hearthbeat.beat "u_CPTFlairBot3_r_casualpokemontrades", 70
|
8
|
+
Hearthbeat.beat "u_CPTFlairBot3_r_casualpokemontrades", 70 if Google::Cloud.env.compute_engine?
|
6
9
|
|
7
10
|
unread = BOT.json :get, "/message/unread"
|
8
11
|
unread["data"]["children"].each do |msg|
|
9
|
-
next
|
12
|
+
next logger.info "bad destination: #{msg["data"]["dest"]}" unless msg["data"]["dest"] == "CPTFlairBot3"
|
10
13
|
case msg["data"]["subject"]
|
11
14
|
when "casualpokemontrades"
|
12
|
-
unless /^(?<name>\S+)
|
13
|
-
|
15
|
+
unless /^(?<name>\S+( \S+)*) ?\n(?<id>\d\d\d\d-\d\d\d\d-\d\d\d\d)\n(?<css_class>\S+)$/ =~ msg["data"]["body"]
|
16
|
+
logger.info "invalid message for #{msg["data"]["subject"]}: %p" % msg["data"]["body"] unless Google::Cloud.env.compute_engine?
|
14
17
|
# puts "marking invalid message as read: %p" % msg["data"]["body"]
|
15
18
|
# BOT.json :post, "/api/read_message", {id: msg["data"]["name"]} unless Gem::Platform.local.os == "darwin"
|
16
19
|
next
|
17
20
|
end
|
21
|
+
if name.size > 50
|
22
|
+
logger.info "too large name: %p" % name unless Google::Cloud.env.compute_engine?
|
23
|
+
next
|
24
|
+
end
|
18
25
|
begin
|
19
26
|
BOT.json :post, "/r/#{msg["data"]["subject"]}/api/flair", {
|
20
27
|
name: msg["data"]["author"],
|
@@ -23,21 +30,35 @@ loop do
|
|
23
30
|
"relaxedpokemontrades" => "#{name} #{id}",
|
24
31
|
}[msg["data"]["subject"]],
|
25
32
|
css_class: css_class,
|
26
|
-
}.tap{ |h|
|
33
|
+
}.tap{ |h|
|
34
|
+
timeout = 0
|
35
|
+
begin
|
36
|
+
logger.warn h.merge( {
|
37
|
+
messaged_at: Time.at(msg["data"]["created_utc"]),
|
38
|
+
processed_at: Time.now,
|
39
|
+
} ), {
|
40
|
+
subreddit: msg["data"]["subject"],
|
41
|
+
}
|
42
|
+
rescue Google::Cloud::UnavailableError => e
|
43
|
+
logger.info "retrying in #{timeout += 1} seconds because of #{e}"
|
44
|
+
sleep timeout
|
45
|
+
retry
|
46
|
+
end
|
47
|
+
}
|
27
48
|
rescue RuntimeError => e
|
28
49
|
if e.to_s == "BAD_FLAIR_TARGET"
|
29
|
-
|
50
|
+
logger.error "#{e.to_s}: '#{msg["data"]["author"]}'"
|
30
51
|
else
|
31
52
|
raise e
|
32
53
|
end
|
33
54
|
end
|
34
55
|
BOT.json :post, "/api/read_message", {id: msg["data"]["name"]}
|
35
56
|
else
|
36
|
-
next
|
57
|
+
next logger.debug "bad subject: #{msg["data"]["subject"]}"
|
37
58
|
end
|
38
59
|
break # just for a case
|
39
60
|
end
|
40
61
|
|
41
|
-
|
62
|
+
logger.info "END LOOP #{Time.now}" unless Google::Cloud.env.compute_engine?
|
42
63
|
sleep 60
|
43
64
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# this emulates a Pub/Sub message from a 'casualpokemontrades' Sink for a deployed Function in Emulator as
|
2
|
+
# `GOOGLE_APPLICATION_CREDENTIALS="***.json" functions start`
|
3
|
+
# `functions deploy casualpokemontrades --trigger-topic casualpokemontrades`
|
4
|
+
# it waits for JSON payload from STDIN -- enter `{}` to use default payload sample
|
5
|
+
# after that you may wanna do `tail -30 /usr/local/lib/node_modules/@google-cloud/functions-emulator/logs/cloud-functions-emulator.log`
|
6
|
+
# to really deploy the Function do `gcloud beta functions deploy casualpokemontrades --stage-bucket casualpokemontrades.function.nakilon.pro --trigger-topic casualpokemontrades`
|
7
|
+
|
8
|
+
require "base64"
|
9
|
+
require "json"
|
10
|
+
|
11
|
+
base64 = Base64.strict_encode64 JSON.dump(
|
12
|
+
{
|
13
|
+
"insertId"=>"dbkwdqg109zgse",
|
14
|
+
"jsonPayload"=>{
|
15
|
+
"css_class"=>"charizard",
|
16
|
+
"messaged_at"=>"2017-08-19 10:11:57 +0300",
|
17
|
+
"name"=>"nakilon",
|
18
|
+
"processed_at"=>"2017-08-19 12:18:46 +0300",
|
19
|
+
"text"=>"0000-0000-0000 | test"
|
20
|
+
}.merge(JSON.load gets),
|
21
|
+
"labels"=>{"subreddit"=>"casualpokemontrades"},
|
22
|
+
"logName"=>"projects/nakilonpro/logs/cptflairbot3",
|
23
|
+
"receiveTimestamp"=>"2017-08-19T09:18:47.260056855Z",
|
24
|
+
"resource"=>{"labels"=>{"project_id"=>"nakilonpro"}, "type"=>"global"},
|
25
|
+
"severity"=>"WARNING",
|
26
|
+
"timestamp"=>"2017-08-19T09:18:46.666079Z"
|
27
|
+
}
|
28
|
+
)
|
29
|
+
|
30
|
+
exec 'functions call casualpokemontrades --data=\'{"data":"' + base64 + '","attributes":{"logging.googleapis.com/timestamp":"2017-08-19T09:18:46.666079Z"},"@type":"type.googleapis.com/google.pubsub.v1.PubsubMessage"}\''
|
@@ -7,8 +7,8 @@ GIT
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
json (2.0
|
11
|
-
reddit_bot (1.
|
10
|
+
json (2.1.0)
|
11
|
+
reddit_bot (1.3.0)
|
12
12
|
json
|
13
13
|
|
14
14
|
PLATFORMS
|
@@ -16,7 +16,7 @@ PLATFORMS
|
|
16
16
|
|
17
17
|
DEPENDENCIES
|
18
18
|
net_http_utils!
|
19
|
-
reddit_bot (~> 1.
|
19
|
+
reddit_bot (~> 1.3.0)
|
20
20
|
|
21
21
|
BUNDLED WITH
|
22
22
|
1.13.5
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative "../boilerplate"
|
2
2
|
|
3
|
-
BOT = RedditBot::Bot.new YAML.load
|
3
|
+
BOT = RedditBot::Bot.new YAML.load File.read "secrets.yaml"
|
4
4
|
|
5
5
|
loop do
|
6
6
|
Hearthbeat.beat "u_DevFlairBot_r_ion_r_survivetheculling", 130 unless Gem::Platform.local.os == "darwin"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://gist.github.com/97549ceb58d21e1fcbc0e6cdaf92fce8.git
|
3
|
+
revision: a5728a4745cf4479a3cc4a7742ca54fcb94955ab
|
4
|
+
specs:
|
5
|
+
net_http_utils (0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.6)
|
11
|
+
fastimage (1.7.0)
|
12
|
+
addressable (~> 2.3, >= 2.3.5)
|
13
|
+
json (2.1.0)
|
14
|
+
reddit_bot (1.3.0)
|
15
|
+
json
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
fastimage (= 1.7.0)
|
22
|
+
net_http_utils!
|
23
|
+
reddit_bot (~> 1.3.0)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.13.1
|
@@ -0,0 +1,183 @@
|
|
1
|
+
### THIS BOT IS OLD AS FUCK
|
2
|
+
### DON'T TRY TO LEARN FROM THIS CODE
|
3
|
+
|
4
|
+
if Gem::Platform.local.os == "darwin"
|
5
|
+
require_relative "../../../tcpsm/lib/tcp_socket_measurer"
|
6
|
+
else
|
7
|
+
require_relative "#{Dir.home}/tcp_socket_measurer"
|
8
|
+
end
|
9
|
+
|
10
|
+
%w{
|
11
|
+
198.41.208.137
|
12
|
+
198.41.208.138
|
13
|
+
198.41.208.139
|
14
|
+
198.41.208.140
|
15
|
+
198.41.208.141
|
16
|
+
198.41.208.142
|
17
|
+
198.41.208.143
|
18
|
+
198.41.209.136
|
19
|
+
198.41.209.137
|
20
|
+
198.41.209.138
|
21
|
+
198.41.209.139
|
22
|
+
198.41.209.140
|
23
|
+
198.41.209.141
|
24
|
+
198.41.209.142
|
25
|
+
198.41.209.143
|
26
|
+
|
27
|
+
151.101.33.140
|
28
|
+
151.101.32.193
|
29
|
+
}.each do |ip|
|
30
|
+
TCPSocketMeasurer.known_hosts[ip] = "www.reddit.com"
|
31
|
+
end
|
32
|
+
Thread.new do
|
33
|
+
loop do
|
34
|
+
TCPSocketMeasurer.report
|
35
|
+
puts "next report is in an hour"
|
36
|
+
sleep 3600
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
require "../boilerplate"
|
42
|
+
|
43
|
+
BOT = RedditBot::Bot.new YAML.load File.read "secrets.yaml"
|
44
|
+
|
45
|
+
if Gem::Platform.local.os == "darwin"
|
46
|
+
require_relative "../../../../dimensioner/get_dimensions"
|
47
|
+
else
|
48
|
+
require_relative "#{Dir.home}/get_dimensions"
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
checked = []
|
53
|
+
|
54
|
+
loop do
|
55
|
+
Hearthbeat.beat "u_largeimagesbot_r_largeimages", 310 unless Gem::Platform.local.os == "darwin"
|
56
|
+
puts "LOOP #{Time.now}"
|
57
|
+
|
58
|
+
%w{
|
59
|
+
|
60
|
+
r/pics
|
61
|
+
r/funny
|
62
|
+
r/wtf
|
63
|
+
r/woahdude
|
64
|
+
|
65
|
+
r/earthporn
|
66
|
+
r/spaceporn
|
67
|
+
r/mapporn
|
68
|
+
r/historyporn
|
69
|
+
r/abandonedporn
|
70
|
+
r/macroporn
|
71
|
+
r/microporn
|
72
|
+
|
73
|
+
r/bigwallpapers
|
74
|
+
r/wallpapers
|
75
|
+
r/wallpaper
|
76
|
+
|
77
|
+
user/I_AM_STILL_A_IDIOT/m/nationalphotosubs
|
78
|
+
}
|
79
|
+
|
80
|
+
# r/highres
|
81
|
+
# r/bigwallpapers
|
82
|
+
# r/wtf
|
83
|
+
# r/funny
|
84
|
+
%w{
|
85
|
+
|
86
|
+
user/kjoneslol/m/sfwpornnetwork
|
87
|
+
|
88
|
+
r/woahdude
|
89
|
+
|
90
|
+
r/highres
|
91
|
+
r/wallpapers
|
92
|
+
r/wallpaper
|
93
|
+
r/WQHD_Wallpaper
|
94
|
+
|
95
|
+
r/pic
|
96
|
+
|
97
|
+
}.shuffle.each do |where|
|
98
|
+
|
99
|
+
# next puts "#{where} seems to be 403-ed" unless _ = NetHTTPUtils.request_data("https://www.reddit.com/#{where}.json?sort=new&restrict_sr=on&t=hour")
|
100
|
+
_ = BOT.json(:get, "/#{where}/new")["data"]["children"].each do |post|
|
101
|
+
id, url, title, subreddit = post["data"].values_at(*%w{ id url title subreddit })
|
102
|
+
next puts "skipped /r/FoodPorn" if subreddit.downcase == "foodporn"
|
103
|
+
# id, url, title, subreddit = "39ywvu", "http://i.imgur.com/WGdRPmT.jpg", "I don't know how fireworks have anything to do with genocide, but this manufacturer clearly begs to differ", "wtf"
|
104
|
+
next if checked.include? id
|
105
|
+
checked << id
|
106
|
+
# id = "36y3w1"
|
107
|
+
# url = "http://i.imgur.com/c6uGJV0.jpg"
|
108
|
+
# unless (url = item["data"]["url"])[%r{//[^/]*imgur\.com/}]
|
109
|
+
# next if Gem::Platform.local.os == "darwin" # prevent concurrent posting
|
110
|
+
next puts "skipped #{url} from http://redd.it/#{id}" if :skipped == _ = GetDimensions::get_dimensions(url)
|
111
|
+
next puts "unable #{url} from http://redd.it/#{id}" unless _
|
112
|
+
width, height, best_direct_url, *all_direct_urls = _
|
113
|
+
unless 5000000 <= width * height
|
114
|
+
# puts " -- that is too small"
|
115
|
+
next
|
116
|
+
end
|
117
|
+
# next if Gem::Platform.local.os == "darwin" # prevent concurrent posting
|
118
|
+
# puts "https://www.reddit.com/r/LargeImages/search.json?q=url%3A#{CGI.escape url}&restrict_sr=on"
|
119
|
+
resolution = "[#{width}x#{height}]"
|
120
|
+
next puts "already submitted #{resolution} #{id}: '#{url}'" unless
|
121
|
+
Gem::Platform.local.os == "darwin" ||
|
122
|
+
(JSON.parse NetHTTPUtils.request_data "https://www.reddit.com/r/LargeImages/search.json?q=url%3A#{CGI.escape url}&restrict_sr=on", header: ["User-Agent", "ajsdjasdasd"])["data"]["children"].empty?
|
123
|
+
puts "#{resolution} got from #{id}: #{url}"
|
124
|
+
# next if Gem::Platform.local.os == "darwin" # prevent concurrent posting
|
125
|
+
title = "#{resolution}#{
|
126
|
+
" [#{all_direct_urls.size} images]" if all_direct_urls.size > 1
|
127
|
+
} #{
|
128
|
+
title.sub(/\s*\[?#{width}\s*[*x×]\s*#{height}\]?\s*/i, " ").
|
129
|
+
gsub(/\s+/, " ").strip.
|
130
|
+
sub(/(.{#{100 - subreddit.size}}).+/, '\1...')
|
131
|
+
} /r/#{subreddit}".
|
132
|
+
gsub(/\s+\(\s+\)\s+/, " ")
|
133
|
+
if Gem::Platform.local.os == "darwin"
|
134
|
+
puts title
|
135
|
+
else
|
136
|
+
result = BOT.json :post,
|
137
|
+
"/api/submit",
|
138
|
+
{
|
139
|
+
kind: "link",
|
140
|
+
url: url,
|
141
|
+
sr: "LargeImages",
|
142
|
+
title: title,
|
143
|
+
# ["uh / X-Modhash header", ""]
|
144
|
+
}
|
145
|
+
# }.tap{ |form|
|
146
|
+
# form.merge!( {
|
147
|
+
# iden: BOT.iden_and_captcha[0],
|
148
|
+
# captcha: BOT.iden_and_captcha[1],
|
149
|
+
# } ) if BOT.iden_and_captcha
|
150
|
+
# }
|
151
|
+
next unless result["json"]["errors"].empty?
|
152
|
+
puts result["json"]["data"]["url"]
|
153
|
+
end
|
154
|
+
# {"json"=>
|
155
|
+
# {"errors"=>[],
|
156
|
+
# "data"=>
|
157
|
+
# {"url"=>
|
158
|
+
# "https://www.reddit.com/r/LargeImages/comments/3a9rel/2594x1724_overlooking_wildhorse_lake_from_near/",
|
159
|
+
# "id"=>"3a9rel",
|
160
|
+
# "name"=>"t3_3a9rel"}}}
|
161
|
+
line1 = "[Original thread](https://www.reddit.com#{post["data"]["permalink"]}) by /u/#{post["data"]["author"]}"
|
162
|
+
line2 = "Direct link#{" (the largest image)" if all_direct_urls.size > 1}: #{best_direct_url}"
|
163
|
+
line3 = [
|
164
|
+
"Direct links to all other images in album:",
|
165
|
+
all_direct_urls - [best_direct_url]
|
166
|
+
] if all_direct_urls.size > 1
|
167
|
+
text = [line1, line2, line3].compact.join(" \n")
|
168
|
+
if Gem::Platform.local.os == "darwin"
|
169
|
+
puts text
|
170
|
+
else
|
171
|
+
result = BOT.leave_a_comment "#{result["json"]["data"]["name"]}", text.sub(/(?<=.{9000}).+/m, "...")
|
172
|
+
unless result["json"]["errors"].empty?
|
173
|
+
p result
|
174
|
+
fail "failed to leave comment"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
# abort if Gem::Platform.local.os == "darwin"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
puts "END LOOP #{Time.now}"
|
182
|
+
sleep 300
|
183
|
+
end
|
data/examples/mlgtv/Gemfile
CHANGED
data/examples/mlgtv/Gemfile.lock
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
|
@@ -0,0 +1,110 @@
|
|
1
|
+
Ricky
|
2
|
+
ACHES
|
3
|
+
Lacefield
|
4
|
+
Clayster
|
5
|
+
Enable
|
6
|
+
Zoomaa
|
7
|
+
Attach
|
8
|
+
TheFEARS
|
9
|
+
MiRx1
|
10
|
+
SaintsRF
|
11
|
+
StuDyy
|
12
|
+
SpaceLyTV
|
13
|
+
NAMELESS
|
14
|
+
Scump
|
15
|
+
FORMAL
|
16
|
+
Crimsix
|
17
|
+
Karma
|
18
|
+
Loony
|
19
|
+
Slacked
|
20
|
+
Octane
|
21
|
+
MJChino
|
22
|
+
Diabolic_TV
|
23
|
+
ImTheIvy
|
24
|
+
Senderxz
|
25
|
+
Jkap
|
26
|
+
John
|
27
|
+
SlasheRAL
|
28
|
+
Apathy
|
29
|
+
ColtHavok
|
30
|
+
MikeSwarley
|
31
|
+
ParasiteTV
|
32
|
+
TyreeLegal
|
33
|
+
Silly
|
34
|
+
Blfire
|
35
|
+
methodz
|
36
|
+
TwiZzyTV
|
37
|
+
Mochila
|
38
|
+
Remy
|
39
|
+
Xotic16
|
40
|
+
AquA
|
41
|
+
Faccento
|
42
|
+
Nagafen
|
43
|
+
Tylerfelo
|
44
|
+
TheoryCoD
|
45
|
+
ColeChanTV
|
46
|
+
happyy97
|
47
|
+
goonjar
|
48
|
+
Burns
|
49
|
+
Dedo
|
50
|
+
Neslo
|
51
|
+
TeeCM
|
52
|
+
K1lla93
|
53
|
+
NeLsoNNaTeR
|
54
|
+
ProoFy
|
55
|
+
Whea7s
|
56
|
+
MBoZe
|
57
|
+
Merk
|
58
|
+
Nadeshot
|
59
|
+
ReeP
|
60
|
+
Sharp
|
61
|
+
TeePee
|
62
|
+
Braaain2015
|
63
|
+
Nolsonn
|
64
|
+
QwiKeRTHaNu
|
65
|
+
Zedenyer1
|
66
|
+
Jurd
|
67
|
+
Tommey
|
68
|
+
Swanny
|
69
|
+
MadCatEU
|
70
|
+
Rated_EU1
|
71
|
+
BsportJoshh
|
72
|
+
Sy_Vortex
|
73
|
+
TheMarkyB
|
74
|
+
Peatie95
|
75
|
+
urbandm
|
76
|
+
TreiZer0
|
77
|
+
iDqvee
|
78
|
+
Tojor
|
79
|
+
MethodZ_TV
|
80
|
+
Gotaga
|
81
|
+
WailersWL
|
82
|
+
TCM_Moose
|
83
|
+
skrapzq
|
84
|
+
Reedy
|
85
|
+
fighta71
|
86
|
+
Swiftazor
|
87
|
+
BacabecNZ
|
88
|
+
Zeuss_Gaming
|
89
|
+
Hopeyy
|
90
|
+
GuydraCOD
|
91
|
+
mattmrx
|
92
|
+
Maven
|
93
|
+
CouRageJD
|
94
|
+
Revan
|
95
|
+
BriceyHD
|
96
|
+
Benson
|
97
|
+
PHILWHI7
|
98
|
+
MLG
|
99
|
+
mlgbravo
|
100
|
+
Multiplay_CoD
|
101
|
+
UMGEvents
|
102
|
+
GfinityTV
|
103
|
+
WorldGaming
|
104
|
+
FemaleProLeague
|
105
|
+
Arcitys
|
106
|
+
Prestinni
|
107
|
+
Maux
|
108
|
+
priestahh
|
109
|
+
Vilesyder
|
110
|
+
benbance
|
data/examples/mlgtv/main.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative File.join "../boilerplate"
|
2
2
|
|
3
|
-
BOT = RedditBot::Bot.new YAML.load
|
3
|
+
BOT = RedditBot::Bot.new YAML.load File.read "secrets.yaml"
|
4
4
|
|
5
5
|
SUBREDDIT = "codcompetitive"
|
6
6
|
|
@@ -13,8 +13,11 @@ loop do
|
|
13
13
|
throw :loop unless statuses = JSON.parse(
|
14
14
|
NetHTTPUtils.request_data("http://streamapi.majorleaguegaming.com/service/streams/all")[/\{.+\}/m]
|
15
15
|
)["data"]["items"]
|
16
|
+
games = JSON.parse(
|
17
|
+
NetHTTPUtils.request_data("http://www.majorleaguegaming.com/api/games/all")[/\{.+\}/m]
|
18
|
+
)["data"]["items"]
|
16
19
|
begin
|
17
|
-
JSON.parse NetHTTPUtils.request_data "http://www.majorleaguegaming.com/api/channels/all
|
20
|
+
JSON.parse NetHTTPUtils.request_data "http://www.majorleaguegaming.com/api/channels/all?fields=name,url,tags,stream_name,game_id"
|
18
21
|
rescue JSON::ParserError
|
19
22
|
puts "JSON::ParserError"
|
20
23
|
sleep 60
|
@@ -23,28 +26,78 @@ loop do
|
|
23
26
|
next unless item1["tags"].include? "COD Pro League"
|
24
27
|
status = statuses.find{ |item2| item1["stream_name"] == item2["stream_name"] }
|
25
28
|
next unless status && status["status"] > 0
|
29
|
+
game = games.find{ |game| game["id"] == item1["game_id"] }
|
26
30
|
list << "* [](#mlg) [](##{
|
27
31
|
["?", "live", "replay"][status["status"]]
|
28
|
-
})
|
32
|
+
}) #{
|
33
|
+
"[](##{ {
|
34
|
+
"Call of Duty: Modern Warfare 2" => "codmw2",
|
35
|
+
"Call of Duty: Modern Warfare 3" => "codmw3",
|
36
|
+
"Call of Duty: Black Ops" => "codbo12",
|
37
|
+
"Call of Duty: Black Ops II" => "codbo2",
|
38
|
+
"Call of Duty: Black Ops III" => "codbo3",
|
39
|
+
"Call of Duty: Advanced Warfare" => "codaw",
|
40
|
+
"Call of Duty: Ghosts" => "codghosts2",
|
41
|
+
"Call of Duty: Infinite Warfare" => "codiw",
|
42
|
+
}[game["name"]] }) " if game
|
43
|
+
}[**#{
|
29
44
|
item1["name"]
|
30
45
|
}**](#{
|
31
46
|
item1["url"]
|
32
47
|
})"
|
33
48
|
end
|
34
49
|
|
35
|
-
require "cgi"
|
36
50
|
# to update access_token:
|
37
51
|
# 0. see 'client_id' here https://www.twitch.tv/settings/connections and 'client_secret' from local ./readme file
|
38
52
|
# 1. get 'code' by visiting in browser: https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=*******&redirect_uri=http://www.example.com/unused/redirect/uri&scope=channel_read channel_feed_read
|
39
53
|
# 2. NetHTTPUtils.request_data("https://api.twitch.tv/kraken/oauth2/token", :post, form: {client_id: "*******", client_secret: "*****", grant_type: "authorization_code", redirect_uri: "http://www.example.com/unused/redirect/uri", code: "*******"})
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
54
|
+
twitch = lambda do |url|
|
55
|
+
max = 1000
|
56
|
+
data_key = "top"
|
57
|
+
next_key = "_links"
|
58
|
+
|
59
|
+
request = lambda do |url, acc|
|
60
|
+
uri = URI.parse url
|
61
|
+
query = Hash[URI.decode_www_form uri.query || ""]
|
62
|
+
# query.merge!({ "limit" => max }) if max
|
63
|
+
uri.query = URI.encode_www_form query.merge( {
|
64
|
+
"access_token" => File.read("twitch.token").strip,
|
65
|
+
"client_id" => File.read("client.id").strip,
|
66
|
+
} )
|
67
|
+
json = JSON.parse NetHTTPUtils.request_data uri.to_s
|
68
|
+
unless json[data_key]
|
69
|
+
pp json
|
70
|
+
fail
|
71
|
+
end
|
72
|
+
acc = acc + json[data_key]
|
73
|
+
next acc.take max if max && max <= acc.size
|
74
|
+
request[json[next_key]["next"], acc]
|
75
|
+
end
|
76
|
+
|
77
|
+
request[url, []]
|
78
|
+
end
|
79
|
+
# ? absent on twitch ? "Call of Duty: Modern Warfare 2" => "codmw2"
|
80
|
+
# t = twitch["https://api.twitch.tv/kraken/games/top?limit=100"].map{ |hash| fail hash.keys.to_s unless hash.keys == %w{ game viewers channels }; hash.values.first["name"] }
|
81
|
+
# pp t.grep("/call of duty/i")
|
82
|
+
# pp t.grep("/warfare/i")
|
83
|
+
# ? absent in css ? "Call of Duty: United Offensive"
|
84
|
+
{
|
85
|
+
"Call of Duty: Infinite Warfare" => "codiw",
|
86
|
+
"Call of Duty: Modern Warfare Remastered" => "cod4",
|
87
|
+
"Call of Duty 4: Modern Warfare" => "cod4",
|
88
|
+
"Call of Duty: Modern Warfare 3" => "codmw3",
|
89
|
+
"Call of Duty: Black Ops" => "codbo12",
|
90
|
+
"Call of Duty: Black Ops II" => "codbo2",
|
91
|
+
"Call of Duty: Black Ops III" => "codbo3",
|
92
|
+
"Call of Duty: Advanced Warfare" => "codaw",
|
93
|
+
"Call of Duty: Ghosts" => "codghosts2",
|
94
|
+
"Call of Duty: World at War" => "codwaw",
|
95
|
+
"Call of Duty: WWII" => "codwwii",
|
96
|
+
"Modern Warfare 2" => "codmw2",
|
97
|
+
}.each do |game, css|
|
45
98
|
(begin
|
46
99
|
begin
|
47
|
-
t = NetHTTPUtils.get_response "https://api.twitch.tv/kraken/streams?game=#{CGI::escape game}&access_token=#{File.read("twitch.token").strip}&client_id=#{File.read("client.id").strip}&channel
|
100
|
+
t = NetHTTPUtils.get_response "https://api.twitch.tv/kraken/streams?game=#{CGI::escape game}&access_token=#{File.read("twitch.token").strip}&client_id=#{File.read("client.id").strip}&channel=#{File.read("channels.txt").split.join ?,}"
|
48
101
|
end while t.code == 500
|
49
102
|
JSON.parse t.body
|
50
103
|
rescue JSON::ParserError
|
@@ -52,7 +105,9 @@ loop do
|
|
52
105
|
sleep 60
|
53
106
|
retry
|
54
107
|
end["streams"] || []).each do |channel|
|
55
|
-
list << "* [](#twitch) [](#live)
|
108
|
+
list << "* [](#twitch) [](#live) #{
|
109
|
+
"[](##{css}) "
|
110
|
+
}[**#{
|
56
111
|
channel["channel"]["display_name"]
|
57
112
|
}**](#{
|
58
113
|
channel["channel"]["url"]
|
@@ -88,5 +143,5 @@ loop do
|
|
88
143
|
fail _.inspect if _ != {"json"=>{"errors"=>[]}} && !(_["json"]["errors"].map(&:first) - ["BAD_CAPTCHA"]).empty?
|
89
144
|
|
90
145
|
end
|
91
|
-
sleep
|
146
|
+
sleep 300
|
92
147
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git@github.com:Nakilon/nethttputils.git
|
3
|
+
revision: 5642bf7ecde4b3ecc55423b9ea9957828a9cb2f9
|
4
|
+
tag: v0.0.1.1
|
5
|
+
specs:
|
6
|
+
nethttputils (0.0.1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
json (2.1.0)
|
12
|
+
reddit_bot (1.3.0)
|
13
|
+
json
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
nethttputils!
|
20
|
+
reddit_bot
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
1.13.1
|