telepost 0.9.0 → 0.11.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: 847510fbfea002fc65ee0a20dbc39dd2c5ede53aab590c5a8aa2ed66f2bdc50e
4
- data.tar.gz: '086d01f73bff093ef51dbbcb67757d48d21a37211131ca6522e5b2f25901345b'
3
+ metadata.gz: 669da4747151d6e7c97dd90ef240f9b702b17e8d80196351fba8d974a3516da4
4
+ data.tar.gz: d5454663c1acad864f0dc1a39fa68252d2a7dcf309dad3b59f76e15d0f171782
5
5
  SHA512:
6
- metadata.gz: 77b5815fcaa702a9a0c422b7633e4992cb7824d79e0c0eb0a77ce03bd4e58464463eab5a3a154e47c4aad0704601d9fc7fa43c1c3fb2656401e88d1d4bd4df04
7
- data.tar.gz: 4e9334873a9a5e0e9e7c92828b657fbc00b9f822e6c471f6c57bc7b582e3a54b6c6dde6a3c332de43614cffe7c31485678f8206f8fff7ee185ba9c6dc1f65142
6
+ metadata.gz: 830a1c67439bc7f92afc8e23f75094c831e2d4f56113aa086471f877ca60bf6f28910a02e483701a2a154ee8141ba0dfdbbd3f63beba79f006fd2c1270db78c4
7
+ data.tar.gz: db75e8685f6ac4266807fe4c652eaf36ebba7fea3ac687ce8fb7619a42e0eb819dc1ff72efcf1ffbbc86f26dc2bd2825481c050c69a673955f789803853904f9
data/Gemfile.lock CHANGED
@@ -11,9 +11,9 @@ GEM
11
11
  public_suffix (>= 2.0.2, < 8.0)
12
12
  ansi (1.6.0)
13
13
  ast (2.4.3)
14
- bigdecimal (4.1.2)
14
+ bigdecimal (4.1.3)
15
15
  builder (3.3.0)
16
- concurrent-ruby (1.3.6)
16
+ concurrent-ruby (1.3.7)
17
17
  crack (1.0.1)
18
18
  bigdecimal
19
19
  rexml
@@ -41,18 +41,18 @@ GEM
41
41
  dry-inflector (~> 1.0)
42
42
  dry-logic (~> 1.4)
43
43
  zeitwerk (~> 2.6)
44
- faraday (2.14.2)
44
+ faraday (2.14.3)
45
45
  faraday-net_http (>= 2.0, < 3.5)
46
46
  json
47
47
  logger
48
48
  faraday-multipart (1.2.0)
49
49
  multipart-post (~> 2.0)
50
- faraday-net_http (3.4.3)
50
+ faraday-net_http (3.4.4)
51
51
  net-http (~> 0.5)
52
52
  hashdiff (1.2.1)
53
53
  ice_nine (0.11.2)
54
- json (2.19.5)
55
- language_server-protocol (3.17.0.5)
54
+ json (2.21.2)
55
+ language_server-protocol (3.17.0.6)
56
56
  lint_roller (1.1.0)
57
57
  logger (1.7.0)
58
58
  minitest (6.0.6)
@@ -66,8 +66,8 @@ GEM
66
66
  multipart-post (2.4.1)
67
67
  net-http (0.9.1)
68
68
  uri (>= 0.11.1)
69
- parallel (2.1.0)
70
- parser (3.3.11.1)
69
+ parallel (2.3.0)
70
+ parser (3.3.12.0)
71
71
  ast (~> 2.4.1)
72
72
  racc
73
73
  prism (1.9.0)
@@ -75,32 +75,32 @@ GEM
75
75
  racc (1.8.1)
76
76
  rainbow (3.1.1)
77
77
  rake (13.4.2)
78
- regexp_parser (2.12.0)
78
+ regexp_parser (2.13.1)
79
79
  rexml (3.4.4)
