92 lines
2.5 KiB
Python
92 lines
2.5 KiB
Python
|
#!/usr/bin/env python3
|
|||
|
import logging
|
|||
|
|
|||
|
from aiogram import executor, types
|
|||
|
|
|||
|
from load import bot, dp, config
|
|||
|
from database import get_all_users
|
|||
|
|
|||
|
logging.basicConfig(
|
|||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|||
|
level=logging.INFO
|
|||
|
)
|
|||
|
|
|||
|
|
|||
|
|
|||
|
WEBAPP_HOST = config.bot("ip")
|
|||
|
WEBAPP_PORT = config.bot("port")
|
|||
|
|
|||
|
WEBHOOK_HOST = f'http://{WEBAPP_HOST}:{WEBAPP_PORT}'
|
|||
|
WEBHOOK_PATH = f'/bot{config.bot("token")}/'
|
|||
|
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
|||
|
|
|||
|
engeneerings_works = (
|
|||
|
"Техничиские работы..."
|
|||
|
"Постараемся восстановить работу как можно раньше!"
|
|||
|
)
|
|||
|
|
|||
|
parse_error = (
|
|||
|
"Бот приостановлен на неопределенный срок!\n"
|
|||
|
"Что случилось?\n"
|
|||
|
"Администрация коледжа изменила формат файла с google docs на docx(Microsoft Office)\n"
|
|||
|
"Замены вы можете посмотреть тут: https://docs.google.com/document/d/{}".format(config.documentid)
|
|||
|
)
|
|||
|
|
|||
|
new_year = (
|
|||
|
"С новым годом!❄️\n"
|
|||
|
"Бот будет отключён до 16.01.2022(Период зимних каникул)\n"
|
|||
|
)
|
|||
|
|
|||
|
link_replace = 'https://tfk.org.ua/zamini-do-rozkladu-08-51-30-03-02-2022/'
|
|||
|
|
|||
|
the_end =(
|
|||
|
"Всё было восстановлено и настроено. Бот продолжает работу!:)"
|
|||
|
)
|
|||
|
|
|||
|
|
|||
|
send_msg = the_end
|
|||
|
|
|||
|
async def on_startup(dp):
|
|||
|
await bot.set_webhook(url=WEBHOOK_URL)
|
|||
|
|
|||
|
|
|||
|
async def on_shutdown(dp):
|
|||
|
await bot.delete_webhook()
|
|||
|
|
|||
|
@dp.message_handler(commands=['send'])
|
|||
|
async def asd(message):
|
|||
|
for user_id in get_all_users():
|
|||
|
if user_id != 1083440854:
|
|||
|
print(user_id)
|
|||
|
try:
|
|||
|
await bot.send_message(chat_id=user_id, text=send_msg)
|
|||
|
except:
|
|||
|
pass
|
|||
|
|
|||
|
#@dp.message_handler()
|
|||
|
async def start(message: types.Message):
|
|||
|
logging.info(
|
|||
|
"{} - {}".format(
|
|||
|
message.from_user.id,
|
|||
|
message.from_user.username
|
|||
|
)
|
|||
|
)
|
|||
|
await bot.send_message(
|
|||
|
message.chat.id,
|
|||
|
engeneerings_works
|
|||
|
)
|
|||
|
|
|||
|
if __name__ == "__main__":
|
|||
|
if config.bot("use_webhook").lower() in ['t', 'true', '1', 'yes', 'y']:
|
|||
|
executor.start_webhook(
|
|||
|
dispatcher=dp,
|
|||
|
webhook_path=WEBHOOK_PATH,
|
|||
|
on_startup=on_startup,
|
|||
|
skip_updates=True,
|
|||
|
on_shutdown=on_shutdown,
|
|||
|
host=WEBAPP_HOST,
|
|||
|
port=WEBAPP_PORT,
|
|||
|
)
|
|||
|
else:
|
|||
|
executor.start_polling(dp, skip_updates=True)
|