2023-08-23 14:49:01 +00:00
|
|
|
import asyncio
|
2023-08-23 09:39:03 +00:00
|
|
|
|
2024-05-10 14:06:34 +00:00
|
|
|
from signal import signal as signal_fn, SIGINT, SIGTERM, SIGABRT
|
|
|
|
|
|
|
|
from src.app import web
|
|
|
|
from src.bot import bot
|
|
|
|
from src.env import MIYOUSHE, HOYOLAB, BOT
|
|
|
|
|
|
|
|
|
|
|
|
async def idle():
|
|
|
|
task = None
|
|
|
|
|
|
|
|
def signal_handler(_, __):
|
|
|
|
if web.web_server_task:
|
|
|
|
web.web_server_task.cancel()
|
|
|
|
task.cancel()
|
|
|
|
|
|
|
|
for s in (SIGINT, SIGTERM, SIGABRT):
|
|
|
|
signal_fn(s, signal_handler)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
task = asyncio.create_task(asyncio.sleep(600))
|
|
|
|
web.bot_main_task = task
|
|
|
|
try:
|
|
|
|
await task
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
break
|
2023-08-23 14:49:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2023-08-24 07:35:45 +00:00
|
|
|
if MIYOUSHE:
|
|
|
|
from src.render.article import refresh_recommend_posts
|
|
|
|
|
|
|
|
await refresh_recommend_posts()
|
|
|
|
if HOYOLAB:
|
|
|
|
from src.render.article_hoyolab import refresh_hoyo_recommend_posts
|
|
|
|
|
|
|
|
await refresh_hoyo_recommend_posts()
|
2024-05-10 14:06:34 +00:00
|
|
|
await web.start()
|
|
|
|
if BOT:
|
|
|
|
await bot.start()
|
|
|
|
try:
|
|
|
|
await idle()
|
|
|
|
finally:
|
|
|
|
if BOT:
|
|
|
|
try:
|
|
|
|
await bot.stop()
|
|
|
|
except RuntimeError:
|
|
|
|
pass
|
|
|
|
if web.web_server:
|
|
|
|
try:
|
|
|
|
await web.web_server.shutdown()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2023-08-23 09:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-05-10 14:06:34 +00:00
|
|
|
asyncio.get_event_loop().run_until_complete(main())
|