From 97325b4ff5b4fdc1789bff0c84b29ae3936f8d5c Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 1 Dec 2022 11:06:54 +0100 Subject: [PATCH] Added auto-removal of applications in group --- config_example.json | 2 ++ locale/uk.json | 4 ++-- main.py | 13 ++++++++++++- modules/inline.py | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config_example.json b/config_example.json index b0f7e4a..85ff577 100644 --- a/config_example.json +++ b/config_example.json @@ -2,6 +2,7 @@ "locale": "uk", "debug": false, "owner": 0, + "bot_id": 0, "age_allowed": 0, "birthdays_notify": true, "birthdays_time": "09:00", @@ -9,6 +10,7 @@ "inline_preview_count": 7, "admin_group": 0, "destination_group": 0, + "remove_application_time": -1, "admins": [], "bot": { "api_id": 0, diff --git a/locale/uk.json b/locale/uk.json index c3af36c..f33a6a4 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -138,8 +138,8 @@ }, "not_pm": { "title": "Дія недоступна", - "description": "Ця команда доступна тільки в приватних повідомленнях в чаті з самим ботом", - "message_content": "Дія доступна тільки в ПП." + "description": "Ця команда недоступна в каналах", + "message_content": "Дія недоступна в каналах." }, "user": { "title": "", diff --git a/main.py b/main.py index eb51d99..0d5207d 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import asyncio from datetime import datetime from threading import Thread from dateutil.relativedelta import relativedelta @@ -644,7 +645,7 @@ async def get_contact(app, msg): @app.on_message(~ filters.scheduled & filters.private) async def any_stage(app, msg): - if msg.via_bot == None: + if msg.via_bot is None: user_stage = configGet("stage", file=str(msg.from_user.id)) @@ -703,6 +704,16 @@ async def any_stage(app, msg): else: if not configGet("approved", file=str(msg.from_user.id)) and not configGet("refused", file=str(msg.from_user.id)): await msg.reply_text(locale("already_sent", "message")) + +@app.on_message(~ filters.scheduled & filters.group) +async def message_in_group(app, msg): + if (msg.chat is not None) and (msg.via_bot is not None): + if (msg.via_bot.id == configGet("bot_id")) and (msg.chat.id == configGet("destination_group")): + if configGet("remove_application_time") > 0: + logWrite(f"User {msg.from_user.id} requested application in destination group, removing in {configGet('remove_application_time')} minutes") + await asyncio.sleep(configGet("remove_application_time")*60) + await msg.delete() + logWrite(f"Removed application requested by {msg.from_user.id} in destination group") # ============================================================================================================================== diff --git a/modules/inline.py b/modules/inline.py index 395fa1b..a96b1aa 100644 --- a/modules/inline.py +++ b/modules/inline.py @@ -11,7 +11,7 @@ from modules.utils import configGet, jsonLoad, locale @app.on_inline_query() async def inline_answer(client, inline_query): - if inline_query.chat_type not in [ChatType.BOT, ChatType.PRIVATE]: + if inline_query.chat_type in [ChatType.CHANNEL]: await inline_query.answer( results=[ InlineQueryResultArticle(