80
- rubocop (1.86.2)
81
- json (~> 2.3)
80
+ rubocop (1.92.0)
81
+ json (>= 2.3)
82
82
  language_server-protocol (~> 3.17.0.2)
83
83
  lint_roller (~> 1.1.0)
84
84
  parallel (>= 1.10)
85
85
  parser (>= 3.3.0.2)
86
86
  rainbow (>= 2.2.2, < 4.0)
87
- regexp_parser (>= 2.9.3, < 3.0)
87
+ regexp_parser (>= 2.11.3, < 3.0)
88
88
  rubocop-ast (>= 1.49.0, < 2.0)
89
89
  ruby-progressbar (~> 1.7)
90
90
  unicode-display_width (>= 2.4.0, < 4.0)
91
- rubocop-ast (1.49.1)
91
+ rubocop-ast (1.50.0)
92
92
  parser (>= 3.3.7.2)
93
93
  prism (~> 1.7)
94
94
  rubocop-elegant (0.5.1)
95
95
  lint_roller (~> 1.1)
96
96
  rubocop (~> 1.75)
97
- rubocop-minitest (0.39.1)
97
+ rubocop-minitest (0.41.0)
98
98
  lint_roller (~> 1.1)
99
- rubocop (>= 1.75.0, < 2.0)
99
+ rubocop (>= 1.89.0, < 2.0)
100
100
  rubocop-ast (>= 1.38.0, < 2.0)
101
- rubocop-performance (1.26.1)
101
+ rubocop-performance (1.27.0)
102
102
  lint_roller (~> 1.1)
103
- rubocop (>= 1.75.0, < 2.0)
103
+ rubocop (>= 1.89.0, < 2.0)
104
104
  rubocop-ast (>= 1.47.1, < 2.0)
105
105
  rubocop-rake (0.7.1)
106
106
  lint_roller (~> 1.1)
@@ -120,15 +120,15 @@ GEM
120
120
  faraday (~> 2.0)
121
121
  faraday-multipart (~> 1.0)
122
122
  zeitwerk (~> 2.6)
123
- unicode-display_width (3.2.0)
124
- unicode-emoji (~> 4.1)
125
- unicode-emoji (4.2.0)
123
+ unicode-display_width (3.3.0)
124
+ unicode-emoji (~> 4.3)
125
+ unicode-emoji (4.3.0)
126
126
  uri (1.1.1)
127
- webmock (3.26.2)
127
+ webmock (3.29.0)
128
128
  addressable (>= 2.8.0)
129
129
  crack (>= 0.3.2)
130
130
  hashdiff (>= 0.4.0, < 2.0.0)
131
- yard (0.9.44)
131
+ yard (0.9.45)
132
132
  zeitwerk (2.8.2)
133
133
 
134
134
  PLATFORMS
data/README.md CHANGED
@@ -27,8 +27,8 @@ Then, use it like this:
27
27
  require 'telepost'
28
28
  tp = Telepost.new('..token..')
29
29
  Thread.start do
30
- tp.run do |chat, msg|
31
- tp.post(chat, 'Thanks for talking to me!')
30
+ tp.run do |chat, msg, user|
31
+ tp.post(chat, "Thanks for talking to me, @#{user}!")
32
32
  end
33
33
  end
34
34
  tp.post(12345, 'How are you?', 'How are you doing?')
@@ -46,13 +46,15 @@ tp = Telepost.new('..token..', chats: [12345])
46
46
  tp.spam('How are you?')
47
47
  ```
48
48
 
49
- You can also attach a file (sent as a Telegram document). The
50
- `file` argument accepts a path or an already-open `IO`/`File`,
51
- and `caption:` is optional:
49
+ You can also attach a file. The `file` argument accepts a path or
50
+ an already-open `IO`/`File`, and `caption:` is optional. A file with
51
+ an image extension goes out as a photo, which Telegram shows inline,
52
+ while everything else goes out as a document:
52
53
 
53
54
  ```ruby
