diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-14 19:52:44 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 291ce07645f63614b3b00fbe20063d6ef0161bef (patch) | |
tree | f6b2d0f7412f1f3ac2c02d8c2ab2957d1dc338fa /slack/slack_buffer.py | |
parent | 184bf08360003538179e3c19b2711016c823eadd (diff) | |
download | wee-slack-291ce07645f63614b3b00fbe20063d6ef0161bef.tar.gz |
Support sending messages
Diffstat (limited to 'slack/slack_buffer.py')
-rw-r--r-- | slack/slack_buffer.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py index adad7b7..4fa5981 100644 --- a/slack/slack_buffer.py +++ b/slack/slack_buffer.py @@ -9,12 +9,14 @@ import weechat from slack.shared import shared from slack.slack_message import SlackMessage, SlackTs -from slack.util import get_callback_name +from slack.task import run_async +from slack.util import get_callback_name, htmlescape if TYPE_CHECKING: from typing_extensions import Literal from slack.slack_api import SlackApi + from slack.slack_conversation import SlackConversation from slack.slack_workspace import SlackWorkspace @@ -171,6 +173,11 @@ class SlackBuffer(ABC): @property @abstractmethod + def conversation(self) -> SlackConversation: + raise NotImplementedError() + + @property + @abstractmethod def context(self) -> Literal["conversation", "thread"]: raise NotImplementedError() @@ -304,8 +311,17 @@ class SlackBuffer(ABC): weechat.buffer_set(self.buffer_pointer, "hotlist", "-1") self.hotlist_tss.clear() + @abstractmethod + async def post_message(self, text: str) -> None: + raise NotImplementedError() + + async def process_input(self, input_data: str): + if input_data.startswith(("//", " ")): + input_data = input_data[1:] + await self.post_message(htmlescape(input_data)) + def _buffer_input_cb(self, data: str, buffer: str, input_data: str) -> int: - weechat.prnt(buffer, "Text: %s" % input_data) + run_async(self.process_input(input_data)) return weechat.WEECHAT_RC_OK def _buffer_close_cb(self, data: str, buffer: str) -> int: |