From 73fa5f432e6fd8fdf156239e47763e778bb4ea1b Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Sat, 27 Nov 2021 10:07:10 +0700 Subject: [PATCH] create function get user data --- program/function/user_data.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 program/function/user_data.py diff --git a/program/function/user_data.py b/program/function/user_data.py new file mode 100644 index 0000000..fee3c37 --- /dev/null +++ b/program/function/user_data.py @@ -0,0 +1,33 @@ +import logging +import datetime +from driver.database import Database +from config import DB_URL, DB_NAME, LOG_CH + + +db = Database(DB_URL, DB_NAME) + + +async def user_status(bot, cmd): + chat_id = cmd.from_user.id + if not await db.user_exist(chat_id): + data = await bot.get_me() + BOT_USERNAME = data.username + await db.add_user(chat_id) + if LOG_CH: + await bot.send_message( + LOG_CH, + f"#NEWUSER: \n\nNew User [{cmd.from_user.first_name}](tg://user?id={cmd.from_user.id}) started @{BOT_USERNAME} !!", + ) + else: + logging.info(f"#NewUser :- Name : {cmd.from_user.first_name} ID : {cmd.from_user.id}") + + ban_status = await db.get_ban_status(chat_id) + if ban_status["is_banned"]: + if ( + datetime.date.today() - datetime.date.fromisoformat(ban_status["banned_on"]) + ).days > ban_status["ban_duration"]: + await db.remove_ban(chat_id) + else: + await cmd.reply_text("You are Banned to Use This Bot ", quote=True) + return + await cmd.continue_propagation()