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-02 04:40:29 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2021-02-19 08:56:57 +00:00
|
|
|
|
2021-08-01 14:54:25 +00:00
|
|
|
from core.elements.message import MsgInfo, Session
|
2021-07-30 18:06:04 +00:00
|
|
|
from core.unit_test.template import Template
|
|
|
|
from core.parser.message import parser
|
|
|
|
from core.loader import Modules
|
2021-02-19 12:20:00 +00:00
|
|
|
|
2021-08-02 04:40:29 +00:00
|
|
|
cache_path = os.path.abspath('./cache/')
|
|
|
|
if os.path.exists(cache_path):
|
|
|
|
shutil.rmtree(cache_path)
|
|
|
|
os.mkdir(cache_path)
|
|
|
|
else:
|
|
|
|
os.mkdir(cache_path)
|
|
|
|
|
|
|
|
version = os.path.abspath('.version')
|
|
|
|
write_version = open(version, 'w')
|
|
|
|
write_version.write(os.popen('git rev-parse HEAD', 'r').read()[0:7])
|
|
|
|
write_version.close()
|
|
|
|
|
|
|
|
tag = os.path.abspath('.version_tag')
|
|
|
|
write_tag = open(tag, 'w')
|
|
|
|
write_tag.write(os.popen('git tag -l', 'r').read().split('\n')[-2])
|
|
|
|
write_tag.close()
|
2021-07-30 18:06:04 +00:00
|
|
|
|
|
|
|
async def unit_test():
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
m = input('> ')
|
2021-08-01 14:54:25 +00:00
|
|
|
await parser(Template(target=MsgInfo(targetId='TEST|0',
|
2021-07-30 18:06:04 +00:00
|
|
|
senderId='TEST|0',
|
|
|
|
senderName='',
|
|
|
|
targetFrom='TEST|Console',
|
|
|
|
senderFrom='TEST|Console'),
|
|
|
|
session=Session(message=m, target='TEST|0', sender='TEST|0')))
|
2021-07-31 06:24:01 +00:00
|
|
|
print('----Process end----')
|
2021-07-30 18:06:04 +00:00
|
|
|
except KeyboardInterrupt:
|
2021-07-30 18:07:46 +00:00
|
|
|
print('Exited.')
|
2021-07-30 18:06:04 +00:00
|
|
|
break
|
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
asyncio.run(unit_test())
|