From ce08187356457f53a13f9c405fd0cff46583bb65 Mon Sep 17 00:00:00 2001 From: justuser31 Date: Thu, 27 Apr 2023 15:12:52 +0300 Subject: [PATCH] Bonk it --- bonk.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 bonk.py diff --git a/bonk.py b/bonk.py new file mode 100644 index 0000000..eac38a2 --- /dev/null +++ b/bonk.py @@ -0,0 +1,52 @@ +import telebot +import time +import os +import json + +last_bonk_time = {} # словарь для хранения времени последней команды "хрясь" + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_NAME = 'data.json' + +DB_PATH = os.path.join(BASE_DIR, BASE_NAME) + +# если базы данных нет, то создаем новую +if not os.path.exists(DB_PATH): + with open(DB_PATH, 'w') as f: + json.dump({}, f) + +# загружаем базу данных +with open(DB_PATH, 'r') as f: + last_bonk_time = json.load(f) + +# Загружаем токен из файла +bot = telebot.TeleBot(last_bonk_time['token']) + +print(last_bonk_time) + +@bot.message_handler(func=lambda message: True) +def bonk(message): + chat_id = message.chat.id + reply_message = message.reply_to_message + if reply_message: + bonk_target = reply_message.from_user.id + user_id = str(message.from_user.id) + current_time = time.time() + if 'хрясь' in message.text.lower(): + if user_id not in last_bonk_time or current_time - last_bonk_time[user_id] > 1800: + try: + bot.restrict_chat_member(chat_id, bonk_target, until_date=current_time+300) + text = f'{message.from_user.full_name} угостил дубиной {reply_message.from_user.full_name} 👊' + bot.send_message(chat_id, text) + last_bonk_time[user_id] = current_time + + with open(DB_PATH, 'w') as f: + json.dump(last_bonk_time, f) + except: + bot.send_message(chat_id, 'Что-то пошло не так...') + else: + wait_time = int(1800 - current_time + last_bonk_time[user_id]) + text = f"{message.from_user.full_name}, подождите, вы уже использовали 'хрясь' недавно. Попробуйте снова через {wait_time // 60} мин. {wait_time % 60} сек." + bot.send_message(chat_id, text) + +bot.polling()