diff --git a/README.md b/README.md index efdef84..81d7685 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ If you want the server to load a file (*module*) on startup, add it to the `modu > Adds `/cycler`, swaps the hotbar with inventory when player changes slot from right->left or left->right +* `motd.py` + + > Adds `/getmotd` & `/setmotd` to update the motd on the fly (no reboot). + # Code styleguide & tips diff --git a/helpers.py b/helpers.py index 39f5181..219172e 100644 --- a/helpers.py +++ b/helpers.py @@ -41,8 +41,10 @@ def safetp(player, world, x, y, z, yaw = 0, pitch = 0): else: safetp(player, world, x, y+1, z, yaw, pitch) -def plugHeader(sender, name): - msg(sender, "\n&2--=[ %s ]=--" % name) +def plugHeader(sender=None, name="Redstoner Utils"): + head = "\n&2--=[ %s ]=--" % name + msg(sender, head) + return head def noperm(player): msg(player, "&cno permission") diff --git a/main.py b/main.py index a0d6efb..fe6caad 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,7 @@ def onDisable(): log("Loading RedstonerUtils...") # Import all modules -modules = ["misc", "adminchat", "lagchunks", "reports", "chatgroups", "webtoken", "saylol", "skullclick", "mentio", "cycle"] +modules = ["misc", "adminchat", "lagchunks", "reports", "chatgroups", "webtoken", "saylol", "skullclick", "mentio", "cycle", "motd"] mod = {} for module in modules: try: diff --git a/motd.py b/motd.py new file mode 100644 index 0000000..915fa63 --- /dev/null +++ b/motd.py @@ -0,0 +1,29 @@ +#pylint: disable=F0401 +from helpers import * + +motd = server.getMotd() + +@hook.command("getmotd") +def onGetMotdCommand(sender, args): + plugHeader("MOTD") + msg(sender, motd, usecolor=False) + + +@hook.command("setmotd") +def onSetMotdCommand(sender, args): + global motd + plugHeader("MOTD") + if sender.hasPermission("utils.setmotd"): + if not checkargs(sender, args, 1, -1): + return True + + motd = colorify(" ".join(args)) + broadcast(plugHeader(name="MOTD")) + broadcast("&aNew MOTD:&r\n%s" % motd) + else: + noperm(sender) + return True + +@hook.event("server.ServerListPingEvent") +def onServerPing(event): + event.setMotd(motd) \ No newline at end of file