2020-11-09 20:32:49 +02:00
|
|
|
import os, config
|
|
|
|
|
|
|
|
def getClass(name):
|
|
|
|
str = f'''
|
|
|
|
from Command import Command # import parent class
|
|
|
|
|
|
|
|
class {name} (Command):
|
2021-08-31 22:09:39 +02:00
|
|
|
def start(self, string): # main method
|
2020-11-09 20:32:49 +02:00
|
|
|
pass
|
|
|
|
'''
|
|
|
|
return str.strip()
|
|
|
|
|
|
|
|
def getCommand(name, parent, bg):
|
|
|
|
str = f'''
|
|
|
|
from .{parent} import *
|
2021-02-27 14:21:28 +02:00
|
|
|
from Command import Response
|
2020-11-09 20:32:49 +02:00
|
|
|
################################################################################
|
|
|
|
{f"@{parent}.background(answer = '', voice = '')" if bg else ''}
|
|
|
|
def method(params{', finish_event' if bg else ''}):
|
|
|
|
voice = text = ''
|
|
|
|
{'finish_event.set()' if bg else ''}
|
2021-02-27 14:21:28 +02:00
|
|
|
return Response(text = text, voice = voice)
|
2020-11-09 20:32:49 +02:00
|
|
|
|
|
|
|
keywords = {{}}
|
|
|
|
patterns = []
|
|
|
|
{name} = {parent}('{name}', keywords, patterns)
|
|
|
|
{name}.setStart(method)
|
|
|
|
'''
|
|
|
|
return str.strip()
|
|
|
|
|
|
|
|
def makeModule(name):
|
|
|
|
path = f'{config.path}/{name}'
|
|
|
|
if os.path.isdir(path): return
|
|
|
|
os.mkdir(path)
|
|
|
|
with open(path+'/'+name+'.py', 'w+') as f:
|
|
|
|
f.write(getClass(name))
|
|
|
|
with open(config.path+'/modules.py', 'a+') as f:
|
|
|
|
f.write(f'import {name}\n')
|
|
|
|
|
|
|
|
def makeCommand(name, parent, background):
|
|
|
|
path = f'{config.path}/{parent}/{name}.py'
|
|
|
|
if os.path.exists(path):
|
|
|
|
print(path + ' already exist\n')
|
|
|
|
return
|
|
|
|
with open(path, 'w+') as f:
|
|
|
|
f.write(getCommand(name, parent, background))
|
|
|
|
|
|
|
|
init = f'{config.path}/{parent}/__init__.py'
|
|
|
|
if not os.path.exists(init):
|
|
|
|
with open(init, 'w+'): pass
|
|
|
|
with open(init, 'a+') as f:
|
|
|
|
f.write(f'from .{name} import *\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
num = int(input("\nCreate:\n\t0 - Module\n\t1 - Command\n\t2 - Background Command\n -> "))
|
|
|
|
name = str(input("Name: "))
|
|
|
|
|
|
|
|
if num:
|
|
|
|
parent, name = name.split('.')
|
|
|
|
makeModule(parent)
|
|
|
|
makeCommand(name, parent, num-1)
|
|
|
|
else:
|
|
|
|
makeModule(name)
|