bitbot-3.11-fork/modules/ircv3_typing.py

34 lines
1.2 KiB
Python
Raw Normal View History

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
})
def _has_tags(self, server):
return server.has_capability(CAP)
def _expect_output(self, event):
kwarg = event["hook"].get_kwarg("expect_output", None)
return kwarg if not kwarg is None else event["expect_output"]
@utils.hook("preprocess.command")
def preprocess(self, event):
if self._has_tags(event["server"]) and self._expect_output(event):
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"))