summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-08-08 16:54:17 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2022-08-08 16:54:17 +0200
commit41897324570f5aac31a93b8de240d99c14b02ebc (patch)
tree9a377cb79fe1ad95246c8959a76bb6418f216176
parentnot working, implemented captcha a bit (diff)
downloaddiscord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar.gz
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar.bz2
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar.lz
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar.xz
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.tar.zst
discord.tcl-41897324570f5aac31a93b8de240d99c14b02ebc.zip
-rwxr-xr-xdiscord.tcl77
-rwxr-xr-xwww.tcl2
2 files changed, 53 insertions, 26 deletions
diff --git a/discord.tcl b/discord.tcl
index e664a2c..0548b9b 100755
--- a/discord.tcl
+++ b/discord.tcl
@@ -46,23 +46,29 @@ namespace eval discord {
} else {
set capt [::json::write string $captcha]
}
- proc login_command {callback token} {
- upvar #0 $token state
+ proc login_command {callback http_token} {
+ upvar #0 $http_token state
if {[catch {
- set token [dict get [::json::json2dict $state(body)] token]
+ set discord_token [dict get [::json::json2dict $state(body)] token]
set user_id [dict get [::json::json2dict $state(body)] user_id]
} result] != 0} {
if {[catch {
set captcha_sitekey [dict get [::json::json2dict $state(body)] captcha_sitekey]
} result] != 0} {
- [{*}$callback error $result $state(body)]
+ if {[catch {
+ set message [dict get [lindex [dict get [::json::json2dict $state(body)] errors login _errors] 0] message]
+ } result] != 0} {
+ {*}$callback error $result $state(body)
+ } else {
+ {*}$callback error_message $message $state(body)
+ }
} else {
- [{*}$callback captcha $captcha_sitekey]
+ {*}$callback captcha $captcha_sitekey $state(body)
}
} else {
- [{*}$callback ok $token $user_id]
+ {*}$callback ok $discord_token $user_id
}
- ::http::cleanup $token
+ ::http::cleanup $http_token
}
::http::geturl https://discord.com/api/v9/auth/login -query "{\"login\":[::json::write string $email],\"password\":[::json::write string $password],\"undelete\":\"false\",\"captcha_key\":$capt,\"login_source\":null,\"gift_code_sku_id\":null}" -timeout 10000 -type application/json -command "[namespace which login_command] {$callback}"
}
@@ -89,12 +95,26 @@ namespace eval discord {
captcha {
puts "solve the captcha at address $arg1"
}
+ error_message {
+ puts "the server sent a human-readable error message: $arg1"
+ }
error {
puts "error: $arg1"
}
}
}
+ # links sent in mail are click.discord.com links, I couldn't reverse engineer the upn param
+ proc authorize_ip {click_url callback} {
+ proc authorize_ip_command {callback http_token} {
+ upvar #0 $http_token state
+ puts $state(body)
+ puts $state(meta)
+ }
+ puts $click_url
+ ::http::geturl $click_url -timeout 10000 -command "[namespace which authorize_ip_command] {$callback}"
+ }
+
oo::class create discord {
constructor {{stor {login {} password {} token {} user_id {}}}} {
my variable log storage
@@ -129,12 +149,12 @@ namespace eval discord {
# handles captcha interactively
method login {callback {captcha {}}} {
my variable storage log
- proc login_callback {self_discordobj that callback type {arg1 ""} {arg2 ""}} {
- namespace upvar $that log log sockets sockets
+ proc login_callback {self_discordobj callback type {arg1 ""} {arg2 ""}} {
+ my variable log log sockets sockets
switch $type {
ok {
${log}::notice "login ok: token is $arg1, user_id is $arg2"
- [{*}$callback ok [list $arg1 $arg2]]
+ {*}$callback ok [list $arg1 $arg2]
}
captcha {
${log}::warn "login captcha: sitekey is $arg1"
@@ -167,7 +187,7 @@ namespace eval discord {
"
# this keeps the client object alive
$server destroy
- [{*}$discordobj login $callback [dict get $arguments h-captcha-response]]
+ {*}$discordobj login $callback [dict get $arguments h-captcha-response]
}
proc stop.txt {server client path arguments headers body uri} {
# server destroy does not destroy clients
@@ -177,15 +197,19 @@ namespace eval discord {
}
::www::server create s 0 [list /captcha.html [list [namespace which captcha.html] $arg1] /submit [list [namespace which submit] $self_discordobj $callback [namespace current]::s] /stop.txt [list [namespace which stop.txt] [namespace which s]]]
${log}::notice "please solve captcha at http://127.0.0.1:[s ports]/captcha.html"
- [{*}$callback captcha "http://127.0.0.1:[s ports]/captcha.html"]
+ {*}$callback captcha "http://127.0.0.1:[s ports]/captcha.html"
+ }
+ error_message {
+ ${log}::error "server sent a human-readable error message: $arg1, response from server is $arg2"
+ {*}$callback error_message $arg1
}
error {
${log}::error "login error: message is $arg1, response from server is $arg2"
- [{*}$callback error [list $arg1 $arg2]]
+ {*}$callback error [list $arg1 $arg2]
}
}
}
- ::discord::login [dict get $storage login] [dict get $storage password] "[namespace which login_callback] [self] [self namespace] $callback" $captcha
+ ::discord::login [dict get $storage login] [dict get $storage password] "[namespace which login_callback] [self] $callback" $captcha
}
method connect {} {
my variable sock log storage
@@ -228,14 +252,17 @@ namespace eval discord {
}
}
}
-
-::discord::discord create d
-d set_login_password $env(DC_E) $env(DC_P)
-d login ::discord::login_example_callback
-vwait forever
-::discord::login env(DC_E) env(DC_P) login_example_callback
-d connect
-gets stdin
-d disconnect
-gets stdin
-d destroy
+if [string match *discord.tcl* $argv0] {
+ ::discord::authorize_ip https://click.discord.com/ls/click?upn=qDOo8cnwIoKzt0aLL1cBeJWc43CAiLlKYSQGUErhKV7fF2lroxEuEaMS14HcVQRWKEsXxCWfVqMYFnAqiyFKlyc60qLVSfrR2BpIhn60wAL4y7X8dEY5UhD7n-2BEIulILGfHWzhi03YqYAqwN1dzNDsL7BrPVj5dWSRz43qNCKZs2Mre7Chd4IbpPox9Y-2F4ktYY4N_PdlvdP47mdorwIWlvGoY-2Fnv9MARx98jl0olgQff-2FSKZtFfa9W0dHpN7isUf-2BBQiGTEplWgkKV5AWO17KWsssOLh7AWnsZoy5YvVHlKWck92RQ5vrqN5LMcYUfucbVfjTrOdjPoOJLpa-2F6uIpp4HgFjgpPQjxA-2B3Mm9UmJJTSAUKfWdzMYiWkDqft72DZnIyAHKkjDaEO8wSn3CcCTqm-2FzMMTi-2BVKGxWIQb2p-2F6LNSxtos3YXgYUOtHh5pLu6WeUIvmdhDYWgvG9534NpmGXELQ-3D-3D {}
+ vwait forever
+ ::discord::discord create d
+ d set_login_password $env(DC_E) $env(DC_P)
+ d login ::discord::login_example_callback
+ vwait forever
+ ::discord::login env(DC_E) env(DC_P) login_example_callback
+ d connect
+ gets stdin
+ d disconnect
+ gets stdin
+ d destroy
+}
diff --git a/www.tcl b/www.tcl
index 0e20f7a..5385a9c 100755
--- a/www.tcl
+++ b/www.tcl
@@ -36,7 +36,7 @@ namespace eval www {
method accept {chan addr port} {
my variable actions
if [dict exists $actions accept] {
- [{*}[dict get $actions accept] $chan $addr $port]
+ {*}[dict get $actions accept] $chan $addr $port
}
::www::client new $chan $actions
}