Added LabelTooLongError() and changed names

This commit is contained in:
Profitroll
2022-12-22 22:11:36 +01:00
parent 7db8c9ac5c
commit 12da1b2376
4 changed files with 13 additions and 6 deletions

View File

@@ -68,6 +68,11 @@ class UserInvalidError(Exception):
self.user = user
super().__init__(f"Could not find HoloUser by using {type(self.user)} as an input type")
class LabelTooLongError(Exception):
def __init__(self, label: str) -> None:
self.label = label
super().__init__(f"Could not set label to '{label}' because it is {len(label)} characters long (16 is maximum)")
class HoloUser():
"""This object represents a user of HoloChecker bot.
It is primarily used to interact with a database in a more python-friendly way,
@@ -270,20 +275,22 @@ class HoloUser():
logWrite(f"Could not notify admin about failure when sending message! Admin has never interacted with bot!")
await context.reply_text(locale("message_error", "message"), quote=should_quote(context))
async def set_label(self, chat: Chat, label: str) -> None:
async def label_set(self, chat: Chat, label: str) -> None:
"""Set label in destination group
### Args:
* chat (`Chat`): Telegram chat
* label (`str`): Label you want to set
"""
if len(label) > 16:
raise LabelTooLongError(label)
self.label = label
self.set("label", label)
await app.promote_chat_member(configGet("destination_group"), self.id)
if not await isAnAdmin(self.id):
await app.set_administrator_title(configGet("destination_group"), self.id, label)
async def reset_label(self, chat: Chat) -> None:
async def label_reset(self, chat: Chat) -> None:
"""Reset label in destination group
### Args: