reddit-to-telegram 0.7.0 → 0.7.2

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: 667847008d3eeff44d452a47a6bcc0737cef0c3ecb75554c01c8ea7104a87d49
4
- data.tar.gz: 0e0a9e231c2dfe7c40c09511a4d7ec4a5cf82e759b3731473921d4c649ceb368
3
+ metadata.gz: 64c3e44dd622e534404baf7a42ecd2bfab3c6a61ae0fb662f9803e674c626dcf
4
+ data.tar.gz: f7f48164b5746abded0025b5025e0b295e7c4f3287b65d2d2a58fd04bd8a577b
5
5
  SHA512:
6
- metadata.gz: 472c7cfda620d8d19871204fed27fc117a84fec638ab4a7c53820c15e650d7752c7fd9ad34813fb3286424939f1e619914593373a8d12de20edabc4bc02e4b12
7
- data.tar.gz: 1afd6608049236795ca77ee797d9b2c4f3ce811e9c7caed9688abb3b8639a8bb5108b77e3712cb2209ee8e6f1f12a70c4dbddcd7547e394a47026927fd8bf6fd
6
+ metadata.gz: e2e562fbb1831955bb921311e963c02ed3dbf6a05e46d93fb729a2604b15397f0dda97afee91c1fd967d83b5196a4ff311cf286b352e4e6cf5a59e15e2cb537d
7
+ data.tar.gz: 644e1ef22281b1ba0a97c419a321c1ec9f00e3e71b41d25c998a6e9a7820c60bff9e38c2eec7f514c23962671d7460ec546ac129d6f31a5fcda5ad4f0af010be
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))
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.2"
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.2
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