reddit-to-telegram 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 141226c6670a9b95e6ec4f7a9e74da982ed135ac22d57173c39625d4c1acfb11
4
- data.tar.gz: 05c3a7b11a49162ed3742abfa3b2ea38a39048393133f9e1b16130b6c8c747ec
3
+ metadata.gz: '05893e8e006a0f401dbcec8e91cfd46be3cf3b53bbc1c9e89ccd95620db3087c'
4
+ data.tar.gz: 62ef80526ab1051177eafcab26de219b6d196262024c473dc53813fcbac32365
5
5
  SHA512:
6
- metadata.gz: bca6427e5ab1fe8fd76f2e11f0b0101f624f37874915b056731385ba74f4b584aed9b7180b7ae380227db1745b15538ecdd2df4cdbf0c8b0f0ecabed17e571d5
7
- data.tar.gz: bd53e70c0a7587af11fc27016e236205b4966ba5c4cd2bdfad1eedc72170abe035ad21945dc2c9933198608e8517053f7e467733cb36acf8c36c4efdcf198879
6
+ metadata.gz: 4319bf2ff9cbe27433514492093865c55ee65a77ef6d1eaae1a89376ea37cf0b16a998856b8f5c7ad21f7442d4ca2aca9f710d74fd40a7def9d8859f429d0dee
7
+ data.tar.gz: 58a917a293a78fdca894d5249114d26f19c79d27574ea02d3f412152aec321a45fb7ebc6672e63e46ebafcad5c3ed561867ace3420b15a1dd5b77d33d26ad392
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Beware, this is remotely not production-ready, API will change, you'll see lots of bugs and it may break at any time.
8
8
  Be sure to check for gem updates.
9
9
 
