Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add stream to Text backend #1527

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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