/nearby, subscriptions check, geocoding #2
@ -68,6 +68,11 @@ class UserInvalidError(Exception):
|
|||||||
self.user = user
|
self.user = user
|
||||||
super().__init__(f"Could not find HoloUser by using {type(self.user)} as an input type")
|
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():
|
class HoloUser():
|
||||||
"""This object represents a user of HoloChecker bot.
|
"""This object represents a user of HoloChecker bot.
|
||||||
It is primarily used to interact with a database in a more python-friendly way,
|
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!")
|
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))
|
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
|
"""Set label in destination group
|
||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
* chat (`Chat`): Telegram chat
|
* chat (`Chat`): Telegram chat
|
||||||
* label (`str`): Label you want to set
|
* label (`str`): Label you want to set
|
||||||
"""
|
"""
|
||||||
|
if len(label) > 16:
|
||||||
|
raise LabelTooLongError(label)
|
||||||
self.label = label
|
self.label = label
|
||||||
self.set("label", label)
|
self.set("label", label)
|
||||||
await app.promote_chat_member(configGet("destination_group"), self.id)
|
await app.promote_chat_member(configGet("destination_group"), self.id)
|
||||||
if not await isAnAdmin(self.id):
|
if not await isAnAdmin(self.id):
|
||||||
await app.set_administrator_title(configGet("destination_group"), self.id, label)
|
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
|
"""Reset label in destination group
|
||||||
|
|
||||||
### Args:
|
### Args:
|
||||||
|
@ -40,7 +40,7 @@ async def callback_query_sponsor_yes(app, clb):
|
|||||||
|
|
||||||
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "approved", "sent": False}})
|
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "approved", "sent": False}})
|
||||||
|
|
||||||
await holo_user.set_label(configGet("destination_group"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
|
await holo_user.label_set(configGet("destination_group"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
|
||||||
|
|
||||||
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ async def cmd_label(app, msg):
|
|||||||
label = " ".join(msg.command[2:])
|
label = " ".join(msg.command[2:])
|
||||||
|
|
||||||
if label.lower() == "reset":
|
if label.lower() == "reset":
|
||||||
await target.reset_label(msg.chat)
|
await target.label_reset(msg.chat)
|
||||||
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
|
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if len(label) > 16:
|
if len(label) > 16:
|
||||||
await msg.reply_text(locale("label_too_long", "message"))
|
await msg.reply_text(locale("label_too_long", "message"))
|
||||||
return
|
return
|
||||||
await target.set_label(msg.chat, label)
|
await target.label_set(msg.chat, label)
|
||||||
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
|
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -61,7 +61,7 @@ if configGet("enabled", "scheduler", "sponsorships"):
|
|||||||
try:
|
try:
|
||||||
holo_user = HoloUser(entry["user"])
|
holo_user = HoloUser(entry["user"])
|
||||||
await app.send_message( entry["user"], locale("sponsorships_expired", "message") ) # type: ignore
|
await app.send_message( entry["user"], locale("sponsorships_expired", "message") ) # type: ignore
|
||||||
await holo_user.reset_label(configGet("destination_group"))
|
await holo_user.label_reset(configGet("destination_group"))
|
||||||
try:
|
try:
|
||||||
tg_user = await app.get_users(entry["user"])
|
tg_user = await app.get_users(entry["user"])
|
||||||
logWrite(f"Notified user that sponsorship expires in {until_expiry} days")
|
logWrite(f"Notified user that sponsorship expires in {until_expiry} days")
|
||||||
|
Reference in New Issue
Block a user