mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Implement reply_image in Telegram serfs
This commit is contained in:
parent
243c4218bc
commit
6f67d16452
2 changed files with 17 additions and 1 deletions
|
@ -3,6 +3,7 @@ import contextlib
|
|||
import logging
|
||||
import asyncio as aio
|
||||
import royalnet.utils as ru
|
||||
import io
|
||||
from .errors import UnsupportedError
|
||||
from .commandinterface import CommandInterface
|
||||
from royalnet.backpack.tables.aliases import Alias
|
||||
|
@ -51,6 +52,14 @@ class CommandData:
|
|||
text: The text to be sent, possibly formatted in the weird undescribed markup that I'm using."""
|
||||
raise UnsupportedError(f"'{self.reply.__name__}' is not supported")
|
||||
|
||||
async def reply_image(self, image: io.IOBase, caption: str) -> None:
|
||||
"""Send an image (with optionally a caption) to the channel where the call was made.
|
||||
|
||||
Parameters:
|
||||
image: The bytes of the image to send.
|
||||
caption: The caption to attach to the image."""
|
||||
raise UnsupportedError(f"'{self.reply_image.__name__}' is not supported")
|
||||
|
||||
async def get_author(self, error_if_none: bool = False):
|
||||
"""Try to find the identifier of the user that sent the message.
|
||||
That probably means, the database row identifying the user.
|
||||
|
|
|
@ -8,7 +8,7 @@ import royalnet.utils as ru
|
|||
import royalnet.backpack.tables as rbt
|
||||
from .escape import escape
|
||||
from ..serf import Serf
|
||||
|
||||
import io
|
||||
import telegram
|
||||
import urllib3
|
||||
from telegram.utils.request import Request as TRequest
|
||||
|
@ -117,6 +117,13 @@ class TelegramSerf(Serf):
|
|||
parse_mode="HTML",
|
||||
disable_web_page_preview=True)
|
||||
|
||||
async def reply_image(data, image: io.IOBase, caption: str) -> None:
|
||||
await self.api_call(data.message.chat.send_photo,
|
||||
photo=image,
|
||||
caption=escape(caption),
|
||||
parse_mode="HTML",
|
||||
disable_web_page_preview=True)
|
||||
|
||||
async def get_author(data, error_if_none=False):
|
||||
user: Optional[telegram.User] = data.message.from_user
|
||||
if user is None:
|
||||
|
|
Loading…
Reference in a new issue