brutalismbot 1.6.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/brutalismbot/base.rb +1 -1
- data/lib/brutalismbot/client.rb +3 -8
- data/lib/brutalismbot/reddit/post.rb +17 -15
- data/lib/brutalismbot/reddit/resource.rb +2 -1
- data/lib/brutalismbot/reddit/stub.rb +1 -2
- data/lib/brutalismbot/slack/auth.rb +0 -16
- data/lib/brutalismbot/slack/client.rb +10 -5
- data/lib/brutalismbot/twitter/client.rb +9 -16
- data/lib/brutalismbot/version.rb +1 -1
- metadata +2 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc9aa96ddf426ba53cd94234a85ab6b3b11237dcdfb8414ca522f983a58c807c
|
4
|
+
data.tar.gz: 87ccc44e65a2565e31a3e60c399ab2d6725f6594a12da582c273e9b95292020d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8160fd997677a8ab632be035009b1cea925c4791cc45109c9cba086eda92408b4d931394efa92a1b438357a9784206b2479ccf191397dd66f0beeb809af7d6f
|
7
|
+
data.tar.gz: bba9c3dda2a30a14209d74599a4bcd01e0cce55caa138970135fd001a0a9db79272c8acdb4d0bef6dce89970ac0cda8bbfca181d7d4febb0bcb8103e581e96f0
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
<img alt="brutalismbot" src="https://brutalismbot.com/banner.png"/>
|
2
2
|
|
3
|
-
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
3
|
+
![gem](https://img.shields.io/gem/v/brutalismbot?logo=rubygems&logoColor=eee&style=flat-square)
|
4
|
+
[![rspec](https://img.shields.io/github/workflow/status/brutalismbot/gem/rspec?logo=github&style=flat-square)](https://github.com/brutalismbot/gem/actions)
|
5
|
+
[![coverage](https://img.shields.io/codeclimate/coverage/brutalismbot/gem?logo=code-climate&style=flat-square)](https://codeclimate.com/github/brutalismbot/gem/test_coverage)
|
6
|
+
[![maintainability](https://img.shields.io/codeclimate/maintainability/brutalismbot/gem?logo=code-climate&style=flat-square)](https://codeclimate.com/github/brutalismbot/gem/maintainability)
|
7
7
|
|
8
8
|
Brutalismbot RubyGem
|
9
9
|
|
data/lib/brutalismbot/base.rb
CHANGED
data/lib/brutalismbot/client.rb
CHANGED
@@ -14,16 +14,11 @@ module Brutalismbot
|
|
14
14
|
@twitter = twitter || Twitter::Client.new
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
lag = ENV["BRUTALISMBOT_LAG_TIME"].to_s
|
19
|
-
lag.empty? ? 9000 : lag.to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
def pull(limit:nil, min_time:nil, max_time:nil, lag:nil, dryrun:nil)
|
17
|
+
def pull(limit:nil, min_time:nil, max_time:nil, min_age:nil, dryrun:nil)
|
23
18
|
# Get time window for new posts
|
24
|
-
|
19
|
+
min_age ||= 9000
|
25
20
|
min_time ||= @posts.max_time
|
26
|
-
max_time ||= Time.now.utc.to_i -
|
21
|
+
max_time ||= Time.now.utc.to_i - min_age.to_i
|
27
22
|
|
28
23
|
# Get posts
|
29
24
|
opts = {q:"self:no AND nsfw:no", restrict_sr: true, sort: "new"}
|
@@ -7,11 +7,6 @@ require "brutalismbot/base"
|
|
7
7
|
module Brutalismbot
|
8
8
|
module Reddit
|
9
9
|
class Post < Base
|
10
|
-
def initialize(**item)
|
11
|
-
@mime_type = item.delete(:mime_type)
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
10
|
def created_after?(time = nil)
|
16
11
|
time.nil? || created_utc.to_i > time.to_i
|
17
12
|
end
|
@@ -83,6 +78,10 @@ module Brutalismbot
|
|
83
78
|
end
|
84
79
|
end
|
85
80
|
|
81
|
+
def mime_type=(value)
|
82
|
+
@mime_type = value
|
83
|
+
end
|
84
|
+
|
86
85
|
def path
|
87
86
|
created_utc.strftime("year=%Y/month=%Y-%m/day=%Y-%m-%d/%s.json")
|
88
87
|
end
|
@@ -109,6 +108,19 @@ module Brutalismbot
|
|
109
108
|
is_self? ? to_slack_text : to_slack_image
|
110
109
|
end
|
111
110
|
|
111
|
+
def to_twitter
|
112
|
+
max = 280 - permalink.length - 1
|
113
|
+
status = title.length <= max ? title : "#{title[0...max - 1]}…"
|
114
|
+
status << "\n#{permalink}"
|
115
|
+
{status: status, media_url: is_self? ? nil : media_url}
|
116
|
+
end
|
117
|
+
|
118
|
+
def url
|
119
|
+
data["url"]
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
112
124
|
def to_slack_image
|
113
125
|
{
|
114
126
|
blocks: [
|
@@ -153,16 +165,6 @@ module Brutalismbot
|
|
153
165
|
],
|
154
166
|
}
|
155
167
|
end
|
156
|
-
|
157
|
-
def to_twitter
|
158
|
-
max = 280 - permalink.length - 1
|
159
|
-
text = title.length <= max ? title : "#{title[0...max - 1]}…"
|
160
|
-
[text, permalink].join("\n")
|
161
|
-
end
|
162
|
-
|
163
|
-
def url
|
164
|
-
data["url"]
|
165
|
-
end
|
166
168
|
end
|
167
169
|
end
|
168
170
|
end
|
@@ -24,7 +24,8 @@ module Brutalismbot
|
|
24
24
|
response = JSON.parse(http.request(request).body)
|
25
25
|
children = response.dig("data", "children") || []
|
26
26
|
children.each do |child|
|
27
|
-
|
27
|
+
item = child.transform_keys(&:to_sym)
|
28
|
+
post = Post.new(**item)
|
28
29
|
Brutalismbot.logger.warn("NO PHOTO URL for #{post.permalink}") if post.url.nil?
|
29
30
|
yield post
|
30
31
|
end
|
@@ -4,13 +4,12 @@ module Brutalismbot
|
|
4
4
|
module Reddit
|
5
5
|
class Post
|
6
6
|
class << self
|
7
|
-
def stub(created_utc:nil, post_id:nil, permalink_id:nil, image_id:nil
|
7
|
+
def stub(created_utc:nil, post_id:nil, permalink_id:nil, image_id:nil)
|
8
8
|
created_utc ||= Time.now.utc - rand(86400) - 86400
|
9
9
|
post_id ||= SecureRandom.alphanumeric(6).downcase
|
10
10
|
permalink_id ||= SecureRandom.alphanumeric.downcase
|
11
11
|
image_id ||= SecureRandom.alphanumeric
|
12
12
|
new(
|
13
|
-
mime_type: mime_type,
|
14
13
|
kind: "t3",
|
15
14
|
data: {
|
16
15
|
id: post_id,
|
@@ -20,22 +20,6 @@ module Brutalismbot
|
|
20
20
|
File.join("team=#{team_id}", "channel=#{channel_id}", "oauth.json")
|
21
21
|
end
|
22
22
|
|
23
|
-
def push(post, dryrun:nil)
|
24
|
-
body = post.to_slack.to_json
|
25
|
-
uri = URI.parse(webhook_url)
|
26
|
-
Brutalismbot.logger.info("POST #{"DRYRUN " if dryrun}#{uri}")
|
27
|
-
unless dryrun
|
28
|
-
ssl = uri.scheme == "https"
|
29
|
-
req = Net::HTTP::Post.new(uri, "content-type" => "application/json")
|
30
|
-
req.body = body
|
31
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
|
32
|
-
http.request(req)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
Net::HTTPOK.new("1.1", "204", "ok")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
23
|
def team_id
|
40
24
|
@item.dig("team_id")
|
41
25
|
end
|
@@ -37,11 +37,16 @@ module Brutalismbot
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def push(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def push(body:, webhook_url:, dryrun:nil)
|
41
|
+
Brutalismbot.logger.info("POST #{"DRYRUN " if dryrun}#{webhook_url}")
|
42
|
+
unless dryrun
|
43
|
+
uri = URI.parse(webhook_url)
|
44
|
+
ssl = uri.scheme == "https"
|
45
|
+
req = Net::HTTP::Post.new(uri, "content-type" => "application/json")
|
46
|
+
req.body = body.to_json
|
47
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) {|http| http.request(req) }
|
48
|
+
else
|
49
|
+
Net::HTTPOK.new("1.1", "204", "ok")
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
@@ -19,22 +19,15 @@ module Brutalismbot
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def push(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def push_image(post, dryrun:nil)
|
33
|
-
Brutalismbot.logger.info("GET #{post.media_uri}")
|
34
|
-
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
|
35
|
-
post.media_uri.open do |media|
|
36
|
-
@client.update_with_media(post.to_twitter, media)
|
37
|
-
end unless dryrun
|
22
|
+
def push(status:, media_url:nil, dryrun:nil)
|
23
|
+
if media_url.nil?
|
24
|
+
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
|
25
|
+
@client.update(status) unless dryrun
|
26
|
+
else
|
27
|
+
Brutalismbot.logger.info("GET #{media_url}")
|
28
|
+
Brutalismbot.logger.info("PUSH #{"DRYRUN " if dryrun}twitter://@brutalismbot")
|
29
|
+
URI.open(media_url) {|media| @client.update_with_media(status, media) } unless dryrun
|
30
|
+
end
|
38
31
|
end
|
39
32
|
end
|
40
33
|
end
|
data/lib/brutalismbot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brutalismbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Mancevice
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -24,118 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '7.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws-sdk-s3
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.0'
|
48
|
-
type: :development
|
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: dotenv
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.7'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.7'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.13'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.13'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rake
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '13.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '13.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.8'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.8'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "<"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.18'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "<"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.18'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: webmock
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '3.6'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '3.6'
|
139
27
|
description: 'A Slack app that mirrors posts from /r/brutalism to a #channel of your
|
140
28
|
choosing using incoming webhooks.'
|
141
29
|
email:
|