gruubY 0.2.1 → 0.2.3
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/LICENSE +21 -21
- data/README.md +11 -6
- data/Rakefile +51 -51
- data/config/config.rb +1 -1
- data/example/bot.rb +122 -2
- data/example/generate_user_session.rb +81 -81
- data/example/tdlib.rb +77 -77
- data/example/userbot.rb +133 -133
- data/lib/gruubY/api.rb +540 -363
- data/lib/gruubY/async.rb +13 -13
- data/lib/gruubY/bot.rb +104 -90
- data/lib/gruubY/bound.rb +14 -14
- data/lib/gruubY/client.rb +310 -296
- data/lib/gruubY/context.rb +296 -242
- data/lib/gruubY/dispatcher.rb +60 -60
- data/lib/gruubY/enums.rb +57 -62
- data/lib/gruubY/exception.rb +5 -5
- data/lib/gruubY/file_stream.rb +17 -17
- data/lib/gruubY/filters.rb +292 -292
- data/lib/gruubY/group_manager.rb +213 -213
- data/lib/gruubY/handlers.rb +225 -170
- data/lib/gruubY/keyboard.rb +49 -49
- data/lib/gruubY/media.rb +38 -38
- data/lib/gruubY/middleware.rb +18 -18
- data/lib/gruubY/plugin.rb +27 -14
- data/lib/gruubY/raw.rb +25 -25
- data/lib/gruubY/retry.rb +14 -14
- data/lib/gruubY/server.rb +18 -18
- data/lib/gruubY/session.rb +30 -30
- data/lib/gruubY/tdlib/client.rb +565 -565
- data/lib/gruubY/tdlib/client_manager.rb +37 -37
- data/lib/gruubY/tdlib/decorators.rb +17 -17
- data/lib/gruubY/tdlib/errors.rb +6 -6
- data/lib/gruubY/tdlib/group_manager.rb +58 -58
- data/lib/gruubY/tdlib/native.rb +72 -72
- data/lib/gruubY/tdlib/schema_builder.rb +237 -237
- data/lib/gruubY/tdlib/tdjson.rb +49 -49
- data/lib/gruubY/tdlib/user_session.rb +69 -69
- data/lib/gruubY/types/base_object.rb +72 -72
- data/lib/gruubY/types/bound_entities.rb +289 -245
- data/lib/gruubY/types/chat.rb +93 -93
- data/lib/gruubY/types/chat_info.rb +32 -31
- data/lib/gruubY/types/extra.rb +289 -251
- data/lib/gruubY/types/message.rb +301 -295
- data/lib/gruubY/types/message_entity.rb +14 -14
- data/lib/gruubY/types/registry.rb +86 -67
- data/lib/gruubY/types/user.rb +47 -31
- data/lib/gruubY/webapp.rb +22 -22
- data/lib/gruubY.rb +39 -41
- data/plugins/logger.rb +7 -7
- metadata +3 -9
- data/example/ntgcalls.rb +0 -80
- data/lib/gruubY/ntgcalls/native.rb +0 -100
- data/lib/gruubY/ntgcalls.rb +0 -478
- data/lib/gruubY/raw_types.rb +0 -57
- data/plugins/media_tools.rb +0 -13
data/lib/gruubY/raw.rb
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
module Raw
|
|
3
|
-
module_function
|
|
4
|
-
|
|
5
|
-
def call(api, method, params = {})
|
|
6
|
-
api.raw(method, params)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def td_call(td_client, query, timeout: 30.0)
|
|
10
|
-
if td_client.respond_to?(:raw)
|
|
11
|
-
td_client.raw(query, timeout: timeout)
|
|
12
|
-
else
|
|
13
|
-
td_client.invoke(query, timeout: timeout)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def td_call!(td_client, query, timeout: 30.0)
|
|
18
|
-
response = td_call(td_client, query, timeout: timeout)
|
|
19
|
-
if response.is_a?(Hash) && response["@type"] == "error"
|
|
20
|
-
raise StandardError, "TDLib raw error: #{response['message']}"
|
|
21
|
-
end
|
|
22
|
-
response
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
module Raw
|
|
3
|
+
module_function
|
|
4
|
+
|
|
5
|
+
def call(api, method, params = {})
|
|
6
|
+
api.raw(method, params)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def td_call(td_client, query, timeout: 30.0)
|
|
10
|
+
if td_client.respond_to?(:raw)
|
|
11
|
+
td_client.raw(query, timeout: timeout)
|
|
12
|
+
else
|
|
13
|
+
td_client.invoke(query, timeout: timeout)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def td_call!(td_client, query, timeout: 30.0)
|
|
18
|
+
response = td_call(td_client, query, timeout: timeout)
|
|
19
|
+
if response.is_a?(Hash) && response["@type"] == "error"
|
|
20
|
+
raise StandardError, "TDLib raw error: #{response['message']}"
|
|
21
|
+
end
|
|
22
|
+
response
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/gruubY/retry.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
class Retry
|
|
3
|
-
def self.call(times=3)
|
|
4
|
-
tries = 0
|
|
5
|
-
begin
|
|
6
|
-
yield
|
|
7
|
-
rescue
|
|
8
|
-
tries += 1
|
|
9
|
-
retry if tries < times
|
|
10
|
-
raise
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
class Retry
|
|
3
|
+
def self.call(times=3)
|
|
4
|
+
tries = 0
|
|
5
|
+
begin
|
|
6
|
+
yield
|
|
7
|
+
rescue
|
|
8
|
+
tries += 1
|
|
9
|
+
retry if tries < times
|
|
10
|
+
raise
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/gruubY/server.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
require "sinatra/base"
|
|
2
|
-
require "json"
|
|
3
|
-
require_relative "../../config/config"
|
|
4
|
-
|
|
5
|
-
module GrubY
|
|
6
|
-
class Server < Sinatra::Base
|
|
7
|
-
def initialize(bot)
|
|
8
|
-
super()
|
|
9
|
-
@bot = bot
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
post Config::WEBHOOK_PATH do
|
|
13
|
-
data = JSON.parse(request.body.read)
|
|
14
|
-
@bot.process_update(data)
|
|
15
|
-
"ok"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
require "sinatra/base"
|
|
2
|
+
require "json"
|
|
3
|
+
require_relative "../../config/config"
|
|
4
|
+
|
|
5
|
+
module GrubY
|
|
6
|
+
class Server < Sinatra::Base
|
|
7
|
+
def initialize(bot)
|
|
8
|
+
super()
|
|
9
|
+
@bot = bot
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
post Config::WEBHOOK_PATH do
|
|
13
|
+
data = JSON.parse(request.body.read)
|
|
14
|
+
@bot.process_update(data)
|
|
15
|
+
"ok"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/gruubY/session.rb
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
|
|
3
|
-
module GrubY
|
|
4
|
-
class Session
|
|
5
|
-
FILE = "storage/sessions.json"
|
|
6
|
-
|
|
7
|
-
def initialize
|
|
8
|
-
Dir.mkdir("storage") unless Dir.exist?("storage")
|
|
9
|
-
File.write(FILE, "{}") unless File.exist?(FILE)
|
|
10
|
-
@data = JSON.parse(File.read(FILE))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def get(user_id)
|
|
14
|
-
@data[user_id.to_s] ||= {}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def set(user_id, value)
|
|
18
|
-
@data[user_id.to_s] = value
|
|
19
|
-
save
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def save
|
|
23
|
-
File.write(FILE, JSON.pretty_generate(@data))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_h
|
|
27
|
-
@data.dup
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
module GrubY
|
|
4
|
+
class Session
|
|
5
|
+
FILE = "storage/sessions.json"
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
Dir.mkdir("storage") unless Dir.exist?("storage")
|
|
9
|
+
File.write(FILE, "{}") unless File.exist?(FILE)
|
|
10
|
+
@data = JSON.parse(File.read(FILE))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get(user_id)
|
|
14
|
+
@data[user_id.to_s] ||= {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def set(user_id, value)
|
|
18
|
+
@data[user_id.to_s] = value
|
|
19
|
+
save
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def save
|
|
23
|
+
File.write(FILE, JSON.pretty_generate(@data))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_h
|
|
27
|
+
@data.dup
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|