Add user auth level

Fixes #162
Closes #168
Closes #170
This commit is contained in:
Tulir Asokan
2018-07-09 20:37:06 +03:00
parent 74f3956608
commit d035e9da73
10 changed files with 50 additions and 18 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ async def ping(evt):
return await evt.reply("You're not logged in.")
@command_handler()
@command_handler(needs_auth=False, needs_puppeting=False)
async def ping_bot(evt):
if not evt.tgbot:
return await evt.reply("Telegram message relay bot not configured.")
+5 -2
View File
@@ -24,7 +24,8 @@ from ..util import format_duration
command_handlers = {}
def command_handler(needs_auth=True, management_only=False, needs_admin=False, name=None):
def command_handler(needs_auth=True, management_only=False, needs_puppeting=True,
needs_admin=False, name=None):
def decorator(func):
async def wrapper(evt):
if management_only and not evt.is_management:
@@ -32,8 +33,10 @@ def command_handler(needs_auth=True, management_only=False, needs_admin=False, n
"you may only run it in management rooms.")
elif needs_auth and not await evt.sender.is_logged_in():
return await evt.reply("This command requires you to be logged in.")
elif needs_puppeting and not evt.sender.puppet_whitelisted:
return await evt.reply("This command requires puppeting privileges.")
elif needs_admin and not evt.sender.is_admin:
return await evt.reply("This is command requires administrator privileges.")
return await evt.reply("This command requires administrator privileges.")
return await func(evt)
command_handlers[name or func.__name__.replace("_", "-")] = wrapper
+21 -4
View File
@@ -17,7 +17,7 @@
from . import command_handler
@command_handler(needs_auth=False)
@command_handler(needs_auth=False, needs_puppeting=False)
def cancel(evt):
if evt.sender.command_status:
action = evt.sender.command_status["action"]
@@ -27,12 +27,12 @@ def cancel(evt):
return evt.reply("No ongoing command.")
@command_handler(needs_auth=False)
@command_handler(needs_auth=False, needs_puppeting=False)
def unknown_command(evt):
return evt.reply("Unknown command. Try `$cmdprefix+sp help` for help.")
@command_handler(needs_auth=False)
@command_handler(needs_auth=False, needs_puppeting=False)
def help(evt):
if evt.is_management:
management_status = ("This is a management room: prefixing commands "
@@ -44,7 +44,24 @@ def help(evt):
else:
management_status = ("**This is not a management room**: you must "
"prefix commands with `$cmdprefix`.\n")
help = """\n
help = None
if not evt.sender.puppet_whitelisted:
help = """\n
#### Generic bridge commands
**help** - Show this help message.
**cancel** - Cancel an ongoing action (such as login).
**ping-bot** - Get info of the message relay Telegram bot.
**invite-link** - Get a Telegram invite link to the current chat.
**delete-portal** - Remove all users from the current portal room and forget the portal.
Only works for group chats; to delete a private chat portal, simply
leave the room.
**unbridge** - Remove puppets from the current portal room and forget the portal.
**bridge** [_id_] - Bridge the current Matrix room to the Telegram chat with the given
ID. The ID must be the prefixed version that you get with the `/id`
command of the Telegram-side bot.
"""
help = help or """\n
#### Generic bridge commands
**help** - Show this help message.
**cancel** - Cancel an ongoing action (such as login).
+1 -1
View File
@@ -103,7 +103,7 @@ def _get_portal_murder_function(action, room_id, function, command, completed_me
}
@command_handler(needs_auth=False)
@command_handler(needs_auth=False, needs_puppeting=False)
async def delete_portal(evt: CommandEvent):
portal, ok = await _get_portal_and_check_permission(evt, "delete_portal")
if not ok: