Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/console.py

60 lines
2 KiB
Python
Raw Normal View History

2021-08-24 10:22:36 +00:00
import os
2021-07-30 19:32:58 +00:00
from config import Config
if not Config('db_path'):
raise AttributeError('Wait! You need to fill a valid database address into the config.cfg "db_path"\n'
'Example: \ndb_path = sqlite:///database/save.db\n'
2021-07-30 19:57:40 +00:00
'(Also you can fill in the above example directly,'
2021-07-30 19:32:58 +00:00
' bot will automatically create a SQLite database in the "./database/save.db")')
2021-02-19 08:56:57 +00:00
import asyncio
2021-04-10 13:12:32 +00:00
import traceback
import aioconsole
2021-02-19 08:56:57 +00:00
2022-01-08 15:14:44 +00:00
from datetime import datetime
2022-01-20 13:44:54 +00:00
from bot import init_bot
2022-06-12 07:07:53 +00:00
from core.elements import MsgInfo, Session, PrivateAssets, EnableDirtyWordCheck
from core.console.template import Template as MessageSession
2021-07-30 18:06:04 +00:00
from core.parser.message import parser
from core.scheduler import Scheduler
2022-06-12 07:07:53 +00:00
from core.utils import init, init_scheduler
2022-01-20 13:31:50 +00:00
from core.logger import Logger
2021-08-24 10:22:36 +00:00
EnableDirtyWordCheck.status = True
2021-08-24 10:22:36 +00:00
PrivateAssets.set(os.path.abspath(os.path.dirname(__file__) + '/assets'))
2021-10-14 15:18:47 +00:00
init()
2021-02-19 12:20:00 +00:00
async def console_scheduler():
2022-06-12 07:07:53 +00:00
await init_scheduler()
async def console_command():
try:
m = await aioconsole.ainput('> ')
2022-01-08 15:14:44 +00:00
time = datetime.now()
2021-08-07 07:56:48 +00:00
await parser(MessageSession(target=MsgInfo(targetId='TEST|0',
senderId='TEST|0',
senderName='',
targetFrom='TEST|Console',
senderFrom='TEST|Console'),
2021-08-07 07:56:48 +00:00
session=Session(message=m, target='TEST|0', sender='TEST|0')))
print('----Process end----')
2022-01-08 15:14:44 +00:00
usage_time = datetime.now() - time
print('Usage time:', usage_time)
await console_command()
except KeyboardInterrupt:
print('Exited.')
2021-10-14 15:18:47 +00:00
exit()
except Exception:
2022-01-20 13:31:50 +00:00
Logger.error(traceback.format_exc())
2021-08-23 12:44:31 +00:00
2021-08-07 12:55:07 +00:00
init_bot()
loop = asyncio.get_event_loop()
loop.create_task(console_scheduler())
loop.create_task(console_command())
loop.run_forever()