aboutsummaryrefslogtreecommitdiff
path: root/modules/commands
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-28 10:56:33 +0000
committerGravatar jesopo2019-10-28 10:56:33 +0000
commit7ee65f8f8ca9da93174284450db891346ea9daaf (patch)
treeef74117b4262d1f5a4e18f6d568b5ef8d13aeb14 /modules/commands
parentRevert "remove unneeded import" (diff)
signature
remove src/utils/irc/protocol.py
Diffstat (limited to 'modules/commands')
-rw-r--r--modules/commands/__init__.py13
-rw-r--r--modules/commands/outs.py18
2 files changed, 18 insertions, 13 deletions
diff --git a/modules/commands/__init__.py b/modules/commands/__init__.py
index 9b104325..8cf56aa4 100644
--- a/modules/commands/__init__.py
+++ b/modules/commands/__init__.py
@@ -2,7 +2,7 @@
#--depends-on permissions
import re, string, traceback, typing
-from src import EventManager, ModuleManager, utils
+from src import EventManager, IRCLine, ModuleManager, utils
from . import outs
COMMAND_METHOD = "command-method"
@@ -172,6 +172,9 @@ class Module(ModuleManager.BaseModule):
if not is_success:
raise utils.EventError(message)
+ def _tagmsg(self, target, tags):
+ return IRCLine.ParsedLine("TAGMSG", [target], tags=tags)
+
def command(self, server, target, target_str, is_channel, user, command,
args_split, tags, hook, **kwargs):
message_tags = server.has_capability(MESSAGE_TAGS_CAP)
@@ -188,8 +191,8 @@ class Module(ModuleManager.BaseModule):
send_tags["+draft/reply"] = msgid
if expect_output:
- server.send(utils.irc.protocol.tagmsg(target_str,
- {"+draft/typing": "active"}), immediate=True)
+ line = self._tagmsg(target_str, {"+draft/typing": "active"})
+ server.send(line, immediate=True)
stdout = outs.StdOut(server, module_name, target, target_str, send_tags)
stderr = outs.StdErr(server, module_name, target, target_str, send_tags)
@@ -238,8 +241,8 @@ class Module(ModuleManager.BaseModule):
ret = new_event.eaten
if expect_output and message_tags and not has_out:
- server.send(utils.irc.protocol.tagmsg(target_str,
- {"+draft/typing": "done"}), immediate=True)
+ line = self._tagmsg(target_str, {"+draft/typing": "done"})
+ server.send(line, immediate=True)
return ret
diff --git a/modules/commands/outs.py b/modules/commands/outs.py
index 9098df63..0fd8db7d 100644
--- a/modules/commands/outs.py
+++ b/modules/commands/outs.py
@@ -6,6 +6,14 @@ STR_MORE_LEN = len(STR_MORE.encode("utf8"))
STR_CONTINUED = "(...continued) "
WORD_BOUNDARY = ' '
+def _mesage_factory(command):
+ if not command in ["PRIVMSG", "NOTICE"]:
+ raise ValueError("Unknown command method '%s'" % method)
+
+ def _(target, message):
+ return IRCLine.ParsedLine(command, [target, message])
+ return _
+
class Out(object):
def __init__(self, server, module_name, target, target_str, tags):
self.server = server
@@ -39,15 +47,9 @@ class Out(object):
text = text.replace("\n\n", "\n")
full_text = "%s%s" % (prefix, text)
- line_factory = None
- if method == "PRIVMSG":
- line_factory = utils.irc.protocol.privmsg
- elif method == "NOTICE":
- line_factory = utils.irc.protocol.notice
- else:
- raise ValueError("Unknown command method '%s'" % method)
+ message_factory = _mess_factory(method)
- line = line_factory(self._target_str, full_text, tags=self._tags)
+ line = message_factory(self._target_str, full_text, tags=self._tags)
if self._assured:
line.assure()