From 7ff1e6464d7fe75004e607970a4342c0b47f88c9 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Mon, 9 Aug 2021 22:18:48 -0500 Subject: [PATCH] fix: add stream to Text backend (#1527) * feat: add send_stream_request stub * fix: room lookup * docs: Add fixes to CHANGES --- CHANGES.rst | 1 + errbot/backends/text.py | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ea8b0c21a..229f4be25 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,7 @@ fixes: - core/plugins: cascade dependency plugins (#1519) - core/plugins: reload all repo plugins when updating a repo (#1521) - plugin_manager: correct syntax error (#1524) +- backend/text: add stub send_stream_request method (#1527) v6.1.8 (2021-06-21) ------------------- diff --git a/errbot/backends/text.py b/errbot/backends/text.py index 8ef565429..6582f2d9f 100644 --- a/errbot/backends/text.py +++ b/errbot/backends/text.py @@ -3,6 +3,7 @@ import re import sys from time import sleep +from typing import BinaryIO from ansi.color import fg, fx from markdown import Markdown @@ -14,11 +15,13 @@ from errbot.backends.base import ( OFFLINE, ONLINE, + Identifier, Message, Person, Presence, Room, RoomOccupant, + Stream, ) from errbot.core import ErrBot from errbot.logs import console_hdlr @@ -279,8 +282,8 @@ def serve_forever(self): while True: if self._inroom: - frm = TextOccupant(self.user, self.rooms[0]) - to = self.rooms[0] + frm = TextOccupant(self.user, self.rooms()[0]) + to = self.rooms()[0] else: frm = self.user to = self.bot_identifier @@ -439,3 +442,32 @@ def rooms(self): def prefix_groupchat_reply(self, message, identifier): message.body = f"{identifier.person} {message.body}" + + def send_stream_request( + self, + user: Identifier, + fsource: BinaryIO, + name: str = None, + size: int = None, + stream_type: str = None, + ) -> Stream: + """ + Starts a file transfer. For Slack, the size and stream_type are unsupported + + :param user: is the identifier of the person you want to send it to. + :param fsource: is a file object you want to send. + :param name: is an optional filename for it. + :param size: not supported in Slack backend + :param stream_type: not supported in Slack backend + + :return Stream: object on which you can monitor the progress of it. + """ + stream = Stream(user, fsource, name, size, stream_type) + log.debug( + "Requesting upload of %s to %s (size hint: %d, stream type: %s).", + stream.name, + stream.identifier, + size, + stream_type, + ) + return stream