add python-click and improve mxdiscover
This commit is contained in:
parent
7abdbf674a
commit
0697c3b9d0
4 changed files with 18 additions and 13 deletions
|
|
@ -38,7 +38,7 @@ usage:
|
|||
autopickup by all tools & bots that requires credentials, no further configuration required
|
||||
|
||||
commands:
|
||||
mxdiscover
|
||||
mxdiscover --help
|
||||
mxwhoami
|
||||
mxtoken
|
||||
mxaccountinfo
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ func DiscoverHS(ids string) string {
|
|||
domainname = _hs
|
||||
}
|
||||
|
||||
fmt.Printf("Attempt to discover '%s'\n", domainname)
|
||||
|
||||
wk, err := mautrix.DiscoverClientAPI(context.Background(), domainname)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("ERR: %v", err)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ classifiers = [
|
|||
"Programming Language :: Python",
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
"click",
|
||||
]
|
||||
|
||||
[tool.setuptools.package-dir]
|
||||
"pymxutils" = "src/pymxutils"
|
||||
"smal" = "src/smal"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,20 @@
|
|||
import sys
|
||||
from _pygomx import lib, ffi
|
||||
import click
|
||||
import json
|
||||
|
||||
|
||||
def discoverhs():
|
||||
if len(sys.argv) != 2:
|
||||
print("usage: ", sys.argv[0], " matrixid|domainname")
|
||||
return 1
|
||||
|
||||
mxid = sys.argv[1].encode(encoding="utf-8")
|
||||
|
||||
print("try to discover from: ", mxid)
|
||||
@click.command()
|
||||
@click.argument("domain", metavar="string")
|
||||
def discoverhs(domain):
|
||||
"""Attempts to discover the homeserver from the given string"""
|
||||
mxid = domain.encode(encoding="utf-8")
|
||||
|
||||
r = lib.cli_discoverhs(mxid)
|
||||
result = ffi.string(r)
|
||||
result = ffi.string(r).decode("utf-8")
|
||||
lib.FreeCString(r)
|
||||
if result.startswith("ERR:"):
|
||||
print(result)
|
||||
sys.exit(1)
|
||||
result_dict = json.loads(result)
|
||||
print(result_dict["m.homeserver"]["base_url"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue