telegem 2.0.3 → 2.0.5
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/lib/api/client.rb +2 -2
- data/lib/core/bot.rb +14 -4
- data/lib/telegem.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: c8a100bc051a797130ecebdf67164f6d2566fda1241a3240226396412b1cd6d7
|
|
4
|
+
data.tar.gz: 6f41d93f14122381a14138be904987032abc577c8d0fde33e53d0632505d6363
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11ee3ef944c5ddafeb77c91e9e069bca3631061f073525abf3b7a60f009b8b2c30cc8f12e73a828001b2bec062039b73de55af23896d621b77f7c2dac6e544ca
|
|
7
|
+
data.tar.gz: 9a378f859712a891550e5fd1647053a7a2dae80065d08f9c1b73f9fbdaf6ff7b006115165a403848866d6ba8da439a351166661200128ed7bfb23af83141f4a6
|
data/lib/api/client.rb
CHANGED
|
@@ -12,10 +12,10 @@ module Telegem
|
|
|
12
12
|
def initialize(token, **options)
|
|
13
13
|
@token = token
|
|
14
14
|
@logger = options[:logger] || Logger.new($stdout)
|
|
15
|
-
timeout = options[:timeout] || 30
|
|
15
|
+
@timeout = options[:timeout] || 30
|
|
16
16
|
|
|
17
17
|
@http = HTTPX.with(
|
|
18
|
-
timeout: timeout,
|
|
18
|
+
timeout: { request_timeout: @timeout},
|
|
19
19
|
headers: {
|
|
20
20
|
'Content-Type' => 'application/json'
|
|
21
21
|
}
|
data/lib/core/bot.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'logger'
|
|
|
4
4
|
module Telegem
|
|
5
5
|
module Core
|
|
6
6
|
class Bot
|
|
7
|
-
attr_reader :token, :api, :handlers, :middleware, :logger, :scenes, :running
|
|
7
|
+
attr_reader :token, :api, :handlers, :middleware, :logger, :scenes, :running, :polling_thread
|
|
8
8
|
|
|
9
9
|
def initialize(token, **options)
|
|
10
10
|
@token = token
|
|
@@ -175,14 +175,22 @@ module Telegem
|
|
|
175
175
|
def poll_loop
|
|
176
176
|
while @running
|
|
177
177
|
begin
|
|
178
|
+
# Get updates - returns HTTPX request object
|
|
178
179
|
updates_request = fetch_updates
|
|
179
180
|
|
|
180
|
-
|
|
181
|
+
# Wait for the request to complete
|
|
182
|
+
updates_request.wait(@polling_options[:timeout] + 5)
|
|
181
183
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
# Get the response AFTER waiting
|
|
185
|
+
response = updates_request.response
|
|
186
|
+
|
|
187
|
+
if response && response.status == 200
|
|
188
|
+
if json = response.json
|
|
189
|
+
handle_updates_response(json)
|
|
190
|
+
end
|
|
184
191
|
end
|
|
185
192
|
|
|
193
|
+
# Small delay to prevent tight loop
|
|
186
194
|
sleep 0.1 unless @offset.nil?
|
|
187
195
|
|
|
188
196
|
rescue => e
|
|
@@ -208,10 +216,12 @@ module Telegem
|
|
|
208
216
|
|
|
209
217
|
updates_data = api_response['result'] || []
|
|
210
218
|
|
|
219
|
+
# Queue updates for worker processing
|
|
211
220
|
updates_data.each do |update_data|
|
|
212
221
|
@update_queue << [update_data, nil]
|
|
213
222
|
end
|
|
214
223
|
|
|
224
|
+
# Update offset for next poll
|
|
215
225
|
if updates_data.any?
|
|
216
226
|
@offset = updates_data.last['update_id'] + 1
|
|
217
227
|
end
|
data/lib/telegem.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: telegem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sick_phantom
|
|
@@ -198,7 +198,7 @@ metadata:
|
|
|
198
198
|
bug_tracker_uri: https://gitlab.com/ruby-telegem/telegem/-/issues
|
|
199
199
|
documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/blob/main/README.md
|
|
200
200
|
rubygems_mfa_required: 'false'
|
|
201
|
-
post_install_message: "Thanks for installing Telegem 2.0.
|
|
201
|
+
post_install_message: "Thanks for installing Telegem 2.0.5!\n\nQuick start:\n bot
|
|
202
202
|
= Telegem.new(\"YOUR_TOKEN\")\n bot.on(:message) { |ctx| ctx.reply(\"Hello!\")
|
|
203
203
|
}\n bot.start_polling\n\nDocumentation: https://gitlab.com/ruby-telegem/telegem\nHappy
|
|
204
204
|
bot building! \U0001F916\n"
|