fixes to json structure in api calls and date formatting, plus readme updates

This commit is contained in:
William Kray 2021-05-10 09:13:40 -07:00
parent 20a9ab5cd7
commit 63387d03b9
2 changed files with 7 additions and 7 deletions

View File

@ -1,10 +1,11 @@
this is a simple [maubot](https://github.com/maubot/maubot) plugin which interacts with a [matrix-registration](https://github.com/zeratax/matrix-registration) deployment and generates invite tokens.
###Warning
this bot currently only works with matrix-registration versions 0.7.x. Newer implementations (currently in development as of this comment) use different api endpoints and logic, and I haven't written those changes into this code. PRs are welcomed!
modify the config to point to your matrix-registration url, include your admin secret to authenticate, and ensure that you're in the list of approved users.
*please note* that matrix-registration versions BELOW 0.9.0 have different API endpoints, expected date structures, json
arguments, etc. and require the `legacy_mr` value in your config to be set to `True`! If your matrix-registration
instance is 0.9.0 or greater, leave this as `false`.
once your bot is running, simply use the command
!invite generate
@ -23,4 +24,3 @@ to revoke a token, use
!invite revoke MyTokenName
please note: i haven't made the json output of those responses pretty. sorry not sorry.

View File

@ -53,7 +53,7 @@ class Invite(Plugin):
ex_date = datetime.datetime.strftime( \
(datetime.date.today() + datetime.timedelta(days=self.config["expiration"])), \
"%Y.%m.%d")
"%Y-%m-%d")
# use re-ordered date if using legacy code
if self.config["legacy_mr"] == True:
ex_date = datetime.datetime.strftime( \
@ -66,7 +66,7 @@ class Invite(Plugin):
try:
response = await self.http.post(f"{self.config['api_url']}/token", headers=headers, \
json={"max_usage": 1, "one_time": True, "ex_date": ex_date})
json={"max_usage": 1, "one_time": True, "ex_date": ex_date, "expiration_date": ex_date})
resp_json = await response.json()
except Exception as e:
await evt.respond(f"request failed: {e.message}")
@ -149,7 +149,7 @@ class Invite(Plugin):
else:
try:
response = await self.http.patch(f"{self.config['api_url']}/token/{token}", headers=headers, \
json={"disable": True})
json={"disabled": True})
resp_json = await response.json()
except Exception as e:
await evt.respond(f"request failed: {e.message}")