122 lines
4.9 KiB
Python
122 lines
4.9 KiB
Python
from pathlib import Path
|
|
from os import system
|
|
|
|
import libminecraft
|
|
import libsignal
|
|
import libcommon
|
|
|
|
RetardsServer = libcommon.Group(
|
|
"Retards Server", "5PlbXaPmWZQkhmuyyC/fkWTy8K+BqomjK7byVDyxmpo=")
|
|
|
|
|
|
@libsignal.onMessage(RetardsServer)
|
|
def signalControl(usr: str, msg: str):
|
|
if usr == "Malasaur" and msg.startswith("!"):
|
|
match msg.split():
|
|
|
|
################
|
|
### !modules ###
|
|
################
|
|
|
|
case ["!modules", "list"]:
|
|
available_modules, loaded_modules, unloaded_modules = libcommon.listModules()
|
|
libsignal.sendMessage(
|
|
f"""Available modules: {" ".join(available_modules)}
|
|
Loaded modules: {" ".join(loaded_modules)}
|
|
Unloaded modules: {" ".join(unloaded_modules)}""", RetardsServer
|
|
)
|
|
case ["!modules", "load", *modules]:
|
|
for module in modules:
|
|
try:
|
|
libcommon.loadModule(module)
|
|
libsignal.sendMessage(
|
|
f"'{module}' successfully loaded.", RetardsServer)
|
|
except Exception as e:
|
|
libsignal.sendMessage(
|
|
f"Error loading '{module}': {e}", RetardsServer)
|
|
case ["!modules", "unload", *modules]:
|
|
for module in modules:
|
|
try:
|
|
libcommon.unloadModule(module)
|
|
libsignal.sendMessage(
|
|
f"'{module}' successfully unloaded.", RetardsServer)
|
|
except Exception as e:
|
|
libsignal.sendMessage(
|
|
f"Error unloading '{module}': {e}", RetardsServer)
|
|
case ["!modules", "reload", *modules]:
|
|
for module in modules:
|
|
try:
|
|
libcommon.unloadModule(module)
|
|
libcommon.loadModule(module)
|
|
libsignal.sendMessage(
|
|
f"'{module}' successfully reloaded.", RetardsServer)
|
|
except Exception as e:
|
|
libsignal.sendMessage(
|
|
f"Error reloading '{module}': {e}", RetardsServer)
|
|
case ["!modules", "update"]:
|
|
system("git -C Serve pull")
|
|
log = []
|
|
modules = []
|
|
for file in Path("Serve", "modules").iterdir():
|
|
if file.name[:-3] in libcommon.listModules()[0]:
|
|
if file.read_text() != Path("modules", file.name).read_text():
|
|
log.append(
|
|
f"Module '{file.name[:-3]}' has an available update.")
|
|
else:
|
|
log.append(f"New module added: '{file.name[:-3]}'.")
|
|
modules.append(file.name[:-3])
|
|
for module in libcommon.listModules()[0]:
|
|
if module not in modules:
|
|
log.append(f"Module '{module}' was removed.")
|
|
if not log:
|
|
log.append("Already up to date.")
|
|
libsignal.sendMessage("\n".join(log), RetardsServer)
|
|
case ["!modules", "install"]:
|
|
system("cp Serve/modules/* modules")
|
|
libsignal.sendMessage("Modules installed.", RetardsServer)
|
|
|
|
############
|
|
### !cmd ###
|
|
############
|
|
|
|
case ["!cmd", *cmd]:
|
|
libminecraft.sendCommand(' '.join(cmd))
|
|
|
|
#############
|
|
### !help ###
|
|
#############
|
|
|
|
case ["!help"]:
|
|
log = """Serve - Minecraft/Signal bot.
|
|
|
|
Commands:
|
|
!help [<command>] - Get command help.
|
|
|
|
Admin commands:
|
|
!modules <command> - Manage Serve modules.
|
|
!cmd <command> - Run Minecraft commands."""
|
|
libsignal.sendMessage(log, RetardsServer)
|
|
case ["!help", "modules"]:
|
|
log = """!modules - Manage Serve modules.
|
|
|
|
Admin usage:
|
|
!modules list - List available, loaded and unloaded modules.
|
|
!modules load <module> [<module> [...]] - Load module(s).
|
|
!modules unload <module> [<module> [...]] - Unload module(s).
|
|
!modules reload <module> [<module> [...]] - Reload module(s).
|
|
!modules update - Download modules from remote and list available updates.
|
|
!modules install - Install modules from remote into local directory."""
|
|
libsignal.sendMessage(log, RetardsServer)
|
|
case ["!help", "cmd"]:
|
|
log = """!cmd - Run Minecraft commands.
|
|
|
|
Admin usage:
|
|
!cmd <command> - Run a Minecraft command in the Server."""
|
|
libsignal.sendMessage(log, RetardsServer)
|
|
case ["!help", "help"]:
|
|
log = """!help - Get command help.
|
|
|
|
Usage:
|
|
!help - List available commands.
|
|
!help <command> - Get help about a command."""
|
|
libsignal.sendMessage(log, RetardsServer)
|