Revamp perform.py (including adding channel-performs)
This commit is contained in:
parent
702f5c5972
commit
a077e086cd
1 changed files with 61 additions and 27 deletions
|
@ -4,35 +4,69 @@
|
||||||
from src import EventManager, ModuleManager, utils
|
from src import EventManager, ModuleManager, utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _execute(self, server):
|
def _execute(self, server, commands, **kwargs):
|
||||||
commands = server.get_setting("perform", [])
|
for command in commands:
|
||||||
for i, command in enumerate(commands):
|
print(command)
|
||||||
command = command.split("%%")
|
server.send_raw(command.format(**kwargs))
|
||||||
for j, part in enumerate(command[:]):
|
|
||||||
command[j] = part.replace("%nick%", server.nickname)
|
|
||||||
command = "%".join(command)
|
|
||||||
server.send_raw(command)
|
|
||||||
|
|
||||||
@utils.hook("received.001", priority=EventManager.PRIORITY_URGENT)
|
@utils.hook("received.001", priority=EventManager.PRIORITY_URGENT)
|
||||||
def on_connect(self, event):
|
def on_connect(self, event):
|
||||||
self._execute(event["server"])
|
commands = event["server"].get_setting("perform", [])
|
||||||
|
self._execute(event["server"], commands, NICK=event["server"].nickname)
|
||||||
|
|
||||||
@utils.hook("received.command.performadd", min_args=1)
|
@utils.hook("self.join", priority=EventManager.PRIORITY_URGENT)
|
||||||
def perform_add(self, event):
|
def on_join(self, event):
|
||||||
"""
|
commands = event["channel"].get_setting("perform", [])
|
||||||
:help: Add command to be executed on connect
|
self._execute(event["server"], commands, NICK=event["server"].nickname,
|
||||||
:usage: <raw command>
|
CHAN=event["channel"].name)
|
||||||
:permission: perform
|
|
||||||
"""
|
|
||||||
perform = event["server"].get_setting("perform", [])
|
|
||||||
perform.append(event["args"])
|
|
||||||
event["server"].set_setting("perform", perform)
|
|
||||||
event["stdout"].write("Added command")
|
|
||||||
|
|
||||||
@utils.hook("received.command.performexecute")
|
def _perform(self, target, args_split):
|
||||||
def perform_execute(self, event):
|
subcommand = args_split[0].lower()
|
||||||
"""
|
current_perform = target.get_setting("perform", [])
|
||||||
:help: Execute all saved commands
|
if subcommand == "list":
|
||||||
:permission: perform
|
return "Configured commands: %s" % ", ".join(current_perform)
|
||||||
"""
|
|
||||||
self._execute(event["server"])
|
message = None
|
||||||
|
if subcommand == "add":
|
||||||
|
if not len(args_split) > 1:
|
||||||
|
raise utils.EventError("Please provide a raw command to add")
|
||||||
|
current_perform.append(" ".join(args_split[1:]))
|
||||||
|
message = "Added command"
|
||||||
|
elif subcommand == "remove":
|
||||||
|
if not len(args_split) > 1:
|
||||||
|
raise utils.EventError("Please provide an index to remove")
|
||||||
|
if not args_split[1].isdigit():
|
||||||
|
raise utils.EventError("Please provide a number")
|
||||||
|
index = int(args_split[1])
|
||||||
|
if not index < len(current_perform):
|
||||||
|
raise utils.EventError("Index out of bounds")
|
||||||
|
current_perform.pop(index)
|
||||||
|
message = "Removed command"
|
||||||
|
else:
|
||||||
|
raise utils.EventError("Unknown subcommand '%s'" % subcommand)
|
||||||
|
|
||||||
|
target.set_setting("perform", current_perform)
|
||||||
|
return message
|
||||||
|
|
||||||
|
@utils.hook("received.command.perform", min_args=1)
|
||||||
|
@utils.kwarg("min_args", 1)
|
||||||
|
@utils.kwarg("help", "Edit on-connect command configuration")
|
||||||
|
@utils.kwarg("usage", "list")
|
||||||
|
@utils.kwarg("usage", "add <raw command>")
|
||||||
|
@utils.kwarg("usage", "remove <index>")
|
||||||
|
@utils.kwarg("permission", "perform")
|
||||||
|
def perform(self, event):
|
||||||
|
event["stdout"].write(self._perform(event["server"],
|
||||||
|
event["args_split"]))
|
||||||
|
|
||||||
|
@utils.hook("received.command.cperform", min_args=1)
|
||||||
|
@utils.kwarg("min_args", 1)
|
||||||
|
@utils.kwarg("channel_only", True)
|
||||||
|
@utils.kwarg("help", "Edit channel on-join command configuration")
|
||||||
|
@utils.kwarg("usage", "list")
|
||||||
|
@utils.kwarg("usage", "add <raw command>")
|
||||||
|
@utils.kwarg("usage", "remove <index>")
|
||||||
|
@utils.kwarg("permission", "cperform")
|
||||||
|
def cperform(self, event):
|
||||||
|
event["stdout"].write(self._perform(event["target"],
|
||||||
|
event["args_split"]))
|
||||||
|
|
Loading…
Reference in a new issue