This commit is contained in:
saces 2026-03-13 15:41:51 +01:00
parent 8df08611a9
commit bf3d383615
4 changed files with 40 additions and 15 deletions

View file

@ -58,7 +58,8 @@ usage:
commands:
mxdiscover --help
mxwhoami
mxpassitem --help
mxwhoami --help
mxtoken
mxaccountinfo
mxclearaccount

View file

@ -143,8 +143,16 @@ func cliv0_mkmxtoken(id *C.char, pw *C.char) *C.char {
func cliv0_whoami(hs *C.char, tk *C.char) *C.char {
_hs := C.GoString(hs)
_tk := C.GoString(tk)
result := mxutils.Whoami(_hs, _tk)
return C.CString(result)
resp, err := mxutils.Whoami(_hs, _tk)
if err != nil {
return C.CString(fmt.Sprintf("ERR: %v", err))
}
out, err := json.Marshal(resp)
if err != nil {
return C.CString(fmt.Sprintf("ERR: %v", err))
}
s := string(out)
return C.CString(s)
}
//export cliv0_accountinfo

View file

@ -89,8 +89,12 @@ func MkToken(ids string, pw string) string {
return resp.AccessToken
}
func Whoami(hs string, accessToken string) string {
return "nope. whoami"
func Whoami(hs string, accessToken string) (*mautrix.RespWhoami, error) {
mauclient, err := mautrix.NewClient(hs, "", accessToken)
if err != nil {
return nil, err
}
return mauclient.Whoami(context.Background())
}
func AccountInfo(hs string, accessToken string) string {

View file

@ -1,18 +1,30 @@
# Copyright (C) 2026 saces@c-base.org
# SPDX-License-Identifier: AGPL-3.0-only
import sys
from _pygomx import lib, ffi
import json
import click
from _pygomx import ffi, lib
def whoami():
if len(sys.argv) != 3:
print("usage: ", sys.argv[0], " url accesstoken")
return 1
@click.command()
@click.option("-u", "--url", "hs_url", metavar="url", help="homeserver url")
@click.option("-t", "--token", "token", metavar="token", help="access token")
def whoami(hs_url, token):
"""this token belongs to?"""
url = sys.argv[1].encode(encoding="utf-8")
tk = sys.argv[2].encode(encoding="utf-8")
if hs_url is None and token is None:
r = lib.cliv0_mxpassitem(b".mxpass", b"*", b"*", b"*")
r = lib.cliv0_whoami(url, tk)
result = ffi.string(r).decode("utf-8")
lib.FreeCString(r)
result_dict = json.loads(result)
hs_url = result_dict["Matrixhost"]
token = result_dict["Token"]
r = lib.cliv0_whoami(
hs_url.encode(encoding="utf-8"), token.encode(encoding="utf-8")
)
result = ffi.string(r)
lib.FreeCString(r)
print(result)
print(result.decode("utf-8"))