Separate out everything into files and implement a modules system to segment commands
This commit is contained in:
15
utils/loaders/command_loader.py
Normal file
15
utils/loaders/command_loader.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from os import listdir
|
||||
from core.main import *
|
||||
from utils.logging.log import *
|
||||
import commands
|
||||
|
||||
def loadCommands(func):
|
||||
for filename in listdir('commands'):
|
||||
if filename.endswith('.py') and filename != "__init__.py":
|
||||
commandName = filename[0:-3]
|
||||
className = commandName.capitalize()
|
||||
#try:
|
||||
__import__('commands.%s' % commandName)
|
||||
eval('commands.%s.%s(func)' % (commandName, className))
|
||||
#except Exception as err:
|
||||
# error("Exception while loading command %s:\n%s" % (commandName, err))
|
||||
@@ -9,4 +9,3 @@ def warn(data):
|
||||
|
||||
def error(data):
|
||||
print("[ERROR]", data)
|
||||
exit(1)
|
||||
|
||||
26
utils/logging/send.py
Normal file
26
utils/logging/send.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from core.main import connections, help
|
||||
|
||||
def sendData(addr, data):
|
||||
connections[addr].send(data)
|
||||
|
||||
def sendSuccess(addr, data):
|
||||
sendData(addr, "[y] " + data)
|
||||
|
||||
def sendFailure(addr, data):
|
||||
sendData(addr, "[n] " + data)
|
||||
|
||||
def sendInfo(addr, data):
|
||||
sendData(addr, "[i] " + data)
|
||||
|
||||
def sendAll(data):
|
||||
for i in connections:
|
||||
connections[i].send(data)
|
||||
return
|
||||
|
||||
def incorrectUsage(addr, mode):
|
||||
if mode == None:
|
||||
sendFailure(addr, "Incorrect usage")
|
||||
return
|
||||
if mode in help.keys():
|
||||
sendFailure(addr, "Usage: " + help[mode])
|
||||
return
|
||||
Reference in New Issue
Block a user