2021-07-11 12:53:33 +03:00
|
|
|
|
import asyncio
|
2021-09-28 01:43:57 +03:00
|
|
|
|
import argparse
|
2021-07-11 12:53:33 +03:00
|
|
|
|
from tortoise import Tortoise
|
|
|
|
|
|
2021-09-06 00:36:03 +03:00
|
|
|
|
from olgram.router import dp
|
2021-10-01 19:48:23 +03:00
|
|
|
|
from olgram.settings import TORTOISE_ORM, OlgramSettings
|
|
|
|
|
from olgram.utils.permissions import AccessMiddleware
|
2021-09-10 22:38:29 +03:00
|
|
|
|
from server.custom import init_redis
|
2021-07-11 12:53:33 +03:00
|
|
|
|
|
2021-09-09 10:58:33 +03:00
|
|
|
|
import olgram.commands.bots # noqa: F401
|
|
|
|
|
import olgram.commands.start # noqa: F401
|
|
|
|
|
import olgram.commands.menu # noqa: F401
|
|
|
|
|
import olgram.commands.bot_actions # noqa: F401
|
2021-12-24 19:39:25 +03:00
|
|
|
|
import olgram.commands.info # noqa: F401
|
2021-07-11 12:53:33 +03:00
|
|
|
|
|
2021-09-09 23:35:13 +03:00
|
|
|
|
from server.server import main as server_main
|
|
|
|
|
|
2021-07-11 12:53:33 +03:00
|
|
|
|
|
|
|
|
|
async def init_database():
|
|
|
|
|
await Tortoise.init(config=TORTOISE_ORM)
|
|
|
|
|
|
|
|
|
|
|
2021-09-10 23:20:06 +03:00
|
|
|
|
async def init_olgram():
|
2021-10-01 19:48:23 +03:00
|
|
|
|
from olgram.router import bot, dp
|
|
|
|
|
dp.setup_middleware(AccessMiddleware(OlgramSettings.admin_id()))
|
2021-09-10 23:20:06 +03:00
|
|
|
|
from aiogram.types import BotCommand
|
|
|
|
|
await bot.set_my_commands(
|
|
|
|
|
[
|
|
|
|
|
BotCommand("start", "Запустить бота"),
|
2021-09-10 23:21:23 +03:00
|
|
|
|
BotCommand("addbot", "Добавить бот"),
|
|
|
|
|
BotCommand("mybots", "Управление ботами"),
|
2021-09-10 23:20:06 +03:00
|
|
|
|
BotCommand("help", "Справка")
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def initialization():
|
|
|
|
|
await init_database()
|
|
|
|
|
await init_redis()
|
|
|
|
|
await init_olgram()
|
|
|
|
|
|
|
|
|
|
|
2021-07-11 12:53:33 +03:00
|
|
|
|
def main():
|
|
|
|
|
"""
|
|
|
|
|
Classic polling
|
|
|
|
|
"""
|
2021-09-28 01:43:57 +03:00
|
|
|
|
parser = argparse.ArgumentParser("Olgram server")
|
|
|
|
|
parser.add_argument("--noserver", help="Не запускать сервер обратной связи, только сам Olgram (режим для "
|
|
|
|
|
"разработки)", action="store_true")
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2022-01-19 00:42:29 +03:00
|
|
|
|
loop = asyncio.get_event_loop()
|
2021-09-10 23:20:06 +03:00
|
|
|
|
loop.run_until_complete(initialization())
|
2021-07-11 12:53:33 +03:00
|
|
|
|
|
2021-09-10 00:41:50 +03:00
|
|
|
|
loop.create_task(dp.start_polling())
|
2021-09-28 01:43:57 +03:00
|
|
|
|
if not args.noserver:
|
|
|
|
|
loop.create_task(server_main().start())
|
2021-07-11 12:53:33 +03:00
|
|
|
|
|
|
|
|
|
loop.run_forever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|