1
Fork 0
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:
Steffo 2020-05-19 17:59:48 +02:00
parent 243c4218bc
commit 6f67d16452
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
2 changed files with 17 additions and 1 deletions

View file

@ -3,6 +3,7 @@ import contextlib
import logging import logging
import asyncio as aio import asyncio as aio
import royalnet.utils as ru import royalnet.utils as ru
import io
from .errors import UnsupportedError from .errors import UnsupportedError
from .commandinterface import CommandInterface from .commandinterface import CommandInterface
from royalnet.backpack.tables.aliases import Alias 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.""" 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") 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): async def get_author(self, error_if_none: bool = False):
"""Try to find the identifier of the user that sent the message. """Try to find the identifier of the user that sent the message.
That probably means, the database row identifying the user. That probably means, the database row identifying the user.

View file

@ -8,7 +8,7 @@ import royalnet.utils as ru
import royalnet.backpack.tables as rbt import royalnet.backpack.tables as rbt
from .escape import escape from .escape import escape
from ..serf import Serf from ..serf import Serf
import io
import telegram import telegram
import urllib3 import urllib3
from telegram.utils.request import Request as TRequest from telegram.utils.request import Request as TRequest
@ -117,6 +117,13 @@ class TelegramSerf(Serf):
parse_mode="HTML", parse_mode="HTML",
disable_web_page_preview=True) 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): async def get_author(data, error_if_none=False):
user: Optional[telegram.User] = data.message.from_user user: Optional[telegram.User] = data.message.from_user
if user is None: if user is None: