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/example/userbot.rb
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
require_relative "../lib/gruubY"
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require "io/console"
|
|
5
|
-
rescue LoadError
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
begin
|
|
9
|
-
require "rqrcode"
|
|
10
|
-
rescue LoadError
|
|
11
|
-
RQRCode = nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def clear_print
|
|
15
|
-
print "\e[2J\e[f"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def prompt(label)
|
|
19
|
-
print label
|
|
20
|
-
STDIN.gets.to_s.strip
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
api_id = ENV["TD_API_ID"]&.to_i
|
|
24
|
-
api_hash = ENV["TD_API_HASH"]
|
|
25
|
-
|
|
26
|
-
abort("Missing TD_API_ID or TD_API_HASH") if api_id.nil? || api_hash.to_s.empty?
|
|
27
|
-
|
|
28
|
-
client = GrubY::TDLib::Client.new(
|
|
29
|
-
api_id: api_id,
|
|
30
|
-
api_hash: api_hash,
|
|
31
|
-
database_directory: "storage/tdlib-userbot",
|
|
32
|
-
files_directory: "storage/tdlib-userbot/files",
|
|
33
|
-
tdjson_path: ENV["TDJSON_PATH"],
|
|
34
|
-
td_verbosity: 2,
|
|
35
|
-
options: {
|
|
36
|
-
"ignore_background_updates" => false
|
|
37
|
-
},
|
|
38
|
-
workers: 4,
|
|
39
|
-
default_handler_timeout: 15
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
client.on("updateAuthorizationState") do |update|
|
|
43
|
-
state = update.dig("authorization_state", "@type")
|
|
44
|
-
|
|
45
|
-
case state
|
|
46
|
-
when "authorizationStateWaitPhoneNumber"
|
|
47
|
-
loop do
|
|
48
|
-
input = prompt('Enter phone number or "qr": ')
|
|
49
|
-
next if input.empty?
|
|
50
|
-
|
|
51
|
-
if input.downcase == "qr"
|
|
52
|
-
res = client.request_qr_code_authentication
|
|
53
|
-
if res["@type"] == "error"
|
|
54
|
-
puts "Error: #{res['message']}"
|
|
55
|
-
next
|
|
56
|
-
end
|
|
57
|
-
else
|
|
58
|
-
res = client.set_authentication_phone_number(phone_number: input)
|
|
59
|
-
if res["@type"] == "error"
|
|
60
|
-
puts "Error: #{res['message']}"
|
|
61
|
-
next
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
break
|
|
66
|
-
end
|
|
67
|
-
when "authorizationStateWaitOtherDeviceConfirmation"
|
|
68
|
-
link = update.dig("authorization_state", "link")
|
|
69
|
-
clear_print
|
|
70
|
-
puts "Scan QR from Telegram mobile app -> Settings -> Devices -> Link Desktop Device"
|
|
71
|
-
puts
|
|
72
|
-
puts link
|
|
73
|
-
|
|
74
|
-
if RQRCode
|
|
75
|
-
puts
|
|
76
|
-
qr = RQRCode::QRCode.new(link)
|
|
77
|
-
qr.modules.each do |row|
|
|
78
|
-
puts row.map { |m| m ? "##" : " " }.join
|
|
79
|
-
end
|
|
80
|
-
else
|
|
81
|
-
puts "\nInstall `rqrcode` gem for terminal QR rendering."
|
|
82
|
-
end
|
|
83
|
-
when "authorizationStateWaitCode"
|
|
84
|
-
loop do
|
|
85
|
-
code = prompt("Enter login code: ")
|
|
86
|
-
next if code.empty?
|
|
87
|
-
|
|
88
|
-
res = client.check_authentication_code(code)
|
|
89
|
-
if res["@type"] == "error"
|
|
90
|
-
puts "Error: #{res['message']}"
|
|
91
|
-
next
|
|
92
|
-
end
|
|
93
|
-
break
|
|
94
|
-
end
|
|
95
|
-
when "authorizationStateWaitPassword"
|
|
96
|
-
clear_print
|
|
97
|
-
hint = update.dig("authorization_state", "password_hint")
|
|
98
|
-
loop do
|
|
99
|
-
pass = prompt("Enter 2FA password (hint: #{hint}): ")
|
|
100
|
-
next if pass.empty?
|
|
101
|
-
|
|
102
|
-
res = client.check_authentication_password(pass)
|
|
103
|
-
if res["@type"] == "error"
|
|
104
|
-
puts "Error: #{res['message']}"
|
|
105
|
-
next
|
|
106
|
-
end
|
|
107
|
-
break
|
|
108
|
-
end
|
|
109
|
-
when "authorizationStateReady"
|
|
110
|
-
me = client.get_me
|
|
111
|
-
clear_print
|
|
112
|
-
puts "Logged in as #{me['first_name']} (ID: #{me['id']})"
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
client.on_message do |message|
|
|
117
|
-
next unless message.dig("content", "@type") == "messageText"
|
|
118
|
-
next unless message["is_outgoing"]
|
|
119
|
-
|
|
120
|
-
text = message.dig("content", "text", "text").to_s
|
|
121
|
-
next unless text == "!hi"
|
|
122
|
-
|
|
123
|
-
client.edit_message_text(
|
|
124
|
-
chat_id: message["chat_id"],
|
|
125
|
-
message_id: message["id"],
|
|
126
|
-
input_message_content: {
|
|
127
|
-
"@type" => "inputMessageText",
|
|
128
|
-
"text" => { "@type" => "formattedText", "text" => "Hey, This is from GrubY TDLib Userbot!" }
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
client.run
|
|
1
|
+
require_relative "../lib/gruubY"
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require "io/console"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require "rqrcode"
|
|
10
|
+
rescue LoadError
|
|
11
|
+
RQRCode = nil
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def clear_print
|
|
15
|
+
print "\e[2J\e[f"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def prompt(label)
|
|
19
|
+
print label
|
|
20
|
+
STDIN.gets.to_s.strip
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
api_id = ENV["TD_API_ID"]&.to_i
|
|
24
|
+
api_hash = ENV["TD_API_HASH"]
|
|
25
|
+
|
|
26
|
+
abort("Missing TD_API_ID or TD_API_HASH") if api_id.nil? || api_hash.to_s.empty?
|
|
27
|
+
|
|
28
|
+
client = GrubY::TDLib::Client.new(
|
|
29
|
+
api_id: api_id,
|
|
30
|
+
api_hash: api_hash,
|
|
31
|
+
database_directory: "storage/tdlib-userbot",
|
|
32
|
+
files_directory: "storage/tdlib-userbot/files",
|
|
33
|
+
tdjson_path: ENV["TDJSON_PATH"],
|
|
34
|
+
td_verbosity: 2,
|
|
35
|
+
options: {
|
|
36
|
+
"ignore_background_updates" => false
|
|
37
|
+
},
|
|
38
|
+
workers: 4,
|
|
39
|
+
default_handler_timeout: 15
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
client.on("updateAuthorizationState") do |update|
|
|
43
|
+
state = update.dig("authorization_state", "@type")
|
|
44
|
+
|
|
45
|
+
case state
|
|
46
|
+
when "authorizationStateWaitPhoneNumber"
|
|
47
|
+
loop do
|
|
48
|
+
input = prompt('Enter phone number or "qr": ')
|
|
49
|
+
next if input.empty?
|
|
50
|
+
|
|
51
|
+
if input.downcase == "qr"
|
|
52
|
+
res = client.request_qr_code_authentication
|
|
53
|
+
if res["@type"] == "error"
|
|
54
|
+
puts "Error: #{res['message']}"
|
|
55
|
+
next
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
res = client.set_authentication_phone_number(phone_number: input)
|
|
59
|
+
if res["@type"] == "error"
|
|
60
|
+
puts "Error: #{res['message']}"
|
|
61
|
+
next
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
break
|
|
66
|
+
end
|
|
67
|
+
when "authorizationStateWaitOtherDeviceConfirmation"
|
|
68
|
+
link = update.dig("authorization_state", "link")
|
|
69
|
+
clear_print
|
|
70
|
+
puts "Scan QR from Telegram mobile app -> Settings -> Devices -> Link Desktop Device"
|
|
71
|
+
puts
|
|
72
|
+
puts link
|
|
73
|
+
|
|
74
|
+
if RQRCode
|
|
75
|
+
puts
|
|
76
|
+
qr = RQRCode::QRCode.new(link)
|
|
77
|
+
qr.modules.each do |row|
|
|
78
|
+
puts row.map { |m| m ? "##" : " " }.join
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
puts "\nInstall `rqrcode` gem for terminal QR rendering."
|
|
82
|
+
end
|
|
83
|
+
when "authorizationStateWaitCode"
|
|
84
|
+
loop do
|
|
85
|
+
code = prompt("Enter login code: ")
|
|
86
|
+
next if code.empty?
|
|
87
|
+
|
|
88
|
+
res = client.check_authentication_code(code)
|
|
89
|
+
if res["@type"] == "error"
|
|
90
|
+
puts "Error: #{res['message']}"
|
|
91
|
+
next
|
|
92
|
+
end
|
|
93
|
+
break
|
|
94
|
+
end
|
|
95
|
+
when "authorizationStateWaitPassword"
|
|
96
|
+
clear_print
|
|
97
|
+
hint = update.dig("authorization_state", "password_hint")
|
|
98
|
+
loop do
|
|
99
|
+
pass = prompt("Enter 2FA password (hint: #{hint}): ")
|
|
100
|
+
next if pass.empty?
|
|
101
|
+
|
|
102
|
+
res = client.check_authentication_password(pass)
|
|
103
|
+
if res["@type"] == "error"
|
|
104
|
+
puts "Error: #{res['message']}"
|
|
105
|
+
next
|
|
106
|
+
end
|
|
107
|
+
break
|
|
108
|
+
end
|
|
109
|
+
when "authorizationStateReady"
|
|
110
|
+
me = client.get_me
|
|
111
|
+
clear_print
|
|
112
|
+
puts "Logged in as #{me['first_name']} (ID: #{me['id']})"
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
client.on_message do |message|
|
|
117
|
+
next unless message.dig("content", "@type") == "messageText"
|
|
118
|
+
next unless message["is_outgoing"]
|
|
119
|
+
|
|
120
|
+
text = message.dig("content", "text", "text").to_s
|
|
121
|
+
next unless text == "!hi"
|
|
122
|
+
|
|
123
|
+
client.edit_message_text(
|
|
124
|
+
chat_id: message["chat_id"],
|
|
125
|
+
message_id: message["id"],
|
|
126
|
+
input_message_content: {
|
|
127
|
+
"@type" => "inputMessageText",
|
|
128
|
+
"text" => { "@type" => "formattedText", "text" => "Hey, This is from GrubY TDLib Userbot!" }
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
client.run
|