Files
uzbekgpt/helpers.py
T

87 lines
3.4 KiB
Python
Raw Normal View History

2026-05-24 22:26:14 +03:00
import time
from aiogram.methods import AnswerGuestQuery
from aiogram.types import InlineQueryResultArticle, InputTextMessageContent, Message
from aiogram.enums import ChatType
from supergenerator import *
def is_blocked(user_id):
current_time = time.time()
2026-07-05 14:52:57 +03:00
if user_id and user_id in last_command_time:
time_diff = current_time - last_command_time[user_id][0]
2026-07-05 15:43:52 +03:00
if user_id in last_error_time:
time_error_diff = current_time - last_error_time[user_id]
else:
last_error_time[user_id] = current_time
time_error_diff = 1984
2026-06-18 21:48:44 +03:00
if time_diff < 3:
alo = "🚫 *файл не вошёл.* хватит так быстро слать свои сообщения.\n" \
f"подожди {round(3 - time_diff, 3)} секунд, брат😡😡"
2026-07-05 17:34:41 +03:00
elif last_command_time[user_id][1] and time_diff < 10:
2026-07-05 14:52:57 +03:00
alo = "🚫 *файл не вошёл.* я ещё не сгенерировал прошлое сообщение.\n" \
f"подожди {round(10 - time_diff, 3)} секунд, чтобы я закрыл глаза " \
"на это da."
2026-07-05 15:43:52 +03:00
elif len(last_command_time[user_id][2]) > 1:
alo = "🚫 *файл не вошёл.* хватит так быстро слать свои сообщения."
2026-07-05 14:52:57 +03:00
else:
return "", False
2026-07-05 17:06:11 +03:00
2026-07-05 15:43:52 +03:00
if time_error_diff < 2:
return "", True
else:
last_error_time[user_id] = current_time
return alo, True
2026-05-24 22:26:14 +03:00
return "", False
def is_replied_bot(message, is_channel, user_text, config=None):
if message.chat.type in [ChatType.GROUP, ChatType.SUPERGROUP, ChatType.CHANNEL]:
if not is_channel:
is_reply_to_bot = (
message.reply_to_message
and message.reply_to_message.from_user
and message.reply_to_message.from_user.is_bot
and message.reply_to_message.from_user.username == BOT_USERNAME
)
if config:
if config.get("call") == "da":
mentions_bot = any(
user_text.lower().startswith(call.lower()) for call in BOT_CALLS
)
2026-05-29 15:49:45 +03:00
for call in BOT_CALLS:
if call.startswith("@"):
if call.lower() in user_text.lower():
mentions_bot = True
2026-05-24 22:26:14 +03:00
else:
mentions_bot = False
else:
mentions_bot = any(
user_text.lower().startswith(call.lower()) for call in BOT_CALLS
)
2026-05-29 15:49:45 +03:00
for call in BOT_CALLS:
if call.startswith("@"):
if call.lower() in user_text.lower():
mentions_bot = True
2026-05-24 22:26:14 +03:00
if not (is_reply_to_bot or mentions_bot):
return False
return True
async def g_answer(data, message, text, title="da", id="1", parse_mode="Markdown"):
return await data["bot"](
AnswerGuestQuery(
guest_query_id=message.guest_query_id,
result=InlineQueryResultArticle(
id=id,
title=title,
input_message_content=InputTextMessageContent(
message_text=text,
parse_mode=parse_mode,
),
),
)
)