Бот для телеги, открывающий доступ в чатик по приглашениям.
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.

63 lines
1.8 KiB

import os
import logging
import threading
from aiogram import Bot, Dispatcher, executor, types
from time import sleep
from aiogram.utils.exceptions import MessageToDeleteNotFound
import asyncio
from datetime import timedelta
logging.basicConfig(level=logging.INFO)
DELAY_TIME = 1
API_TOKEN = os.getenv("TELEGRAM_API_TOKEN")
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
def auth(func):
# нужно будет узнать свой id
async def wrapper(message):
# if message["from"]["id"] != 123:
# return await message.replay("Access Denied", reply=False)
return await func(message)
return wrapper
async def clean_up(message_id: int, delay_min: int):
await asyncio.sleep(delay_min * 60)
try:
await bot.delete_message(chat_id="@gorgorod_information", message_id=message_id)
except MessageToDeleteNotFound:
print("Ошибка удаления сообщения")
@dp.message_handler(commands=["start", "help"])
@auth
async def send_welcome(message: types.Message):
await message.reply(
"Бот для отправки новостей\n\n" "Еще одна строка\n", reply=False
)
@dp.message_handler(commands=["mes"])
@auth
async def send_to_chanel(message: types.Message):
deletion_time = message.date + timedelta(minutes=DELAY_TIME)
out_text = f"{message.text[5:]} \n\nБудет удалено в *{deletion_time}*"
result = await bot.send_message(
chat_id="@gorgorod_information",
text=out_text,
disable_notification=True,
parse_mode="Markdown",
)
print(message.message_id)
print(result.message_id)
await clean_up(message_id=result.message_id, delay_min=DELAY_TIME)
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)