54
55
  tp = Telepost.new('..token..')
55
56
  tp.attach(12345, '/tmp/dump.sql', caption: 'Today is dump')
57
+ tp.attach(12345, '/tmp/chart.png', caption: 'Today is chart')
56
58
  ```
57
59
 
58
60
  You can also pass an array of files, to post them all as a single
data/lib/telepost.rb CHANGED
@@ -10,8 +10,8 @@ require 'telegram/bot'
10
10
  #
11
11
  # require 'telepost'
12
12
  # tp = Telepost.new('... secret token ...')
13
- # tp.run do |chat, msg|
14
- # # Reply to the message via tp.post(msg, chat)
13
+ # tp.run do |chat, msg, user|
14
+ # # Reply to the message via tp.post(chat, msg), user is the sender
15
15
  # end
16
16
  #
17
17
  # For more information read
@@ -82,7 +82,9 @@ class Telepost
82
82
  # You can run a chat bot to listen to the messages coming to it, in
83
83
  # a separate thread.
84
84
  #
85
- # @yield [Integer, String] Yields chat ID and message text
85
+ # @yield [Integer, String, String, nil] Yields chat ID, message text, and
86
+ # sender username, which is +nil+ when the sender has no username or the
87
+ # update has no sender
86
88
  # @return [void]
87
89
  # @raise [RuntimeError] If no block is given
88
90
  def run
@@ -90,7 +92,11 @@ class Telepost
90
92
  @bot.listen do |message|
91
93
  next unless message.respond_to?(:chat)
92
94
  next if message.chat.nil?
93
- yield(message.chat.id, message.respond_to?(:text) ? message.text : '')
95
+ yield(
96
+ message.chat.id,
97
+ message.respond_to?(:text) ? message.text : '',
98
+ message.respond_to?(:from) ? message.from&.username : nil
99
+ )
94
100
  end
95
101
  rescue Net::OpenTimeout
96
102
  retry
@@ -121,9 +127,11 @@ class Telepost
121
127
  @bot.api.send_message(chat_id: chat, parse_mode:, disable_web_page_preview: true, text: lines.join(' '))
122
128
  end
123
129
 
124
- # Attach a file (as a Telegram document) to the chat. The file
125
- # argument can either be a path (String) or an open IO/File. The
126
- # filename shown in Telegram comes from the basename of the path.
130
+ # Attach a file to the chat. The file argument can either be a
131
+ # path (String) or an open IO/File. The filename shown in Telegram
132
+ # comes from the basename of the path. A file with an image
133
+ # extension goes out as a photo via +sendPhoto+, so Telegram shows
134
+ # it inline, and everything else as a document via +sendDocument+.
127
135
  #
128
136
  # When +file+ is an +Array+, all of its items are posted as a single
129
137
  # grouped message (a Telegram "album") via +sendMediaGroup+. Items
@@ -139,7 +147,11 @@ class Telepost
139
147
  def attach(chat, file, caption: nil, parse_mode: 'Markdown')
140
148
  return album(chat, file, caption:, parse_mode:) if file.is_a?(Array)
141
149
  io = upload(file)
142
- @bot.api.send_document(chat_id: chat, document: io, caption:, parse_mode:)
150
+ if photo?(file)
151
+ @bot.api.send_photo(chat_id: chat, photo: io, caption:, parse_mode:)
152
+ else
153
+ @bot.api.send_document(chat_id: chat, document: io, caption:, parse_mode:)
154
+ end
143
155
  ensure
144
156
  io.close if file.is_a?(String) && io.respond_to?(:close)
145
157
  end
data/telepost.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'telepost'
12
- s.version = '0.9.0'
12
+ s.version = '0.11.0'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'Simple Telegram posting Ruby gem'
15
15
  s.description = 'Simple Telegram posting Ruby gem'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telepost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko