reddit-to-telegram 0.7.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 667847008d3eeff44d452a47a6bcc0737cef0c3ecb75554c01c8ea7104a87d49
4
- data.tar.gz: 0e0a9e231c2dfe7c40c09511a4d7ec4a5cf82e759b3731473921d4c649ceb368
3
+ metadata.gz: '08430693bae08f13ed579d54b5647c7a08e2f41cc9b56d5f5b81de3c2a6ae843'
4
+ data.tar.gz: 6e84d4876a8168ba5a7eee55b00e65529487f45a06bccc7df421a0579af3859c
5
5
  SHA512:
6
- metadata.gz: 472c7cfda620d8d19871204fed27fc117a84fec638ab4a7c53820c15e650d7752c7fd9ad34813fb3286424939f1e619914593373a8d12de20edabc4bc02e4b12
7
- data.tar.gz: 1afd6608049236795ca77ee797d9b2c4f3ce811e9c7caed9688abb3b8639a8bb5108b77e3712cb2209ee8e6f1f12a70c4dbddcd7547e394a47026927fd8bf6fd
6
+ metadata.gz: ee7c43b1db322d243a46f555821f13d81fbdf2651fa9af8ee949bf44dacc6225dd2b63762643b5fbc3008f59985d4d1f100e883aa2bec4d4acc9c18375d8f721
7
+ data.tar.gz: 39b4de9770189c74240f77c8dc07be38ede2f656e9d385afbd0ee221d87c6bd1d90c482f3d8345ae74d985f39deb1a3fc4d87f8bda6218fb9bbf7bb359f7cb08
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mark Tityuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -35,8 +35,10 @@ module RedditToTelegram
35
35
  end
36
36
 
37
37
  def format_image_post(data)
38
+ post_type = data["url"]&.split(".")&.last == "gif" ? :gif : :image
39
+
38
40
  base_post_format_attrs(data).merge(
39
- { type: :image,
41
+ { type: post_type,
40
42
  media: data["url"] }
41
43
  )
42
44
  end
@@ -52,10 +54,17 @@ module RedditToTelegram
52
54
  end
53
55
 
54
56
  def format_gallery_post(data)
55
- base_post_format_attrs(data).merge(
56
- { type: :gallery,
57
- media: prepare_gallery_links(data) }
58
- )
57
+ gallery_links = prepare_gallery_links(data)
58
+
59
+ gallery_attrs = {
60
+ type: :gallery,
61
+ media: gallery_links.first(10)
62
+ }
63
+
64
+ remaining_links = gallery_links.drop(10)
65
+ gallery_attrs[:additional_media] = remaining_links unless remaining_links.empty?
66
+
67
+ base_post_format_attrs(data).merge(gallery_attrs)
59
68
  end
60
69
 
61
70
  def format_video_post(data)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../post"
4
+
5
+ module RedditToTelegram
6
+ module Telegram
7
+ class Post
8
+ class Gallery
9
+ class << self
10
+ def push_remaining_gallery_data(post, channel, res, opts = {})
11
+ if post[:additional_media]
12
+ push_remaining_gallery_images(post, channel, opts)
13
+ else
14
+ push_gallery_caption(post, channel, res, opts)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def push_remaining_gallery_images(post, channel,opts = {})
21
+ post[:media] = post[:additional_media].first(10)
22
+ remaining = post.delete(:additional_media).drop(10)
23
+ post[:additional_media] = remaining unless remaining.empty?
24
+ Post.push(post, channel, opts)
25
+ end
26
+
27
+ def push_gallery_caption(post, channel, res, opts = {})
28
+ Post.push(
29
+ { type: :text,
30
+ id: post[:id],
31
+ text: post[:text] },
32
+ channel,
33
+ opts.merge(gallery_caption_opts(res, opts))
34
+ )
35
+ end
36
+
37
+ def gallery_caption_opts(res)
38
+ gallery_caption_options = { disable_link_preview: true }
39
+ reply_to = res.dig("result", 0, "message_id")
40
+ return gallery_caption_options if reply_to.nil?
41
+
42
+ gallery_caption_options[:reply_to] = reply_to
43
+ gallery_caption_options
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "httparty"
4
+ require_relative "post/gallery"
4
5
  require_relative "prepare_request"
5
6
  require_relative "video"
6
7
  require_relative "../variables"
@@ -16,6 +17,7 @@ module RedditToTelegram
16
17
  METHOD_MAP = {
17
18
  image: :photo,
18
19
  gallery: :mediagroup,
20
+ gif: :animation,
19
21
  text: :message,
20
22
  video: :video
21
23
  }.freeze
@@ -46,24 +48,11 @@ module RedditToTelegram
46
48
 
47
49
  def handle_response(post, channel, res, opts = {})
48
50
  push_error(post, channel, res, opts) unless res["ok"] || opts[:no_retry]
49
- push_gallery_caption(post, channel, res, opts) if post[:type] == :gallery
51
+ Gallery.push_remaining_gallery_data(post, channel, res, opts) if post[:type] == :gallery
50
52
  Video.delete_file if post[:type] == :video && post.dig(:misc)&.dig(:binary)
51
53
  res
52
54
  end
53
55
 
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
56
  def push_error(post, channel, res, opts = {})
68
57
  return if Variables.telegram.error_channel_id.to_s.empty?
69
58
 
@@ -22,6 +22,8 @@ module RedditToTelegram
22
22
  { chat_id: "@#{chat_id}", photo: post[:media], caption: prepare_text(post, chat_id, opts) }
23
23
  when :gallery
24
24
  { chat_id: "@#{chat_id}", media: prepare_gallery_media(post), caption: prepare_text(post, chat_id, opts) }
25
+ when :gif
26
+ { chat_id: "@#{chat_id}", animation: post[:media], caption: prepare_text(post, chat_id, opts) }
25
27
  when :text
26
28
  { chat_id: "@#{chat_id}", text: prepare_text(post, chat_id, opts) }
27
29
  when :video
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedditToTelegram
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.1"
5
5
  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.7.0
4
+ version: 0.7.1
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-16 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-simpledb
@@ -63,6 +63,7 @@ files:
63
63
  - ".tool-versions"
64
64
  - Gemfile
65
65
  - Gemfile.lock
66
+ - LICENSE
66
67
  - README.md
67
68
  - lib/reddit-to-telegram.rb
68
69
  - lib/reddit_to_telegram/errors.rb
@@ -77,6 +78,7 @@ files:
77
78
  - lib/reddit_to_telegram/store/memory.rb
78
79
  - lib/reddit_to_telegram/store/temp_file.rb
79
80
  - lib/reddit_to_telegram/telegram/post.rb
81
+ - lib/reddit_to_telegram/telegram/post/gallery.rb
80
82
  - lib/reddit_to_telegram/telegram/prepare_request.rb
81
83
  - lib/reddit_to_telegram/telegram/video.rb
82
84
  - lib/reddit_to_telegram/variables.rb