Simplify modules/line_handler.handle
This commit is contained in:
parent
59a5d1283a
commit
e27c0e0a0c
1 changed files with 25 additions and 39 deletions
|
@ -23,55 +23,41 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
if line[0] == "@":
|
if line[0] == "@":
|
||||||
tags_prefix, line = line[1:].split(" ", 1)
|
tags_prefix, line = line[1:].split(" ", 1)
|
||||||
for tag in tags_prefix.split(";"):
|
for tag in filter(None, tags_prefix.split(";")):
|
||||||
if tag:
|
tag, _, value = tag.partition("=")
|
||||||
tag_split = tag.split("=", 1)
|
tags[tag] = value
|
||||||
tags[tag_split[0]] = "".join(tag_split[1:])
|
|
||||||
if "batch" in tags and tags["batch"] in event["server"].batches:
|
if "batch" in tags and tags["batch"] in event["server"].batches:
|
||||||
server.batches[tag["batch"]].append(line)
|
server.batches[tag["batch"]].append(line)
|
||||||
return
|
return
|
||||||
|
|
||||||
arbitrary = None
|
line, _, arbitrary = line.partition(" :")
|
||||||
if " :" in line:
|
arbitrary = arbitrary or None
|
||||||
line, arbitrary = line.split(" :", 1)
|
|
||||||
if line.endswith(" "):
|
|
||||||
line = line[:-1]
|
|
||||||
if line[0] == ":":
|
|
||||||
prefix, command = line[1:].split(" ", 1)
|
|
||||||
prefix = Utils.seperate_hostmask(prefix)
|
|
||||||
if " " in command:
|
|
||||||
command, line = command.split(" ", 1)
|
|
||||||
else:
|
|
||||||
line = ""
|
|
||||||
else:
|
|
||||||
command = line
|
|
||||||
if " " in line:
|
|
||||||
command, line = line.split(" ", 1)
|
|
||||||
args = line.split(" ")
|
|
||||||
|
|
||||||
hooks = self.events.on("raw").on(command).get_hooks()
|
if line[0] == ":":
|
||||||
default_event = False
|
prefix, line = line[1:].split(" ", 1)
|
||||||
for hook in hooks:
|
prefix = Utils.seperate_hostmask(prefix)
|
||||||
if hook.kwargs.get("default_event", False):
|
command, _, line = line.partition(" ")
|
||||||
default_event = True
|
|
||||||
break
|
args = line.split(" ")
|
||||||
last = arbitrary or args[-1]
|
last = arbitrary or args[-1]
|
||||||
|
|
||||||
#server, prefix, command, args, arbitrary
|
hooks = self.events.on("raw").on(command).get_hooks()
|
||||||
self.events.on("raw").on(command).call(server=event["server"],
|
default_events = []
|
||||||
last=last, prefix=prefix, args=args, arbitrary=arbitrary,
|
for hook in hooks:
|
||||||
tags=tags)
|
default_events.append(hook.kwargs.get("default_event", False))
|
||||||
|
default_event = any(default_events)
|
||||||
|
|
||||||
|
kwargs = {"last": last, "args": args, "arbitrary": arbitrary,
|
||||||
|
"tags": tags, "last": last, "server": event["server"],
|
||||||
|
"prefix": prefix}
|
||||||
|
|
||||||
|
self.events.on("raw").on(command).call(**kwargs)
|
||||||
if default_event or not hooks:
|
if default_event or not hooks:
|
||||||
if command.isdigit():
|
if command.isdigit():
|
||||||
self.events.on("received.numeric").on(command).call(
|
self.events.on("received.numeric").on(command).call(**kwargs)
|
||||||
line=original_line, server=event["server"], tags=tags,
|
|
||||||
last=last, line_split=original_line.split(" "),
|
|
||||||
number=command)
|
|
||||||
else:
|
else:
|
||||||
self.events.on("received").on(command).call(
|
self.events.on("received").on(command).call(**kwargs)
|
||||||
line=original_line, line_split=original_line.split(" "),
|
|
||||||
command=command, server=event["server"], tags=tags,
|
|
||||||
last=last)
|
|
||||||
|
|
||||||
# ping from the server
|
# ping from the server
|
||||||
@Utils.hook("raw.ping")
|
@Utils.hook("raw.ping")
|
||||||
|
|
Loading…
Reference in a new issue