add python-click and improve mxdiscover

This commit is contained in:
saces 2026-02-19 14:12:17 +01:00
parent 7abdbf674a
commit 0697c3b9d0
4 changed files with 18 additions and 13 deletions

View file

@ -38,7 +38,7 @@ usage:
autopickup by all tools & bots that requires credentials, no further configuration required autopickup by all tools & bots that requires credentials, no further configuration required
commands: commands:
mxdiscover mxdiscover --help
mxwhoami mxwhoami
mxtoken mxtoken
mxaccountinfo mxaccountinfo

View file

@ -28,8 +28,6 @@ func DiscoverHS(ids string) string {
domainname = _hs domainname = _hs
} }
fmt.Printf("Attempt to discover '%s'\n", domainname)
wk, err := mautrix.DiscoverClientAPI(context.Background(), domainname) wk, err := mautrix.DiscoverClientAPI(context.Background(), domainname)
if err != nil { if err != nil {
return fmt.Sprintf("ERR: %v", err) return fmt.Sprintf("ERR: %v", err)

View file

@ -15,6 +15,10 @@ classifiers = [
"Programming Language :: Python", "Programming Language :: Python",
] ]
dependencies = [
"click",
]
[tool.setuptools.package-dir] [tool.setuptools.package-dir]
"pymxutils" = "src/pymxutils" "pymxutils" = "src/pymxutils"
"smal" = "src/smal" "smal" = "src/smal"

View file

@ -1,17 +1,20 @@
import sys import sys
from _pygomx import lib, ffi from _pygomx import lib, ffi
import click
import json
def discoverhs(): @click.command()
if len(sys.argv) != 2: @click.argument("domain", metavar="string")
print("usage: ", sys.argv[0], " matrixid|domainname") def discoverhs(domain):
return 1 """Attempts to discover the homeserver from the given string"""
mxid = domain.encode(encoding="utf-8")
mxid = sys.argv[1].encode(encoding="utf-8")
print("try to discover from: ", mxid)
r = lib.cli_discoverhs(mxid) r = lib.cli_discoverhs(mxid)
result = ffi.string(r) result = ffi.string(r).decode("utf-8")
lib.FreeCString(r) lib.FreeCString(r)
if result.startswith("ERR:"):
print(result) print(result)
sys.exit(1)
result_dict = json.loads(result)
print(result_dict["m.homeserver"]["base_url"])