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/commandlist.py

38 lines
1.2 KiB
Python
Raw Normal View History

2020-09-19 06:21:06 +00:00
def commandlist():
2020-09-19 10:30:27 +00:00
clist = {}
2020-09-19 06:21:06 +00:00
import os
path = os.path.abspath('./modules')
dirs = os.listdir(path)
import re
for file in dirs:
filename = os.path.abspath(f'./modules/{file}')
2020-09-22 15:44:05 +00:00
a1 = None
a2 = None
2020-09-19 06:21:06 +00:00
if os.path.isdir(filename):
if file == '__pycache__':
pass
else:
2020-09-22 15:44:05 +00:00
a1 = file
a2 = file
2020-09-19 06:21:06 +00:00
if os.path.isfile(filename):
b = re.match(r'(.*)(.py)', file)
if b:
2020-09-22 15:44:05 +00:00
a1 = b.group(1)
a2 = b.group(1)
try:
if a1 is not None:
a = __import__('modules.' + a1, fromlist=[a2])
if isinstance(a.command, dict):
clist.update(a.command)
print(f'Successful loaded {a2} from {a1}! command = {a.command}')
elif isinstance(a.command, tuple):
for x in a.command:
if isinstance(x, dict):
clist.update(x)
print(f'Successful loaded {x.keys()}! command = {x}')
except Exception as e:
print(str(e) + ', skip!')
2020-09-19 06:21:06 +00:00
return clist