10
- You can set this bot up absolutely for free [via AWS Lambda](https://gist.github.com/dersnek/851c32a6b45eab19f1c8748095b2a481#file-free-rtt-bot-in-aws-lambda).
10
+ You can set this bot up absolutely for free [via AWS Lambda](https://gist.github.com/dersnek/851c32a6b45eab19f1c8748095b2a481#file-free-rtt-bot-in-aws-lambda), no ruby knowledge required.
11
11
 
12
12
  ## Installation
13
13
  In your `Gemfile` add:
@@ -19,33 +19,34 @@ Then run `bundle install`.
19
19
  Or `gem install reddit-to-telegram`. Don't forget to `require` it.
20
20
 
21
21
  ## Prerequisites
22
+ - [Obtain a telegram bot token](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)
22
23
  - (Optionally) You'll need an [AWS account](https://aws.amazon.com/) to host a free SimpleDB (best available storage type, also default one). I also recommend hosting the bot on AWS lambda, since it would be free.
23
24
  - (Optionally) [Create a Reddit app](https://www.reddit.com/prefs/apps), which would allow more requests to reddit
24
- - [Obtain a telegram bot token](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)
25
25
 
26
- To run it, you'll need some env variables set.
27
- | Variable Name | Description | Required |
28
- | ------------- | ----------- | -------- |
29
- | RTT_AWS_ACCESS_KEY_ID | Your AWS access key ID. Needed for AWS SimpleDB storage | No |
30
- | RTT_AWS_DOMAIN_NAME | Domain name to use for SimpleDB | No |
31
- | RTT_AWS_REGION | AWS region your SimpleDB will be hosted on. Beware, it's not available in all regions. | No |
32
- | RTT_AWS_SECRET_ACCESS_KEY | Your AWS access key ID. Needed for AWS SimpleDB storage. | No |
33
- | RTT_GOOGLE_API_KEY | Your Google API key to translate posts via Google Translate. | No |
34
- | RTT_MAX_STORED_POSTS | Number of posts to store in the database to avoid duplicates, default is 25. | No |
35
- | RTT_REDDIT_CLIENT_ID | Reddit app credentials to access API. Reddit allows more authenticated requests. | No |
36
- | RTT_REDDIT_CLIENT_SECRET | Reddit app credentials to access API. Reddit allows more authenticated requests. | No |
37
- | 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 |
38
- | RTT_TELEGRAM_BOT_TOKEN | The token you've received when you've created a telegram bot. | Yes |
39
- | RTT_TELEGRAM_ERROR_CHANNEL_ID | Telegram channel to send errors to (without `@`, only errors from Telegram API responses would be sent for now) | No |
40
- | RTT_TEMP_DIR | Directory to write temp files to without trailing `/` | No |
26
+ It is pretty congifurable, either dynamically or via ENV variables.
27
+ To assign variables dynamically, set them via `RedditToTelegram.config.variable_name= `, e.g. `RedditToTelegram.config.aws.access_key_id = ...`.
28
+ You can also create an ENV variable with a corresponding name. Here is the full configuration explained. Required options have a * next to them.
41
29
 
42
-
43
- You can also set them dynamically:
44
- ```
45
- RedditToTelegram.config.aws.access_key_id =
46
- RedditToTelegram.config.telegram.bot_token =
47
- ```
48
- Check out `lib/configuration` for full configuration.
30
+ Config variable | Corresponding ENV Variable | Description |
31
+ | ----------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
32
+ add_channel_handle | - | Add channel handle to Telegram posts. Accepted values: true or false. Default is false |
33
+ add_reddit_link | - | Add reddit link to Telegram posts. Accepted values: true or false. Default is false. |
34
+ logger | - | Which logger to use. You can pass your own ruby logger |
35
+ on_error | - | What to do when an error happens. Default is :log, but you can also :raise or :ignore |
36
+ send_errors_to_telegram | - | Also log errors to telegram (besides regular logging). Accepted values: true or false, default is false |
37
+ translate | - | Translate posts via Google Translate. Leave empty for no translation. More details below |
38
+ aws.access_key_id | RTT_AWS_ACCESS_KEY_ID | Your AWS access key ID. Needed for AWS SimpleDB storage |
39
+ aws.domain_name | RTT_AWS_DOMAIN_NAME | Domain name to use for SimpleDB |
40
+ aws.region | RTT_AWS_REGION | AWS region your SimpleDB will be hosted on. Beware, it's not available in all regions. |
41
+ aws.secret_access_key | RTT_AWS_SECRET_ACCESS_KEY | Your AWS access key ID. Needed for AWS SimpleDB storage. |
42
+ google.api_key | RTT_GOOGLE_API_KEY | Your Google API key to translate posts via Google Translate |
43
+ reddit.client_id | RTT_REDDIT_CLIENT_ID | Reddit app credentials to access API. Reddit allows more authenticated requests |
44
+ reddit.client_secret | RTT_REDDIT_CLIENT_SECRET | Reddit app credentials to access API. Reddit allows more authenticated requests |
45
+ store.max_stored_posts | RTT_MAX_STORED_POSTS | Number of posts to store in the database to avoid duplicates, default is 25 |
46
+ store.tmp_dir | RTT_TEMP_DIR | Directory to write temp files to without trailing `/` |
47
+ store.type | 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 |
48
+ telegram.bot_token * | RTT_TELEGRAM_BOT_TOKEN | The token you've received when you've created a telegram bot |
49
+ telegram.error_channel_id | RTT_TELEGRAM_ERROR_CHANNEL_ID | Telegram channel to send errors to (without `@`, only errors from Telegram API responses would be sent for now) |
49
50
 
50
51
  ## Usage
51
52
 
@@ -53,30 +54,19 @@ Check out `lib/configuration` for full configuration.
53
54
  2. To fetch latest hot post which hasn't been pushed yet:
54
55
  ```
55
56
  RedditToTelegram.hot(
56
- subreddit_name_1: :telegram_channel_id_1,
57
- subreddit_name_2: :telegram_channel_id_2
57
+ telegram_channel_id_1: :subreddit_name_1,
58
+ telegram_channel_id_2: :subreddit_name_2
58
59
  )
59
60
  ```
60
- Or to push one specific post (the only thing you need to set up for this is your telegram bot token):
61
+ You can push posts from one subreddit to one telegram channel, several-to-one, one-to-several, several-to-several, whatever you like.
62
+ You can also push one specific post:
61
63
  ```
62
- RedditToTelegram.from_link("regular_link_to_post", :telegram_channel_id)
64
+ RedditToTelegram.from_link(telegram_channel_id: "regular_link_to_post")
63
65
  ```
64
66
  Use `:telegram_channel_id` without the `@`.
65
67
 
66
- ### Options
68
+ ### Translation
67
69
 
68
- Translate option is supported. You will have to set up Google Translate API key and add it to env. You can find available languages in [Google Translate docs](https://cloud.google.com/translate/docs/languages).
69
- ```
70
- RedditToTelegram.hot(
71
- { subreddit_name_1: :telegram_channel_id_1 },
72
- translate: :ja
73
- )
74
- ```
75
- You can also specify if you want to add reddit link or telegram channel handle to the post text. By default they won't be added.
76
- ```
77
- RedditToTelegram.hot(
78
- { subreddit_name_1: :telegram_channel_id_1 },
79
- add_reddit_link: true,
80
- add_channel_handle: true
81
- )
82
- ```
70
+ Translation option is supported.
71
+ You will have to set `RedditToTelegram.config.translate` to the language key you want to translate to. You can find available languages in [Google Translate docs](https://cloud.google.com/translate/docs/languages).
72
+ You will also have to set up Google Translate API key assign it to `RedditToTelegram.config.google.api_key`.
@@ -5,7 +5,16 @@ require "logger"
5
5
  module RedditToTelegram
6
6
  module Configuration
7
7
  class << self
8
- attr_writer :logger, :on_error
8
+ attr_writer :add_channel_handle, :add_reddit_link, :logger,
9
+ :on_error, :send_errors_to_telegram, :translate
10
+
11
+ def add_channel_handle
12
+ @add_channel_handle ||= false
13
+ end
14
+
15
+ def add_reddit_link
16
+ @add_reddit_link ||= false
17
+ end
9
18
 
10
19
  def logger
11
20
  @logger ||= Logger.new($stdout).tap do |log|
@@ -16,6 +25,14 @@ module RedditToTelegram
16
25
  def on_error
17
26
  @on_error ||= :log
18
27
  end
28
+
29
+ def send_errors_to_telegram
30
+ @send_errors_to_telegram ||= false
31
+ end
32
+
33
+ def translate
34
+ @translate ||= nil
35
+ end
19
36
  end
20
37
 
21
38
  class Store
@@ -3,19 +3,48 @@
3
3
  module RedditToTelegram
4
4
  class RedditToTelegramError < StandardError; end
5
5
 
6
+ class BadResponseFromTelegram < RedditToTelegramError; end
7
+ class FailedToFetchFromReddit < RedditToTelegramError; end
6
8
  class InvalidStoreType < RedditToTelegramError; end
7
9
  class MissingConfiguration < RedditToTelegramError; end
8
10
 
9
11
  class Errors
10
12
  class << self
11
13
  def new(error, message = nil)
14
+ log_message = error.to_s
15
+ log_message += ": #{message}" unless message.nil?
16
+
12
17
  if Configuration.on_error == :raise
13
18
  raise(error.new(message))
14
19
  elsif Configuration.on_error == :log
15
- log_message = error.to_s
16
- log_message += ": #{message}" unless message.nil?
17
20
  Configuration.logger.error(log_message)
18
21
  end
22
+
23
+ return unless Configuration.send_errors_to_telegram
24
+
25
+ push_error_to_telegram(log_message)
26
+
27
+ nil
28
+ end
29
+
30
+ private
31
+
32
+ def push_error_to_telegram(message)
33
+ if Configuration.telegram.error_channel_id.to_s.empty?
34
+ Configuration.logger.warn("Telegram Error Channel ID is not set up, can't send errors there")
35
+ return
36
+ end
37
+
38
+ Telegram::Post.push(
39
+ {
40
+ type: :text,
41
+ text: message,
42
+ misc: { no_retry: true, disable_link_preview: true }
43
+ },
44
+ Configuration.telegram.error_channel_id
45
+ )
46
+
47
+ nil
19
48
  end
20
49
  end
21
50
  end
@@ -3,29 +3,27 @@
3
3
  module RedditToTelegram
4
4
  class Post
5
5
  class << self
6
- def hot(sources, opts = {})
6
+ def hot(sources)
7
7
  check_config
8
- return if sources.empty?
9
-
10
8
  Store.setup
11
9
 
12
- sources.each do |subreddit, telegram_chat_id|
10
+ sources.each do |telegram_chat_id, subreddit|
13
11
  res = Reddit::Fetch.hot(subreddit)
14
- handle_res(res, subreddit, telegram_chat_id, opts)
12
+ handle_res(res, subreddit, telegram_chat_id)
15
13
  end
16
14
  end
17
15
 
18
- def from_link(link, telegram_chat_id, opts = {})
16
+ def from_link(sources)
19
17
  check_config
20
- return if link.empty?
18
+ return unless check_from_link_sources(sources)
21
19
 
22
20
  Configuration.store.type = :memory
23
21
  Store.setup
24
22
 
25
- res = Reddit::Fetch.post(link)
23
+ res = Reddit::Fetch.post(sources.values.first)
26
24
  return unless res_ok?(res)
27
25
 
28
- Telegram::Post.push(res, telegram_chat_id, opts)
26
+ Telegram::Post.push(res, sources.keys.first)
29
27
  res
30
28
  end
31
29
 
@@ -35,13 +33,17 @@ module RedditToTelegram
35
33
  Errors.new(MissingConfiguration, "Missing Telegram bot token") if Configuration.telegram.bot_token.to_s.empty?
36
34
  end
37
35
 
38
- def handle_res(res, subreddit, telegram_chat_id, opts = {})
36
+ def handle_res(res, subreddit, telegram_chat_id)
39
37
  return unless res_ok?(res)
40
38
 
41
39
  post = find_new_post(subreddit, res)
42
- return if post.nil?
43
40
 
44
- res = Telegram::Post.push(post, telegram_chat_id, opts)
41
+ if post.nil?
42
+ Configuration.logger.info("Could not find a new post to push")
43
+ return
44
+ end
45
+
46
+ res = Telegram::Post.push(post, telegram_chat_id)
45
47
  Store::Posts.add(subreddit, post[:id])
46
48
  res
47
49
  end
@@ -50,7 +52,7 @@ module RedditToTelegram
50
52
  if res.nil?
51
53
  Configuration.logger.warn("Could not fetch Reddit post")
52
54
  false
53
- elsif res[:type].nil?
55
+ elsif res.is_a?(Hash) && res[:type].nil?
54
56
  Configuration.logger.warn("Could not determine Reddit post type")
55
57
  false
56
58
  else
@@ -61,6 +63,15 @@ module RedditToTelegram
61
63
  def find_new_post(subreddit, posts)
62
64
  posts.find { |post| !Store::Posts.dup?(subreddit, post[:id]) }
63
65
  end
66
+
67
+ def check_from_link_sources(sources)
68
+ if !sources.is_a?(Hash) || sources.keys.count != 1 || sources.values.count != 1
69
+ Errors.new(ArgumentError, "Check documentation on usage")
70
+ return false
71
+ end
72
+
73
+ true
74
+ end
64
75
  end
65
76
  end
66
77
  end
@@ -55,12 +55,22 @@ module RedditToTelegram
55
55
  handle_429(func_name, func_args)
56
56
  when 200
57
57
  Output.format_response(res)
58
+ else
59
+ Errors.new(FailedToFetchFromReddit, res.to_s)
58
60
  end
59
61
  end
60
62
 
61
63
  def handle_401(func_name, func_args)
64
+ retries_left = func_args.last
65
+ func_args[func_args.length - 1] = retries_left - 1
66
+
62
67
  Store::Reddit.token = Auth.token
63
- send(func_name, *func_args) if func_args.last > 0
68
+
69
+ if retries_left > 0
70
+ send(func_name, *func_args)
71
+ else
72
+ Errors.new(FailedToFetchFromReddit, "Failed to authenticate")
73
+ end
64
74
  end
65
75
 
66
76
  def handle_429(func_name, func_args)
@@ -68,7 +78,12 @@ module RedditToTelegram
68
78
 
69
79
  sleep(10 / retries_left) if retries_left > 0
70
80
  func_args[func_args.length - 1] = retries_left - 1
71
- send(func_name, *func_args) if retries_left > 0
81
+
82
+ if retries_left > 0
83
+ send(func_name, *func_args)
84
+ else
85
+ Errors.new(FailedToFetchFromReddit, "Too many requests")
86
+ end
72
87
  end
73
88
  end
74
89
  end
@@ -97,7 +97,8 @@ module RedditToTelegram
97
97
 
98
98
  def base_post_format_attrs(data)
99
99
  { id: data["name"],
100
- text: CGI.unescapeHTML(data["title"]) }
100
+ text: CGI.unescapeHTML(data["title"]),
101
+ misc: {} }
101
102
  end
102
103
 
103
104
  def prepare_gallery_links(data)
@@ -5,30 +5,30 @@ module RedditToTelegram
5
5
  class Post
6
6
  class Gallery
7
7
  class << self
8
- def push_remaining_gallery_data(post, channel, res, opts = {})
8
+ def push_remaining_gallery_data(post, channel, res)
9
9
  if post[:additional_media]
10
- push_remaining_gallery_images(post, channel, opts)
10
+ push_remaining_gallery_images(post, channel)
11
11
  else
12
- push_gallery_caption(post, channel, res, opts)
12
+ push_gallery_caption(post, channel, res)
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def push_remaining_gallery_images(post, channel,opts = {})
18
+ def push_remaining_gallery_images(post, channel)
19
19
  post[:media] = post[:additional_media].first(10)
20
20
  remaining = post.delete(:additional_media).drop(10)
21
21
  post[:additional_media] = remaining unless remaining.empty?
22
- Post.push(post, channel, opts)
22
+ Post.push(post, channel)
23
23
  end
24
24
 
25
- def push_gallery_caption(post, channel, res, opts = {})
25
+ def push_gallery_caption(post, channel, res)
26
26
  Telegram::Post.push(
27
27
  { type: :text,
28
28
  id: post[:id],
29
- text: post[:text] },
30
- channel,
31
- opts.merge(gallery_caption_opts(res))
29
+ text: post[:text],
30
+ misc: gallery_caption_opts(res) },
31
+ channel
32
32
  )
33
33
  end
34
34
 
@@ -19,20 +19,20 @@ module RedditToTelegram
19
19
  }.freeze
20
20
 
21
21
  class << self
22
- def push(post, channel, opts = {})
22
+ def push(post, channel)
23
23
  res = HTTParty.post(
24
24
  "#{BASE_URI}#{Configuration.telegram.bot_token}/send#{METHOD_MAP[post[:type]]}",
25
- **params(post, channel, opts)
25
+ **params(post, channel)
26
26
  )
27
27
 
28
- handle_response(post, channel, res, opts)
28
+ handle_response(post, channel, res)
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def params(post, channel, opts = {})
33
+ def params(post, channel)
34
34
  binary = post.dig(:misc)&.dig(:binary)
35
- body = PrepareRequest.body(post, channel, opts)
35
+ body = PrepareRequest.body(post, channel)
36
36
 
37
37
  pars = {
38
38
  body: binary ? body : body.to_json,
@@ -42,29 +42,16 @@ module RedditToTelegram
42
42
  pars
43
43
  end
44
44
 
45
- def handle_response(post, channel, res, opts = {})
46
- push_error(post, channel, res, opts) unless res["ok"] || opts[:no_retry]
47
- Gallery.push_remaining_gallery_data(post, channel, res, opts) if post[:type] == :gallery
48
- Video.delete_file if post[:type] == :video && post.dig(:misc)&.dig(:binary)
45
+ def handle_response(post, channel, res)
46
+ log_error(post, channel, res) unless res["ok"]
47
+ Gallery.push_remaining_gallery_data(post, channel, res) if post[:type] == :gallery
48
+ Video.delete_file if post[:type] == :video && post.dig(:misc, :binary)
49
49
  res
50
50
  end
51
51
 
52
- def push_error(post, channel, res, opts = {})
53
- return if Configuration.telegram.error_channel_id.to_s.empty?
54
-
55
- push(
56
- {
57
- type: :text,
58
- id: post[:id],
59
- text: "Channel: @#{channel}\n\nResponse: #{res}"
60
- },
61
- Configuration.telegram.error_channel_id,
62
- opts.merge(
63
- add_reddit_link: true,
64
- disable_link_preview: true,
65
- no_retry: true
66
- )
67
- )
52
+ def log_error(post, channel, res)
53
+ message = "\n\nChannel: #{channel}\n\nPost data: #{post}\n\nResponse: #{res}"
54
+ Errors.new(BadResponseFromTelegram, message)
68
55
  end
69
56
  end
70
57
  end
@@ -4,54 +4,65 @@ module RedditToTelegram
4
4
  module Telegram
5
5
  class PrepareRequest
6
6
  class << self
7
- def body(post, chat_id, opts = {})
8
- body = prepare_body(post, chat_id, opts)
9
- body[:link_preview_options] = { is_disabled: true } if opts[:disable_link_preview]
10
- body[:reply_parameters] = { message_id: opts[:reply_to] } if opts[:reply_to]
7
+ def body(post, chat_id)
8
+ body = prepare_body(post, chat_id)
9
+ body[:link_preview_options] = { is_disabled: true } if post.dig(:misc, :disable_link_preview)
10
+ body[:reply_parameters] = { message_id: post[:misc][:reply_to] } if post.dig(:misc, :reply_to)
11
11
  body
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- def prepare_body(post, chat_id, opts = {})
16
+ def prepare_body(post, chat_id)
17
17
  case post[:type]
18
18
  when :image
19
- { chat_id: "@#{chat_id}", photo: post[:media], caption: prepare_text(post, chat_id, opts) }
19
+ { chat_id: "@#{chat_id}", photo: post[:media], caption: prepare_text(post, chat_id) }
20
20
  when :gallery
21
- { chat_id: "@#{chat_id}", media: prepare_gallery_media(post), caption: prepare_text(post, chat_id, opts) }
21
+ { chat_id: "@#{chat_id}", media: prepare_gallery_media(post), caption: prepare_text(post, chat_id) }
22
22
  when :gif
23
- { chat_id: "@#{chat_id}", animation: post[:media], caption: prepare_text(post, chat_id, opts) }
23
+ { chat_id: "@#{chat_id}", animation: post[:media], caption: prepare_text(post, chat_id) }
24
24
  when :text
25
- { chat_id: "@#{chat_id}", text: prepare_text(post, chat_id, opts) }
25
+ { chat_id: "@#{chat_id}", text: prepare_text(post, chat_id) }
26
26
  when :video
27
27
  {
28
28
  chat_id: "@#{chat_id}",
29
29
  video: prepare_video(post),
30
30
  height: post[:misc][:video_height],
31
31
  width: post[:misc][:video_width],
32
- caption: prepare_text(post, chat_id, opts)
32
+ caption: prepare_text(post, chat_id)
33
33
  }
34
34
  end
35
35
  end
36
36
 
37
- def prepare_text(post, chat_id, opts = {})
37
+ def prepare_text(post, chat_id)
38
38
  text = post[:text]
39
39
 
40
- text = Services::Translate.text(text, opts[:translate]) if opts[:translate]
40
+ text = translate(text)
41
+ text = add_reddit_link(text, post)
42
+ add_channel_handle(text, chat_id)
43
+ end
41
44
 
42
- if opts[:add_reddit_link]
43
- id = post[:id].split("_")[1]
44
- text += "\n\nhttps://redd.it/#{id}"
45
- end
45
+ def translate(text)
46
+ return text unless Configuration.translate
46
47
 
47
- if opts[:add_channel_handle]
48
- text += opts[:add_reddit_link] ? "\n" : "\n\n"
49
- text += "@#{chat_id}"
50
- end
48
+ Services::Translate.text(text, Configuration.translate)
49
+ end
51
50
 
51
+ def add_reddit_link(text, post)
52
+ return text unless Configuration.add_reddit_link
53
+
54
+ id = post[:id]&.split("_")&.dig(1)
55
+ text += "\n\nhttps://redd.it/#{id}" if id
52
56
  text
53
57
  end
54
58
 
59
+ def add_channel_handle(text, chat_id)
60
+ return text unless Configuration.add_channel_handle
61
+
62
+ text += Configuration.add_reddit_link ? "\n" : "\n\n"
63
+ text + "@#{chat_id}"
64
+ end
65
+
55
66
  def prepare_gallery_media(post)
56
67
  Array(post[:media]).map { |link| { type: "photo", media: link } }
57
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedditToTelegram
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit-to-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Tityuk