new config option for a custom bot response message, complete with variables and everything! fixes #1

This commit is contained in:
William Kray 2021-06-01 10:48:02 -07:00
parent ef08b5d04c
commit fa68da1210
3 changed files with 40 additions and 7 deletions

View File

@ -3,17 +3,44 @@ admin_secret: mYsUp3rs3CretKEY12345
# versions of matrix-registration earlier than 0.9.0 used
# a different api endpoint. if you are running a version
# that is greater than or equal to 0.9.0, set this to false
legacy_mr: true
legacy_mr: false
# how to get to the matrix-registration instance
# note the lack of trailing slash!
# e.g.
# reg_url: http://localhost:5000
reg_url: 'https://www.yourwebsite.com'
# the URI to use for registering tokens
# leave this as the default value unless you are using
# a custom registration page!
# you can also set this to a full URL if your registration
# page is accessible by a completely different host from
# your registration endpoint, just be sure to update your
# formatted message below to remove the reg_url value.
# e.g.
# reg_page: https://someotherwebsite.com/registration-page.html
reg_page: '/register'
# the html-formatted text you would like the bot to respond with
# when a new token is generated. you may use the following variables:
# {token} for the registration token
# {reg_url} for the registration url set in this config
# {reg_page} for the registration uri set in this config
# {expiration} for the expiration value set in this config
#
# if unset, a default message will be used.
#
# example message:
#
message: |
Invitation token <b>{token}</b> created!<br />
<br />
Your unique url for registering is:<br />
{reg_url}{reg_page}?token={token}<br />
This invite token will expire in {expiration} days.<br />
If it expires before use, you must request a new token.
# the duration the invitation should be valid, in days, before expiring
expiration: 3

View File

@ -15,6 +15,7 @@ class Config(BaseProxyConfig):
helper.copy("reg_page")
helper.copy("admins")
helper.copy("expiration")
helper.copy("message")
class Invite(Plugin):
async def start(self) -> None:
@ -79,17 +80,22 @@ class Invite(Plugin):
{resp_json}")
self.log.exception(e)
return None
await evt.respond('<br />'.join(
msg = '<br />'.join(
[
f"Invitation token {token} created! You may share the following message with your invitee:",
f"Invitation token <b>{token}</b> created!",
f"",
f"Your unique url for registering is:",
f"{self.config['reg_url']}{self.config['reg_page']}?token={token}",
f"This invite token will expire in {self.config['expiration']} days.",
f"If it expires before use, you must request a new token."
]
), allow_html=True)
])
if self.config['message']:
msg = self.config["message"].format(token=token, reg_url=self.config['reg_url'],
reg_page=self.config['reg_page'], expiration=self.config['expiration'])
await evt.respond(msg, allow_html=True)
@invite.subcommand("status", help="Return the status of an invite token.")
@command.argument("token", "Token", pass_raw=True, required=True)

View File

@ -1,6 +1,6 @@
maubot: 0.1.0
id: org.jobmachine.invitebot
version: 0.2.1
version: 0.3.0
license: MIT
modules:
- invite