2019-11-22 16:23:30 +00:00
|
|
|
from src import IRCLine, ModuleManager, utils
|
|
|
|
|
|
|
|
CAP = utils.irc.Capability("message-tags", "draft/message-tags-0.2")
|
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
def _tagmsg(self, target, state):
|
|
|
|
return IRCLine.ParsedLine("TAGMSG", [target],
|
2020-05-20 15:36:40 +00:00
|
|
|
tags={
|
|
|
|
"+typing": state,
|
|
|
|
"+draft/typing": state
|
|
|
|
})
|
2019-11-22 16:23:30 +00:00
|
|
|
def _has_tags(self, server):
|
|
|
|
return server.has_capability(CAP)
|
|
|
|
|
2020-01-11 19:10:05 +00:00
|
|
|
def _expect_output(self, event):
|
|
|
|
kwarg = event["hook"].get_kwarg("expect_output", None)
|
|
|
|
return kwarg if not kwarg is None else event["expect_output"]
|
|
|
|
|
2019-11-22 16:23:30 +00:00
|
|
|
@utils.hook("preprocess.command")
|
|
|
|
def preprocess(self, event):
|
2020-01-11 19:10:05 +00:00
|
|
|
if self._has_tags(event["server"]) and self._expect_output(event):
|
2019-11-22 16:23:30 +00:00
|
|
|
event["target"]._typing = True
|
|
|
|
event["server"].send(self._tagmsg(event["target_str"], "active"),
|
|
|
|
immediate=True)
|
|
|
|
else:
|
|
|
|
event["target"]._typing = False
|
|
|
|
|
|
|
|
@utils.hook("postprocess.command")
|
|
|
|
def postprocess(self, event):
|
|
|
|
if (event["target"]._typing and
|
|
|
|
not event["stdout"].has_text() and
|
|
|
|
not event["stderr"].has_text()):
|
|
|
|
event["server"].send(self._tagmsg(event["target_str"], "done"))
|