You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

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()