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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f75fa5e061134a60cae44226a5995d8368e802d
|
4
|
+
data.tar.gz: ef7c93b4c345c11d93ab752de2a41ed1d380516b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b980165b04f3db528a79a984da5bb21c5d7c4ee9b8e76b15cebb1ce1ef90a81beb68f6af78cb6fb72526686a924078bb4bd95108bfe49906a30158cd836ed82
|
7
|
+
data.tar.gz: 222bd7ef333723ed9b3969b5f27086e864f4a7f1cc021dfdd6d4b057030d26f546466915573db7676717dd140035dffcc264c25a6e6731099db186e0fbe2c3fd
|
data/README.md
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
#### What
|
7
7
|
|
8
|
-
This library provides an easy way to run bots and scripts that use Reddit API.
|
9
|
-
I (
|
8
|
+
This library provides an easy way to run bots and scripts that use Reddit API.
|
9
|
+
I ([/u/nakilon](https://reddit.com/u/nakilon)) currently run near 10 bots with it.
|
10
10
|
|
11
11
|
#### Why
|
12
12
|
|
@@ -20,10 +20,12 @@ The [examples folder](examples) includes:
|
|
20
20
|
* devflairbot -- bot that flairs posts when some specifically flaired user comments there
|
21
21
|
* mlgtv -- bot that updates sidebar with currently streaming twitch channels
|
22
22
|
* councilofricks -- bot that flairs users according to Google Spreadsheet
|
23
|
-
* wallpaper -- bot that reports images with dimensions not the same as in title
|
24
|
-
* cptflairbot3 -- bot that sets flair
|
23
|
+
* wallpaper -- bot that reports images with dimensions being not the same as in title
|
24
|
+
* cptflairbot3 -- bot that sets user flair according to request submitted via web form
|
25
|
+
also publishes its activily log here http://nakilon.pro/log.htm via Google Cloud Platform automations
|
25
26
|
* oneplus -- bot that removes and modmails about links to 1080x1920 images
|
26
27
|
* yayornay -- bot that flairs posts according to voting in top level comments
|
28
|
+
* realtimeww2 -- bot that posts tweets to a subreddit from a Twitter user timeline
|
27
29
|
* largeimagesreview -- useful script for [subreddit /r/largeimages](https://reddit.com/r/largeimages/top)
|
28
30
|
It calculates quality of x-posts from different subreddits based on mods activity (remove/approve).
|
29
31
|
For example, this showed that it would be ok to ignore /r/pics from now:
|
@@ -70,12 +72,12 @@ helloworld.rb:
|
|
70
72
|
|
71
73
|
require "reddit_bot"
|
72
74
|
|
73
|
-
|
75
|
+
or via Gemfile:
|
74
76
|
|
75
77
|
source "https://rubygems.org"
|
76
78
|
gem "reddit_bot"
|
77
79
|
|
78
|
-
TODO:
|
80
|
+
TODO: write more usage instructions here
|
79
81
|
TODO: manual on how to create bots with Reddit web interface and run via bash console
|
80
82
|
|
81
83
|
To update the gem version in Gemfile.lock when using Gemfile like this: `gem "reddit_bot", "~>1.1.0"`, do the:
|
@@ -84,5 +86,5 @@ To update the gem version in Gemfile.lock when using Gemfile like this: `gem "re
|
|
84
86
|
|
85
87
|
#### Contributing and License
|
86
88
|
|
87
|
-
Bug reports and pull requests are welcome.
|
89
|
+
Bug reports and pull requests are welcome.
|
88
90
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/examples/boilerplate.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
GIT
|
2
|
-
remote:
|
3
|
-
revision:
|
2
|
+
remote: git@github.com:Nakilon/nethttputils.git
|
3
|
+
revision: 5642bf7ecde4b3ecc55423b9ea9957828a9cb2f9
|
4
|
+
tag: v0.0.1.1
|
4
5
|
specs:
|
5
|
-
|
6
|
+
nethttputils (0.0.1.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
json (2.0
|
11
|
-
reddit_bot (1.
|
11
|
+
json (2.1.0)
|
12
|
+
reddit_bot (1.3.0)
|
12
13
|
json
|
13
14
|
|
14
15
|
PLATFORMS
|
15
16
|
ruby
|
16
17
|
|
17
18
|
DEPENDENCIES
|
18
|
-
|
19
|
-
reddit_bot (~> 1.
|
19
|
+
nethttputils!
|
20
|
+
reddit_bot (~> 1.3.0)
|
20
21
|
|
21
22
|
BUNDLED WITH
|
22
23
|
1.13.1
|
@@ -1,12 +1,13 @@
|
|
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
|
SUBREDDIT = "CouncilOfRicks"
|
5
5
|
|
6
6
|
CSS_CLASS = "blueflair"
|
7
7
|
|
8
8
|
require "csv"
|
9
9
|
|
10
|
+
ignored = []
|
10
11
|
loop do
|
11
12
|
Hearthbeat.beat "u_FlairMoTron_r_CouncilOfRicks", 310 unless Gem::Platform.local.os == "darwin"
|
12
13
|
|
@@ -21,21 +22,31 @@ loop do
|
|
21
22
|
existing = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", limit: 1000)["users"]
|
22
23
|
fail if existing.size >= 1000
|
23
24
|
|
24
|
-
if names.size
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
if names.size != flairs.size
|
26
|
+
puts "columns are different by length -- probably someone is editing the Spreadsheet"
|
27
|
+
else
|
28
|
+
names.zip(flairs).drop(1).map(&:flatten).map do |user, text|
|
29
|
+
user = user.to_s.strip
|
30
|
+
next unless user[/\A[a-z-_\d]+\z/i]
|
31
|
+
text = text.to_s.strip
|
32
|
+
next puts "ignored #{user}" if ignored.include? user
|
33
|
+
next if existing.include?( {"user"=>user, "flair_text"=>text, "flair_css_class"=>CSS_CLASS} )
|
34
|
+
[user, text, CSS_CLASS]
|
35
|
+
end.compact.each_slice(50) do |slice|
|
36
|
+
load = CSV.generate do |csv|
|
37
|
+
slice.each &csv.method(:<<)
|
32
38
|
end
|
33
|
-
BOT.json(:post, "/r/#{SUBREDDIT}/api/flaircsv",
|
34
|
-
|
39
|
+
BOT.json(:post, "/r/#{SUBREDDIT}/api/flaircsv", flair_csv: load).each do |report|
|
40
|
+
unless report.values_at("errors", "ok", "warnings") == [{}, true, {}]
|
41
|
+
pp report
|
42
|
+
abort "wrong keys" unless report.keys.sort == %w{ errors ok status warnings }
|
43
|
+
abort "wrong values" unless report.values_at(*%w{ ok status warnings }) == [false, "skipped", {}]
|
44
|
+
abort "wrong error keys" unless report["errors"].keys == %w{ user }
|
45
|
+
abort "wrong error values" unless user = report["errors"]["user"][/\Aunable to resolve user `([A-Za-z-_\d]+)', ignoring\z/, 1]
|
46
|
+
ignored |= [user]
|
47
|
+
end
|
35
48
|
end
|
36
49
|
end
|
37
|
-
else
|
38
|
-
puts "columns are different by length"
|
39
50
|
end
|
40
51
|
|
41
52
|
sleep 300
|
@@ -0,0 +1 @@
|
|
1
|
+
export GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS_NAKILONPRO_LOGGER
|
@@ -0,0 +1,13 @@
|
|
1
|
+
function doGet(e) {
|
2
|
+
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
|
3
|
+
const range = sheet.getRange("A2:D100"); // hardcode
|
4
|
+
console.log(e.parameter.payload);
|
5
|
+
payload = JSON.parse(Utilities.newBlob(Utilities.base64Decode(e.parameter.payload)).getDataAsString());
|
6
|
+
range.moveTo(range.offset(1, 0));
|
7
|
+
sheet.getRange("A2:2").setValues( [ [
|
8
|
+
payload.messaged_at,
|
9
|
+
payload.processed_at,
|
10
|
+
payload.name,
|
11
|
+
payload.text,
|
12
|
+
] ] ); // hardcoded columns order
|
13
|
+
}
|
@@ -1,15 +1,75 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git@github.com:Nakilon/gcplogger.git
|
3
|
+
revision: 7adffeeeb9a209d15fdd76451ad1a68846a908dd
|
4
|
+
tag: v0.0.0.1
|
5
|
+
specs:
|
6
|
+
gcplogger (0.0.0.1)
|
7
|
+
google-cloud-logging
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: https://rubygems.org/
|
3
11
|
specs:
|
4
|
-
|
5
|
-
|
12
|
+
addressable (2.5.1)
|
13
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
14
|
+
faraday (0.13.1)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
google-cloud-core (1.0.0)
|
17
|
+
google-cloud-env (~> 1.0)
|
18
|
+
googleauth (~> 0.5.1)
|
19
|
+
google-cloud-env (1.0.1)
|
20
|
+
faraday (~> 0.11)
|
21
|
+
google-cloud-logging (1.2.1)
|
22
|
+
google-cloud-core (~> 1.0)
|
23
|
+
google-gax (~> 0.8.0)
|
24
|
+
stackdriver-core (~> 1.2)
|
25
|
+
google-gax (0.8.6)
|
26
|
+
google-protobuf (~> 3.2)
|
27
|
+
googleapis-common-protos (~> 1.3.5)
|
28
|
+
googleauth (~> 0.5.1)
|
29
|
+
grpc (~> 1.0)
|
30
|
+
rly (~> 0.2.3)
|
31
|
+
google-protobuf (3.4.0.2)
|
32
|
+
googleapis-common-protos (1.3.5)
|
33
|
+
google-protobuf (~> 3.2)
|
34
|
+
grpc (~> 1.0)
|
35
|
+
googleauth (0.5.3)
|
36
|
+
faraday (~> 0.12)
|
37
|
+
jwt (~> 1.4)
|
38
|
+
logging (~> 2.0)
|
39
|
+
memoist (~> 0.12)
|
40
|
+
multi_json (~> 1.11)
|
41
|
+
os (~> 0.9)
|
42
|
+
signet (~> 0.7)
|
43
|
+
grpc (1.4.5)
|
44
|
+
google-protobuf (~> 3.1)
|
45
|
+
googleauth (~> 0.5.1)
|
46
|
+
json (2.1.0)
|
47
|
+
jwt (1.5.6)
|
48
|
+
little-plugger (1.1.4)
|
49
|
+
logging (2.2.2)
|
50
|
+
little-plugger (~> 1.1)
|
51
|
+
multi_json (~> 1.10)
|
52
|
+
memoist (0.16.0)
|
53
|
+
multi_json (1.12.1)
|
54
|
+
multipart-post (2.0.0)
|
55
|
+
os (0.9.6)
|
56
|
+
public_suffix (2.0.5)
|
57
|
+
reddit_bot (1.3.0)
|
6
58
|
json
|
59
|
+
rly (0.2.3)
|
60
|
+
signet (0.7.3)
|
61
|
+
addressable (~> 2.3)
|
62
|
+
faraday (~> 0.9)
|
63
|
+
jwt (~> 1.5)
|
64
|
+
multi_json (~> 1.10)
|
65
|
+
stackdriver-core (1.2.0)
|
7
66
|
|
8
67
|
PLATFORMS
|
9
68
|
ruby
|
10
69
|
|
11
70
|
DEPENDENCIES
|
12
|
-
|
71
|
+
gcplogger!
|
72
|
+
reddit_bot (~> 1.3.0)
|
13
73
|
|
14
74
|
BUNDLED WITH
|
15
|
-
1.
|
75
|
+
1.13.1
|
@@ -0,0 +1,40 @@
|
|
1
|
+
exports.casualpokemontrades = function(event, callback) {
|
2
|
+
|
3
|
+
// based on https://www.tomas-dvorak.cz/posts/nodejs-request-without-dependencies/
|
4
|
+
const getContent = function(url) {
|
5
|
+
return new Promise((resolve, reject) => {
|
6
|
+
const lib = url.startsWith("https") ? require("https") : require("http");
|
7
|
+
const request = function(url) {
|
8
|
+
lib.get(url, (response) => {
|
9
|
+
var body = [];
|
10
|
+
/*if (response.statusCode == 302) {
|
11
|
+
body = [];
|
12
|
+
request(response.headers.location);
|
13
|
+
} else*/ if (response.statusCode < 200 || response.statusCode > 299) {
|
14
|
+
reject(new Error("Failed to load page, status code: " + response.statusCode));
|
15
|
+
} else {
|
16
|
+
response.on("data", (chunk) => body.push(chunk));
|
17
|
+
response.on("end", () => resolve(body.join("")));
|
18
|
+
};
|
19
|
+
} ).on("error", (err) => reject(err));
|
20
|
+
};
|
21
|
+
request(url);
|
22
|
+
} );
|
23
|
+
};
|
24
|
+
|
25
|
+
const storage = require("@google-cloud/storage")();
|
26
|
+
storage.
|
27
|
+
bucket("casualpokemontrades.function.nakilon.pro").
|
28
|
+
file("gas_hook_id.secret").
|
29
|
+
download( function(err, contents) {
|
30
|
+
const log_payload = JSON.parse(Buffer.from(event.data.data, "base64").toString()).jsonPayload;
|
31
|
+
console.log(log_payload);
|
32
|
+
const path = "https://script.google.com/macros/s/" + contents.toString() + "/exec?payload=" + Buffer.from(JSON.stringify(log_payload)).toString("base64");
|
33
|
+
console.log(path);
|
34
|
+
getContent(path);
|
35
|
+
// then((html) => console.log(html)).
|
36
|
+
// catch((err) => console.error(err));
|
37
|
+
} );
|
38
|
+
|
39
|
+
callback();
|
40
|
+
};
|