reddit-to-telegram 0.6.1 → 0.7.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667847008d3eeff44d452a47a6bcc0737cef0c3ecb75554c01c8ea7104a87d49
|
4
|
+
data.tar.gz: 0e0a9e231c2dfe7c40c09511a4d7ec4a5cf82e759b3731473921d4c649ceb368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 472c7cfda620d8d19871204fed27fc117a84fec638ab4a7c53820c15e650d7752c7fd9ad34813fb3286424939f1e619914593373a8d12de20edabc4bc02e4b12
|
7
|
+
data.tar.gz: 1afd6608049236795ca77ee797d9b2c4f3ce811e9c7caed9688abb3b8639a8bb5108b77e3712cb2209ee8e6f1f12a70c4dbddcd7547e394a47026927fd8bf6fd
|
data/README.md
CHANGED
@@ -22,19 +22,20 @@ Or `gem install reddit-to-telegram`. Don't forget to `require` it.
|
|
22
22
|
- [Obtain a telegram bot token](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)
|
23
23
|
|
24
24
|
To run it, you'll need some env variables set.
|
25
|
-
| Variable Name
|
26
|
-
| -------------
|
27
|
-
| RTT_AWS_ACCESS_KEY_ID
|
28
|
-
| RTT_AWS_DOMAIN_NAME
|
29
|
-
| RTT_AWS_REGION
|
30
|
-
| RTT_AWS_SECRET_ACCESS_KEY
|
31
|
-
| RTT_GOOGLE_API_KEY
|
32
|
-
| RTT_MAX_STORED_POSTS
|
33
|
-
| RTT_REDDIT_CLIENT_ID
|
34
|
-
| RTT_REDDIT_CLIENT_SECRET
|
35
|
-
| RTT_STORE_TYPE
|
36
|
-
| RTT_TELEGRAM_BOT_TOKEN
|
37
|
-
|
|
25
|
+
| Variable Name | Description | Required |
|
26
|
+
| ------------- | ----------- | -------- |
|
27
|
+
| RTT_AWS_ACCESS_KEY_ID | Your AWS access key ID. Needed for AWS SimpleDB storage | No |
|
28
|
+
| RTT_AWS_DOMAIN_NAME | Domain name to use for SimpleDB | No |
|
29
|
+
| RTT_AWS_REGION | AWS region your SimpleDB will be hosted on. Beware, it's not available in all regions. | No |
|
30
|
+
| RTT_AWS_SECRET_ACCESS_KEY | Your AWS access key ID. Needed for AWS SimpleDB storage. | No |
|
31
|
+
| RTT_GOOGLE_API_KEY | Your Google API key to translate posts via Google Translate. | No |
|
32
|
+
| RTT_MAX_STORED_POSTS | Number of posts to store in the database to avoid duplicates, default is 25. | No |
|
33
|
+
| RTT_REDDIT_CLIENT_ID | Reddit app credentials to access API. Reddit allows more authenticated requests. | No |
|
34
|
+
| RTT_REDDIT_CLIENT_SECRET | Reddit app credentials to access API. Reddit allows more authenticated requests. | No |
|
35
|
+
| RTT_STORE_TYPE | Choose between `aws_simple_db`, `memory` or `temp_file`. Default is `aws_simple_db`, so if you're not specifying your AWS credentials, you have to choose another store type. | No |
|
36
|
+
| RTT_TELEGRAM_BOT_TOKEN | The token you've received when you've created a telegram bot. | Yes |
|
37
|
+
| RTT_TELEGRAM_ERROR_CHANNEL_ID | Telegram channel to send errors to (without `@`, only errors from Telegram API responses would be sent for now) | No |
|
38
|
+
| RTT_TEMP_DIR | Directory to write temp files to without trailing `/` | No |
|
38
39
|
|
39
40
|
|
40
41
|
You can also set them dynamically:
|
@@ -27,9 +27,7 @@ module RedditToTelegram
|
|
27
27
|
**params(post, channel, opts)
|
28
28
|
)
|
29
29
|
|
30
|
-
|
31
|
-
Video.delete_file if post[:type] == :video && post.dig(:misc)&.dig(:binary)
|
32
|
-
res
|
30
|
+
handle_response(post, channel, res, opts)
|
33
31
|
end
|
34
32
|
|
35
33
|
private
|
@@ -45,6 +43,44 @@ module RedditToTelegram
|
|
45
43
|
pars[:multipart] = true if binary
|
46
44
|
pars
|
47
45
|
end
|
46
|
+
|
47
|
+
def handle_response(post, channel, res, opts = {})
|
48
|
+
push_error(post, channel, res, opts) unless res["ok"] || opts[:no_retry]
|
49
|
+
push_gallery_caption(post, channel, res, opts) if post[:type] == :gallery
|
50
|
+
Video.delete_file if post[:type] == :video && post.dig(:misc)&.dig(:binary)
|
51
|
+
res
|
52
|
+
end
|
53
|
+
|
54
|
+
def push_gallery_caption(post, channel, res, opts = {})
|
55
|
+
push({ type: :text, id: post[:id], text: post[:text] }, channel, opts.merge(gallery_caption_opts(res)))
|
56
|
+
end
|
57
|
+
|
58
|
+
def gallery_caption_opts(res)
|
59
|
+
gallery_caption_options = { disable_link_preview: true }
|
60
|
+
reply_to = res.dig("result", 0, "message_id")
|
61
|
+
return gallery_caption_options if reply_to.nil?
|
62
|
+
|
63
|
+
gallery_caption_options[:reply_to] = reply_to
|
64
|
+
gallery_caption_options
|
65
|
+
end
|
66
|
+
|
67
|
+
def push_error(post, channel, res, opts = {})
|
68
|
+
return if Variables.telegram.error_channel_id.to_s.empty?
|
69
|
+
|
70
|
+
push(
|
71
|
+
{
|
72
|
+
type: :text,
|
73
|
+
id: post[:id],
|
74
|
+
text: "Channel: @#{channel}\n\nResponse: #{res}"
|
75
|
+
},
|
76
|
+
Variables.telegram.error_channel_id,
|
77
|
+
opts.merge(
|
78
|
+
add_reddit_link: true,
|
79
|
+
disable_link_preview: true,
|
80
|
+
no_retry: true
|
81
|
+
)
|
82
|
+
)
|
83
|
+
end
|
48
84
|
end
|
49
85
|
end
|
50
86
|
end
|
@@ -8,6 +8,15 @@ module RedditToTelegram
|
|
8
8
|
class PrepareRequest
|
9
9
|
class << self
|
10
10
|
def body(post, chat_id, opts = {})
|
11
|
+
body = prepare_body(post, chat_id, opts)
|
12
|
+
body[:link_preview_options] = { is_disabled: true } if opts[:disable_link_preview]
|
13
|
+
body[:reply_parameters] = { message_id: opts[:reply_to] } if opts[:reply_to]
|
14
|
+
body
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def prepare_body(post, chat_id, opts = {})
|
11
20
|
case post[:type]
|
12
21
|
when :image
|
13
22
|
{ chat_id: "@#{chat_id}", photo: post[:media], caption: prepare_text(post, chat_id, opts) }
|
@@ -26,8 +35,6 @@ module RedditToTelegram
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
|
-
private
|
30
|
-
|
31
38
|
def prepare_text(post, chat_id, opts = {})
|
32
39
|
text = post[:text]
|
33
40
|
|
@@ -104,11 +104,15 @@ module RedditToTelegram
|
|
104
104
|
|
105
105
|
class Telegram
|
106
106
|
class << self
|
107
|
-
attr_writer :bot_token
|
107
|
+
attr_writer :bot_token, :error_channel_id
|
108
108
|
|
109
109
|
def bot_token
|
110
110
|
@bot_token ||= ENV["RTT_TELEGRAM_BOT_TOKEN"]
|
111
111
|
end
|
112
|
+
|
113
|
+
def error_channel_id
|
114
|
+
@error_channel_id ||= ENV["RTT_TELEGRAM_ERROR_CHANNEL_ID"]
|
115
|
+
end
|
112
116
|
end
|
113
117
|
end
|
114
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit-to-telegram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Tityuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-simpledb
|