|
|
|
@ -9,16 +9,18 @@ from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
|
DELAY_TIME = 1 |
|
|
|
|
DELAY_TIME_Q = 3 |
|
|
|
|
CHAT_ID = "@gorgorod_information" |
|
|
|
|
ALLOWED_USERS = [106693654, 7063133] |
|
|
|
|
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) |
|
|
|
|
if message["from"]["id"] not in ALLOWED_USERS: |
|
|
|
|
return await message.reply("Access Denied", reply=False) |
|
|
|
|
return await func(message) |
|
|
|
|
|
|
|
|
|
return wrapper |
|
|
|
@ -27,7 +29,7 @@ def auth(func):
|
|
|
|
|
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) |
|
|
|
|
await bot.delete_message(chat_id=CHAT_ID, message_id=message_id) |
|
|
|
|
|
|
|
|
|
except MessageToDeleteNotFound: |
|
|
|
|
print("Ошибка удаления сообщения") |
|
|
|
@ -37,7 +39,7 @@ async def clean_up(message_id: int, delay_min: int):
|
|
|
|
|
@auth |
|
|
|
|
async def send_welcome(message: types.Message): |
|
|
|
|
await message.reply( |
|
|
|
|
"Бот для отправки новостей\n\n" "Еще одна строка\n", reply=False |
|
|
|
|
"Бот для отправки новостей\n\n" "/mes для отправки сообщения\n", reply=False |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -48,15 +50,30 @@ 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", |
|
|
|
|
chat_id=CHAT_ID, |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=["question"]) |
|
|
|
|
@auth |
|
|
|
|
async def send_to_chanel(message: types.Message): |
|
|
|
|
|
|
|
|
|
deletion_time = message.date + timedelta(minutes=DELAY_TIME_Q) |
|
|
|
|
out_text = f"*Внимание, вопрос!*\n\n{message.text[10:]}\n\nБудет удалено в *{deletion_time}*" |
|
|
|
|
result = await bot.send_message( |
|
|
|
|
chat_id=CHAT_ID, |
|
|
|
|
text=out_text, |
|
|
|
|
disable_notification=True, |
|
|
|
|
parse_mode="Markdown", |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
await clean_up(message_id=result.message_id, delay_min=DELAY_TIME_Q) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
executor.start_polling(dp, skip_updates=True) |
|
|
|
|