aboutsummaryrefslogtreecommitdiff
path: root/helpers.py
blob: 4204870b2923d3454c819908d4d4cb9632aa84ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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()
    if user_id:
        if user_id in last_command_time:
            time_diff = current_time - last_command_time[user_id]
            if time_diff < 3:
                alo = "🚫 *файл не вошёл.* хватит так быстро слать свои сообщения.\n" \
                    f"подожди {round(3 - time_diff, 3)} секунд, брат😡😡"
                return alo, True
    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
                    )
                    for call in BOT_CALLS:
                        if call.startswith("@"):
                            if call.lower() in user_text.lower():
                                mentions_bot = True
                else:
                    mentions_bot = False
            else:
                mentions_bot = any(
                    user_text.lower().startswith(call.lower()) for call in BOT_CALLS
                )
                for call in BOT_CALLS:
                    if call.startswith("@"):
                        if call.lower() in user_text.lower():
                            mentions_bot = True
            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,
                ),
            ),
        )
    )