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

100 lines
2.9 KiB
Python
Raw Normal View History

2020-08-07 06:19:34 +00:00
import re
2020-08-12 16:01:34 +00:00
2020-09-19 06:21:06 +00:00
ignorelist = []
2020-08-12 16:01:34 +00:00
2020-09-19 06:21:06 +00:00
from commandlist import commandlist
clist = commandlist()
2020-09-10 14:35:23 +00:00
2020-09-24 14:09:02 +00:00
2020-08-30 08:26:54 +00:00
async def findcommand(str1, group=0):
2020-08-12 16:01:34 +00:00
str1 = re.sub(r'^', '~', str1)
2020-09-10 14:29:33 +00:00
q = re.match(r'^.*(: ~)(.*)', str1)
if q:
2020-08-07 06:19:34 +00:00
return q.group(2)
2020-09-10 14:29:33 +00:00
q = re.match(r'^~(.*)', str1)
if q:
return q.group(1)
q = re.match(r'^!(.*\-.*)', str1)
if q:
q = str.upper(q.group(1))
return 'bug ' + q
2020-09-17 12:19:42 +00:00
w = re.findall(r'\[\[(.*?)\]\]', str1, re.I)
w2 = re.findall(r'\{\{(.*?)\}\}', str1, re.I)
2020-09-10 14:29:33 +00:00
z = []
c = '\n'
if w:
2020-09-11 15:03:01 +00:00
from modules.wiki import im, imarc
2020-09-17 12:05:44 +00:00
wi1 = []
2020-09-10 14:29:33 +00:00
if str(w) != '['']' or str(w) != '[]':
for x in w:
2020-09-17 12:05:44 +00:00
if x == '' or x in wi1:
2020-08-30 08:26:54 +00:00
pass
2020-09-10 14:29:33 +00:00
else:
2020-09-17 12:05:44 +00:00
wi1.append(x)
if wi1 != []:
if group in ignorelist:
z.append(await imarc(wi1))
else:
z.append(await im(wi1))
2020-09-10 14:29:33 +00:00
if w2:
2020-09-11 15:03:01 +00:00
from modules.wiki import imt
2020-09-17 12:05:44 +00:00
wi2 = []
2020-09-10 14:29:33 +00:00
if str(w2) != '['']' or str(w2) != '[]':
for x in w2:
2020-09-17 12:05:44 +00:00
if x == '' or x in wi2:
2020-08-30 08:26:54 +00:00
pass
else:
2020-09-17 12:05:44 +00:00
wi2.append(x)
if wi2 != []:
if group in ignorelist:
pass
else:
z.append(await imt(wi2))
2020-09-10 14:37:13 +00:00
if str(z):
2020-09-10 14:29:33 +00:00
v = c.join(z)
2020-09-10 14:39:23 +00:00
if v != '':
2020-09-10 14:37:13 +00:00
return 'echo ' + v
2020-08-12 16:01:34 +00:00
async def command(text, group=0):
2020-09-10 14:29:33 +00:00
result = await findcommand(text, group)
c = result
2020-09-10 14:32:02 +00:00
if c != None:
try:
d = result.split(' ')
d = d[0]
except Exception:
d = c
if d == 'echo':
2020-09-19 10:35:13 +00:00
echo = re.sub('echo ', '', c)
2020-09-19 06:21:06 +00:00
if echo != '':
return echo
if d in clist:
2020-09-19 10:30:27 +00:00
k = clist.get(d)
2020-09-23 05:21:34 +00:00
k1 = re.match(r'from (.*) import (.*)\|(.*)', k)
if k1:
2020-09-24 14:09:02 +00:00
cmd = eval(
f'__import__("modules.{k1.group(1)}", fromlist=["{k1.group(1)}"]).{k1.group(2)}().{k1.group(3)}')
2020-09-22 15:44:05 +00:00
if d == c:
return await cmd()
else:
2020-09-24 14:09:02 +00:00
c = re.sub(r'^'+d+' ','',c)
2020-09-22 15:44:05 +00:00
return await cmd(c)
else:
2020-09-23 05:21:34 +00:00
k2 = re.match(r'from (.*) import (.*)', k)
if k2:
cmd = eval(f'__import__("modules.{k2.group(1)}", fromlist=["{k2.group(1)}"]).{k2.group(2)}')
if d == c:
return await cmd()
else:
2020-09-24 14:09:02 +00:00
c = re.sub(r'^' + d + ' ', '', c)
2020-09-23 05:21:34 +00:00
return await cmd(c)
2020-09-22 15:44:05 +00:00
else:
2020-09-23 05:21:34 +00:00
a = __import__('modules.' + k, fromlist=[k])
if d == c:
return await a.main()
else:
2020-09-24 14:09:02 +00:00
c = re.sub(r'^' + d + ' ', '', c)
2020-09-23 05:21:34 +00:00
return await a.main(c)