gruubY 0.2.2 → 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/example/bot.rb +120 -1
- 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 +26 -26
- 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
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
require "thread"
|
|
2
|
-
require_relative "tdjson"
|
|
3
|
-
|
|
4
|
-
module GrubY
|
|
5
|
-
module TDLib
|
|
6
|
-
class ClientManager
|
|
7
|
-
attr_reader :tdjson
|
|
8
|
-
|
|
9
|
-
def initialize(lib_path: nil, verbosity: 1)
|
|
10
|
-
@tdjson = TdJson.new(lib_path: lib_path, verbosity: verbosity)
|
|
11
|
-
@clients = {}
|
|
12
|
-
@mutex = Mutex.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def add_client(client)
|
|
16
|
-
key = client.native_client_key
|
|
17
|
-
@mutex.synchronize { @clients[key] = client }
|
|
18
|
-
client
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def remove_client(client)
|
|
22
|
-
key = client.native_client_key
|
|
23
|
-
@mutex.synchronize { @clients.delete(key) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def each_client(&block)
|
|
27
|
-
snapshot = @mutex.synchronize { @clients.values.dup }
|
|
28
|
-
snapshot.each(&block)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def close
|
|
32
|
-
each_client(&:stop)
|
|
33
|
-
true
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
1
|
+
require "thread"
|
|
2
|
+
require_relative "tdjson"
|
|
3
|
+
|
|
4
|
+
module GrubY
|
|
5
|
+
module TDLib
|
|
6
|
+
class ClientManager
|
|
7
|
+
attr_reader :tdjson
|
|
8
|
+
|
|
9
|
+
def initialize(lib_path: nil, verbosity: 1)
|
|
10
|
+
@tdjson = TdJson.new(lib_path: lib_path, verbosity: verbosity)
|
|
11
|
+
@clients = {}
|
|
12
|
+
@mutex = Mutex.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_client(client)
|
|
16
|
+
key = client.native_client_key
|
|
17
|
+
@mutex.synchronize { @clients[key] = client }
|
|
18
|
+
client
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def remove_client(client)
|
|
22
|
+
key = client.native_client_key
|
|
23
|
+
@mutex.synchronize { @clients.delete(key) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def each_client(&block)
|
|
27
|
+
snapshot = @mutex.synchronize { @clients.values.dup }
|
|
28
|
+
snapshot.each(&block)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def close
|
|
32
|
+
each_client(&:stop)
|
|
33
|
+
true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
module TDLib
|
|
3
|
-
module Decorators
|
|
4
|
-
def initializer(filter: nil, position: nil, timeout: nil, &block)
|
|
5
|
-
add_handler("initializer", filter: filter, position: position, timeout: timeout, &block)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def finalizer(filter: nil, position: nil, timeout: nil, &block)
|
|
9
|
-
add_handler("finalizer", filter: filter, position: position, timeout: timeout, &block)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def on_message(filter: nil, position: nil, timeout: nil, &block)
|
|
13
|
-
add_handler("updateNewMessage", filter: filter, position: position, timeout: timeout, inner_object: true, &block)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
module TDLib
|
|
3
|
+
module Decorators
|
|
4
|
+
def initializer(filter: nil, position: nil, timeout: nil, &block)
|
|
5
|
+
add_handler("initializer", filter: filter, position: position, timeout: timeout, &block)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def finalizer(filter: nil, position: nil, timeout: nil, &block)
|
|
9
|
+
add_handler("finalizer", filter: filter, position: position, timeout: timeout, &block)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def on_message(filter: nil, position: nil, timeout: nil, &block)
|
|
13
|
+
add_handler("updateNewMessage", filter: filter, position: position, timeout: timeout, inner_object: true, &block)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/gruubY/tdlib/errors.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
module TDLib
|
|
3
|
-
class StopHandlers < StandardError; end
|
|
4
|
-
class AuthorizationError < StandardError; end
|
|
5
|
-
end
|
|
6
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
module TDLib
|
|
3
|
+
class StopHandlers < StandardError; end
|
|
4
|
+
class AuthorizationError < StandardError; end
|
|
5
|
+
end
|
|
6
|
+
end
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
module GrubY
|
|
2
|
-
module TDLib
|
|
3
|
-
class GroupManager
|
|
4
|
-
def initialize(client)
|
|
5
|
-
@client = client
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def ban_chat_member(chat_id:, member_id:, banned_until_date: 0, revoke_messages: true)
|
|
9
|
-
@client.banChatMember(
|
|
10
|
-
chat_id: chat_id,
|
|
11
|
-
member_id: member_id,
|
|
12
|
-
banned_until_date: banned_until_date,
|
|
13
|
-
revoke_messages: revoke_messages
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def unban_chat_member(chat_id:, member_id:)
|
|
18
|
-
@client.unbanChatMember(chat_id: chat_id, member_id: member_id)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def set_chat_title(chat_id:, title:)
|
|
22
|
-
@client.setChatTitle(chat_id: chat_id, title: title)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def set_chat_description(chat_id:, description:)
|
|
26
|
-
@client.setChatDescription(chat_id: chat_id, description: description)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def set_slow_mode(chat_id:, delay:)
|
|
30
|
-
@client.setChatSlowModeDelay(chat_id: chat_id, slow_mode_delay: delay)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def pin_chat_message(chat_id:, message_id:, disable_notification: false)
|
|
34
|
-
@client.pinChatMessage(
|
|
35
|
-
chat_id: chat_id,
|
|
36
|
-
message_id: message_id,
|
|
37
|
-
disable_notification: disable_notification
|
|
38
|
-
)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def unpin_chat_message(chat_id:, message_id: nil)
|
|
42
|
-
@client.unpinChatMessage(chat_id: chat_id, message_id: message_id)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def leave_chat(chat_id:)
|
|
46
|
-
@client.leaveChat(chat_id: chat_id)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def get_chat_member(chat_id:, member_id:)
|
|
50
|
-
@client.getChatMember(chat_id: chat_id, member_id: member_id)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def get_chat(chat_id:)
|
|
54
|
-
@client.getChat(chat_id: chat_id)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
1
|
+
module GrubY
|
|
2
|
+
module TDLib
|
|
3
|
+
class GroupManager
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def ban_chat_member(chat_id:, member_id:, banned_until_date: 0, revoke_messages: true)
|
|
9
|
+
@client.banChatMember(
|
|
10
|
+
chat_id: chat_id,
|
|
11
|
+
member_id: member_id,
|
|
12
|
+
banned_until_date: banned_until_date,
|
|
13
|
+
revoke_messages: revoke_messages
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def unban_chat_member(chat_id:, member_id:)
|
|
18
|
+
@client.unbanChatMember(chat_id: chat_id, member_id: member_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def set_chat_title(chat_id:, title:)
|
|
22
|
+
@client.setChatTitle(chat_id: chat_id, title: title)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_chat_description(chat_id:, description:)
|
|
26
|
+
@client.setChatDescription(chat_id: chat_id, description: description)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def set_slow_mode(chat_id:, delay:)
|
|
30
|
+
@client.setChatSlowModeDelay(chat_id: chat_id, slow_mode_delay: delay)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def pin_chat_message(chat_id:, message_id:, disable_notification: false)
|
|
34
|
+
@client.pinChatMessage(
|
|
35
|
+
chat_id: chat_id,
|
|
36
|
+
message_id: message_id,
|
|
37
|
+
disable_notification: disable_notification
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def unpin_chat_message(chat_id:, message_id: nil)
|
|
42
|
+
@client.unpinChatMessage(chat_id: chat_id, message_id: message_id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def leave_chat(chat_id:)
|
|
46
|
+
@client.leaveChat(chat_id: chat_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_chat_member(chat_id:, member_id:)
|
|
50
|
+
@client.getChatMember(chat_id: chat_id, member_id: member_id)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def get_chat(chat_id:)
|
|
54
|
+
@client.getChat(chat_id: chat_id)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/gruubY/tdlib/native.rb
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
require "ffi"
|
|
2
|
-
|
|
3
|
-
module GrubY
|
|
4
|
-
module TDLib
|
|
5
|
-
module Native
|
|
6
|
-
extend FFI::Library
|
|
7
|
-
|
|
8
|
-
class LibraryNotFoundError < StandardError; end
|
|
9
|
-
|
|
10
|
-
class << self
|
|
11
|
-
def load!(path = nil)
|
|
12
|
-
return if @loaded
|
|
13
|
-
|
|
14
|
-
ffi_lib(resolve_library_path(path))
|
|
15
|
-
attach_function :td_json_client_create, [], :pointer
|
|
16
|
-
attach_function :td_json_client_send, [:pointer, :string], :void
|
|
17
|
-
attach_function :td_json_client_receive, [:pointer, :double], :string
|
|
18
|
-
attach_function :td_json_client_execute, [:pointer, :string], :string
|
|
19
|
-
attach_function :td_json_client_destroy, [:pointer], :void
|
|
20
|
-
attach_function :td_set_log_verbosity_level, [:int], :void
|
|
21
|
-
@loaded = true
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def resolve_library_path(custom_path)
|
|
27
|
-
return custom_path if custom_path && File.exist?(custom_path)
|
|
28
|
-
|
|
29
|
-
env_path = ENV["TDJSON_PATH"]
|
|
30
|
-
return env_path if env_path && File.exist?(env_path)
|
|
31
|
-
|
|
32
|
-
candidates = default_candidates
|
|
33
|
-
found = candidates.find { |path| File.exist?(path) }
|
|
34
|
-
return found if found
|
|
35
|
-
|
|
36
|
-
raise LibraryNotFoundError,
|
|
37
|
-
"TDLib (tdjson) not found. Set TDJSON_PATH or pass tdjson_path."
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def default_candidates
|
|
41
|
-
if Gem.win_platform?
|
|
42
|
-
[
|
|
43
|
-
"tdjson.dll",
|
|
44
|
-
"vendor/tdlib/windows/tdjson.dll",
|
|
45
|
-
"vendor/tdlib/win/tdjson.dll",
|
|
46
|
-
"vendor/tdlib/tdjson.dll",
|
|
47
|
-
"C:/tdlib/bin/tdjson.dll",
|
|
48
|
-
"C:/Program Files/TDLib/bin/tdjson.dll"
|
|
49
|
-
]
|
|
50
|
-
elsif RUBY_PLATFORM.include?("darwin")
|
|
51
|
-
[
|
|
52
|
-
"libtdjson.dylib",
|
|
53
|
-
"vendor/tdlib/macos/libtdjson.dylib",
|
|
54
|
-
"vendor/tdlib/darwin/libtdjson.dylib",
|
|
55
|
-
"vendor/tdlib/libtdjson.dylib",
|
|
56
|
-
"/usr/local/lib/libtdjson.dylib",
|
|
57
|
-
"/opt/homebrew/lib/libtdjson.dylib"
|
|
58
|
-
]
|
|
59
|
-
else
|
|
60
|
-
[
|
|
61
|
-
"libtdjson.so",
|
|
62
|
-
"vendor/tdlib/linux/libtdjson.so",
|
|
63
|
-
"vendor/tdlib/libtdjson.so",
|
|
64
|
-
"/usr/lib/libtdjson.so",
|
|
65
|
-
"/usr/local/lib/libtdjson.so"
|
|
66
|
-
]
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
1
|
+
require "ffi"
|
|
2
|
+
|
|
3
|
+
module GrubY
|
|
4
|
+
module TDLib
|
|
5
|
+
module Native
|
|
6
|
+
extend FFI::Library
|
|
7
|
+
|
|
8
|
+
class LibraryNotFoundError < StandardError; end
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def load!(path = nil)
|
|
12
|
+
return if @loaded
|
|
13
|
+
|
|
14
|
+
ffi_lib(resolve_library_path(path))
|
|
15
|
+
attach_function :td_json_client_create, [], :pointer
|
|
16
|
+
attach_function :td_json_client_send, [:pointer, :string], :void
|
|
17
|
+
attach_function :td_json_client_receive, [:pointer, :double], :string
|
|
18
|
+
attach_function :td_json_client_execute, [:pointer, :string], :string
|
|
19
|
+
attach_function :td_json_client_destroy, [:pointer], :void
|
|
20
|
+
attach_function :td_set_log_verbosity_level, [:int], :void
|
|
21
|
+
@loaded = true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def resolve_library_path(custom_path)
|
|
27
|
+
return custom_path if custom_path && File.exist?(custom_path)
|
|
28
|
+
|
|
29
|
+
env_path = ENV["TDJSON_PATH"]
|
|
30
|
+
return env_path if env_path && File.exist?(env_path)
|
|
31
|
+
|
|
32
|
+
candidates = default_candidates
|
|
33
|
+
found = candidates.find { |path| File.exist?(path) }
|
|
34
|
+
return found if found
|
|
35
|
+
|
|
36
|
+
raise LibraryNotFoundError,
|
|
37
|
+
"TDLib (tdjson) not found. Set TDJSON_PATH or pass tdjson_path."
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def default_candidates
|
|
41
|
+
if Gem.win_platform?
|
|
42
|
+
[
|
|
43
|
+
"tdjson.dll",
|
|
44
|
+
"vendor/tdlib/windows/tdjson.dll",
|
|
45
|
+
"vendor/tdlib/win/tdjson.dll",
|
|
46
|
+
"vendor/tdlib/tdjson.dll",
|
|
47
|
+
"C:/tdlib/bin/tdjson.dll",
|
|
48
|
+
"C:/Program Files/TDLib/bin/tdjson.dll"
|
|
49
|
+
]
|
|
50
|
+
elsif RUBY_PLATFORM.include?("darwin")
|
|
51
|
+
[
|
|
52
|
+
"libtdjson.dylib",
|
|
53
|
+
"vendor/tdlib/macos/libtdjson.dylib",
|
|
54
|
+
"vendor/tdlib/darwin/libtdjson.dylib",
|
|
55
|
+
"vendor/tdlib/libtdjson.dylib",
|
|
56
|
+
"/usr/local/lib/libtdjson.dylib",
|
|
57
|
+
"/opt/homebrew/lib/libtdjson.dylib"
|
|
58
|
+
]
|
|
59
|
+
else
|
|
60
|
+
[
|
|
61
|
+
"libtdjson.so",
|
|
62
|
+
"vendor/tdlib/linux/libtdjson.so",
|
|
63
|
+
"vendor/tdlib/libtdjson.so",
|
|
64
|
+
"/usr/lib/libtdjson.so",
|
|
65
|
+
"/usr/local/lib/libtdjson.so"
|
|
66
|
+
]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|