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
|
2021-08-04 16:14:23 +00:00
|
|
|
import aioconsole
|
2021-02-19 08:56:57 +00:00
|
|
|
|
2021-08-20 16:32:46 +00:00
|
|
|
from init import init_bot
|
2021-11-01 15:54:12 +00:00
|
|
|
from core.elements import Schedule, StartUp, MsgInfo, Session, PrivateAssets, EnableDirtyWordCheck
|
2021-08-07 07:56:48 +00:00
|
|
|
from core.unit_test.template import Template as MessageSession, FetchTarget
|
2021-07-30 18:06:04 +00:00
|
|
|
from core.parser.message import parser
|
2021-08-04 16:14:23 +00:00
|
|
|
from core.scheduler import Scheduler
|
2021-10-14 15:18:47 +00:00
|
|
|
from core.loader import ModulesManager
|
2021-10-14 15:29:59 +00:00
|
|
|
from core.utils import init
|
2021-08-24 10:22:36 +00:00
|
|
|
|
2021-11-01 15:54:12 +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
|
|
|
|
2021-08-04 16:14:23 +00:00
|
|
|
|
|
|
|
async def unit_test_scheduler():
|
|
|
|
gather_list = []
|
2021-10-14 15:18:47 +00:00
|
|
|
Modules = ModulesManager.return_modules_list_as_dict()
|
2021-08-04 16:14:23 +00:00
|
|
|
for x in Modules:
|
2021-10-14 14:49:12 +00:00
|
|
|
if isinstance(Modules[x], StartUp):
|
2021-08-07 07:56:48 +00:00
|
|
|
gather_list.append(asyncio.ensure_future(Modules[x].function(FetchTarget)))
|
2021-08-30 18:53:39 +00:00
|
|
|
if isinstance(Modules[x], Schedule):
|
|
|
|
Scheduler.add_job(func=Modules[x].function, trigger=Modules[x].trigger, args=[FetchTarget])
|
2021-08-04 16:14:23 +00:00
|
|
|
await asyncio.gather(*gather_list)
|
|
|
|
Scheduler.start()
|
|
|
|
|
|
|
|
|
|
|
|
async def unit_test_command():
|
|
|
|
try:
|
|
|
|
m = await aioconsole.ainput('> ')
|
2021-08-07 07:56:48 +00:00
|
|
|
await parser(MessageSession(target=MsgInfo(targetId='TEST|0',
|
2021-08-04 16:14:23 +00:00
|
|
|
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')))
|
2021-08-04 16:14:23 +00:00
|
|
|
print('----Process end----')
|
|
|
|
await unit_test_command()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('Exited.')
|
2021-10-14 15:18:47 +00:00
|
|
|
exit()
|
2021-08-04 16:14:23 +00:00
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
|
2021-08-23 12:44:31 +00:00
|
|
|
|
2021-08-07 12:55:07 +00:00
|
|
|
init_bot()
|
2021-08-04 16:14:23 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.create_task(unit_test_scheduler())
|
|
|
|
loop.create_task(unit_test_command())
|
|
|
|
loop.run_forever()
|