Add command to force set a Matrix power level without affecting Telegram. Fixes #60

This commit is contained in:
Tulir Asokan
2018-03-08 19:58:49 +02:00
parent b3082da999
commit f6e3903b45
2 changed files with 21 additions and 3 deletions
+1
View File
@@ -58,6 +58,7 @@ def help(evt):
**search** [_-r|--remote_] <_query_> - Search your contacts or the Telegram servers for users. **search** [_-r|--remote_] <_query_> - Search your contacts or the Telegram servers for users.
**sync** [`chats`|`contacts`|`me`] - Synchronize your chat portals, contacts and/or own info. **sync** [`chats`|`contacts`|`me`] - Synchronize your chat portals, contacts and/or own info.
**ping-bot** - Get info of the message relay Telegram bot. **ping-bot** - Get info of the message relay Telegram bot.
**set-pl** <_level_> - Set a temporary power level without affecting Telegram.
#### Initiating chats #### Initiating chats
**pm** <_identifier_> - Open a private chat with the given Telegram user. The identifier is either **pm** <_identifier_> - Open a private chat with the given Telegram user. The identifier is either
+17
View File
@@ -23,6 +23,23 @@ from .. import portal as po
from . import command_handler, CommandEvent from . import command_handler, CommandEvent
@command_handler(needs_admin=True, needs_auth=False, name="set-pl")
async def set_power_level(evt: CommandEvent):
try:
level = int(evt.args[0])
except KeyError:
return await evt.reply("**Usage:** `$cmdprefix+sp set-power <level>`")
except ValueError:
return await evt.reply("The level must be an integer.")
levels = await evt.az.intent.get_power_levels(evt.room_id)
levels["users"][evt.sender.mxid] = level
try:
await evt.az.intent.set_power_levels(evt.room_id, levels)
except MatrixRequestError:
evt.log.exception("Failed to set power level.")
return await evt.reply("Failed to set power level.")
@command_handler() @command_handler()
async def invite_link(evt: CommandEvent): async def invite_link(evt: CommandEvent):
portal = po.Portal.get_by_mxid(evt.room_id) portal = po.Portal.get_by_mxid(evt.room_id)