rubydium 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubydium/mixins/message_sending.rb +29 -8
- data/lib/rubydium/mixins/other_actions.rb +10 -4
- data/lib/rubydium/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee189034adf5cc71d909a3a592aab9f1066f994ee3914f8d8d5c6e80e1a5faf3
|
4
|
+
data.tar.gz: 381ab88806a8557bb10defb367befd058648f002570dfa044c5f7a16d94f7808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3554cfb402b4f5c3e053795dcb7b8b5938217991a5ef4b842f77634593bd13f68c08be3b4bd7e382e90cd90456e159c0ac8d672c304ddfb0d3525ef40ba5148
|
7
|
+
data.tar.gz: 0c17430324d459d43758ab29b894422e1dca8bf3a7d619c320d47529a266fbf5a5cfa87527814c5a44a30758b46a8320c0294c22278eddb61dc7b9842596948e
|
@@ -4,13 +4,38 @@ module Rubydium
|
|
4
4
|
module Mixins
|
5
5
|
# Shorthand methods for sending messages in different ways.
|
6
6
|
module MessageSending
|
7
|
-
|
7
|
+
MAX_MESSAGE_SIZE = 4096
|
8
|
+
|
9
|
+
def chunks(string, size)
|
10
|
+
(string.length / size.to_f).ceil.times.map { |i| string[i * size, size] }
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_message(text, split: false **kwargs)
|
14
|
+
return send_many_messages(text, **kwargs) if split
|
15
|
+
|
8
16
|
@api.send_message(
|
9
17
|
chat_id: @chat.id,
|
10
18
|
message_thread_id: @topic_id,
|
11
19
|
text: text,
|
12
20
|
**kwargs
|
13
21
|
)
|
22
|
+
rescue Telegram::Bot::Exceptions::ResponseError => e
|
23
|
+
data = e.send(:data)
|
24
|
+
raise e unless data["error_code"] == 429
|
25
|
+
|
26
|
+
retry_after = data.dig("parameters", "retry_after")
|
27
|
+
raise e unless retry_after && retry_after > 0
|
28
|
+
|
29
|
+
sleep retry_after
|
30
|
+
retry
|
31
|
+
end
|
32
|
+
|
33
|
+
def send_many_messages(text, **kwargs)
|
34
|
+
text_chunks = chunks(text, MAX_MESSAGE_SIZE)
|
35
|
+
|
36
|
+
text_chunks.map do |chunk|
|
37
|
+
send_message(text, **kwargs)
|
38
|
+
end
|
14
39
|
end
|
15
40
|
|
16
41
|
def send_sticker(sticker, action: nil, **kwargs)
|
@@ -63,11 +88,9 @@ module Rubydium
|
|
63
88
|
end
|
64
89
|
|
65
90
|
def reply(text, **args)
|
66
|
-
|
67
|
-
|
68
|
-
message_thread_id: @topic_id,
|
91
|
+
send_message(
|
92
|
+
text,
|
69
93
|
reply_to_message_id: @message_id,
|
70
|
-
text: text,
|
71
94
|
**args
|
72
95
|
)
|
73
96
|
end
|
@@ -77,9 +100,7 @@ module Rubydium
|
|
77
100
|
end
|
78
101
|
|
79
102
|
def reply_to_target(text)
|
80
|
-
|
81
|
-
chat_id: @chat.id,
|
82
|
-
message_thread_id: @topic_id,
|
103
|
+
send_message(
|
83
104
|
reply_to_message_id: @replies_to.message_id,
|
84
105
|
text: text
|
85
106
|
)
|
@@ -1,11 +1,17 @@
|
|
1
1
|
module Rubydium
|
2
2
|
module Mixins
|
3
3
|
module OtherActions
|
4
|
-
def safe_delete(
|
5
|
-
|
6
|
-
return false unless
|
4
|
+
def safe_delete(maybe_message)
|
5
|
+
message = definitely_message(maybe_message)
|
6
|
+
return false unless message&.from&.id == config.bot_id # also returns if it's nil
|
7
7
|
|
8
|
-
|
8
|
+
safe_delete_by_id(message.id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def safe_delete_by_id(id)
|
12
|
+
return false unless bot_can_delete_messages?
|
13
|
+
|
14
|
+
result = @api.delete_message(chat_id: @chat.id, message_id: id)
|
9
15
|
result["ok"]
|
10
16
|
rescue Telegram::Bot::Exceptions::ResponseError
|
11
17
|
false
|
data/lib/rubydium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bulgakke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: telegram-bot-ruby
|