Загрузка...

Портфолио бот + спамблок

Тема в разделе Python создана пользователем Эксфадор 20 дек 2024. 221 просмотр

  1. Эксфадор
    Эксфадор Автор темы 20 дек 2024 ПЛАГИНЫ ДЛЯ FPC - t.me/coxerhub 1739 30 авг 2023
    Python
    import asyncio
    import logging
    import sys
    from datetime import datetime, timedelta
    from aiogram import F
    import aiosqlite
    from aiogram import Bot, Dispatcher, html
    from aiogram.client.default import DefaultBotProperties
    from aiogram.enums import ParseMode
    from aiogram.filters import CommandStart
    from aiogram.types import Message
    from aiogram.types import CallbackQuery
    from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
    import tracemalloc

    tracemalloc.start()

    TOKEN = '7752447698:AA'
    ADMIN = 8029299947

    text = """
    Тут информационный блог будет
    """

    dp = Dispatcher()
    bot = Bot(token=TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))

    buttons = [
    [
    InlineKeyboardButton(text='ТГК', url='https://t.me/medfaqes'),
    InlineKeyboardButton(text='Портфолио', url='https://t.me/medfaqes'),
    InlineKeyboardButton(text='Профиль', url='https://t.me/exfador'),
    ],
    [
    InlineKeyboardButton(text='LZT', url='https://lolz.live/threads/7607854/'),
    ],
    [
    InlineKeyboardButton(text='Спамблок', callback_data='sp'),
    ]
    ]

    menu = InlineKeyboardMarkup(inline_keyboard=buttons)

    @dp.message(CommandStart())
    async def command_start_handler(message: Message) -> None:
    username = message.from_user.username
    user_id = message.from_user.id
    await register_account(username, user_id)
    await message.answer(f"Привет, {html.bold(message.from_user.full_name)}!\n{text}", reply_markup=menu)

    @dp.callback_query(F.data == 'sp')
    async def spam_block(callback_query: CallbackQuery) -> None:
    user_id = callback_query.from_user.id
    result = await spam_time_and_check(user_id)
    if isinstance(result, str):
    await callback_query.answer(result, show_alert=True)
    else:
    await callback_query.answer("Оповестил администратора о том, что у Вас спамблок. Ожидайте", show_alert=True)
    await bot.send_message(chat_id=ADMIN, text=f"""
    Пользователь: @{callback_query.from_user.username} попросил связаться с ним.
    """)

    async def main() -> None:
    try:
    async with aiosqlite.connect('users.db') as db:
    cursor = await db.cursor()
    await cursor.execute('''CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY,
    username TEXT UNIQUE NOT NULL,
    report_time INTEGER NOT NULL
    )''')
    await db.commit()
    await dp.start_polling(bot)

    except Exception as ee:
    print(f"Cannot connect to the database: {ee}")

    async def register_account(username, user_id) -> None:
    async with aiosqlite.connect('users.db') as db:
    cursor = await db.cursor()
    await cursor.execute('SELECT * FROM users WHERE id = ?', (user_id,))
    result = await cursor.fetchone()
    if not result:
    current_time = int(datetime.utcnow().timestamp())
    await cursor.execute('INSERT INTO users (id, username, report_time) VALUES (?, ?, ?)', (user_id, username, current_time))
    await db.commit()

    async def spam_time_and_check(user_id) -> None:
    async with aiosqlite.connect('users.db') as db:
    time_limit = 300
    cursor = await db.cursor()
    await cursor.execute('SELECT report_time FROM users WHERE id = ?', (user_id,))
    result = await cursor.fetchone()

    if result:
    last_report_time = result[0]
    last_report_time_dt = datetime.fromtimestamp(last_report_time)
    current_time = datetime.utcnow()

    if (current_time - last_report_time_dt).total_seconds() >= time_limit:
    new_report_time = current_time + timedelta(seconds=time_limit)
    await cursor.execute('UPDATE users SET report_time = ? WHERE id = ?', (int(new_report_time.timestamp()), user_id))
    await db.commit()
    return None
    else:
    remaining_time = time_limit - (current_time - last_report_time_dt).total_seconds()
    minutes_left = int(remaining_time // 60)
    seconds_left = int(remaining_time % 60)
    return f'Вы не можете сейчас отправить оповещение администратору, Вам будет доступно через: {minutes_left} минут(ы) и {seconds_left} секунд(ы)'
    else:
    return 'Ошибка, аккаунт не найден в базе данных.'

    if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO, stream=sys.stdout)
    asyncio.run(main())
    [IMG]
    [IMG]
     
  2. tvoiLil
    tvoiLil 20 дек 2024 539 14 дек 2019
    Спамблок прикольно реальзован
     
  3. xnerv1nyyy
    xnerv1nyyy 20 дек 2024 6 10 апр 2022
    очень солидно смотрится, разрешите воспользоваться??
     
    1. Эксфадор Автор темы
Top
Загрузка...