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 +4 -4
- data/Gemfile.lock +22 -22
- data/README.md +7 -5
- data/lib/telepost.rb +20 -8
- data/telepost.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 669da4747151d6e7c97dd90ef240f9b702b17e8d80196351fba8d974a3516da4
|
|
4
|
+
data.tar.gz: d5454663c1acad864f0dc1a39fa68252d2a7dcf309dad3b59f76e15d0f171782
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
14
|
+
bigdecimal (4.1.3)
|
|
15
15
|
builder (3.3.0)
|
|
16
|
-
concurrent-ruby (1.3.
|
|
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.
|
|
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.
|
|
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.
|
|
55
|
-
language_server-protocol (3.17.0.
|
|
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.
|
|
70
|
-
parser (3.3.
|
|
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.
|
|
78
|
+
regexp_parser (2.13.1)
|
|
79
79
|
rexml (3.4.4)
|
|
80
|
-
rubocop (1.
|
|
81
|
-
json (
|
|
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.
|
|
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.
|
|
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.
|
|
97
|
+
rubocop-minitest (0.41.0)
|
|
98
98
|
lint_roller (~> 1.1)
|
|
99
|
-
rubocop (>= 1.
|
|
99
|
+
rubocop (>= 1.89.0, < 2.0)
|
|
100
100
|
rubocop-ast (>= 1.38.0, < 2.0)
|
|
101
|
-
rubocop-performance (1.
|
|
101
|
+
rubocop-performance (1.27.0)
|
|
102
102
|
lint_roller (~> 1.1)
|
|
103
|
-
rubocop (>= 1.
|
|
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.
|
|
124
|
-
unicode-emoji (~> 4.
|
|
125
|
-
unicode-emoji (4.
|
|
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.
|
|
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.
|
|
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,
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
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,
|
|
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
|
|
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(
|
|
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
|
|
125
|
-
#
|
|
126
|
-
#
|
|
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
|
-
|
|
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.
|
|
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'
|