Skip to content

Commit

Permalink
fix: add stream to Text backend (#1527)
Browse files Browse the repository at this point in the history
* feat: add send_stream_request stub

* fix: room lookup

* docs: Add fixes to CHANGES
  • Loading branch information
sijis authored Aug 10, 2021
1 parent 41e80cb commit 7ff1e64
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------
Expand Down
36 changes: 34 additions & 2 deletions errbot/backends/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7ff1e64

Please sign in to comment.