diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 797feef0..db75f204 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -107,10 +107,13 @@ class TelegramBot: if update.message is None: return message: telegram.Message = update.message - # Skip no-text messages - if message.text is None: - return text: str = message.text + # Try getting the caption instead + if text is None: + text: str = message.caption + # No text or caption, ignore the message + if text is None: + return # Find and clean parameters command_text, *parameters = text.split(" ") command_text.replace(f"@{self.bot.username}", "") diff --git a/royalnet/commands/diario.py b/royalnet/commands/diario.py index f39d8140..56ee64ac 100644 --- a/royalnet/commands/diario.py +++ b/royalnet/commands/diario.py @@ -108,6 +108,8 @@ class DiarioCommand(Command): # Check if there's an image associated with the reply photosizes: typing.Optional[typing.List[telegram.PhotoSize]] = reply.photo if photosizes: + # Text is a caption + text = reply.caption # Python is doing some weird stuff here, self._telegram_to_imgur appears to be unbound? # noinspection PyArgumentList media_url = await self._telegram_to_imgur(self, photosizes, text if text is not None else "") @@ -132,6 +134,14 @@ class DiarioCommand(Command): timestamp = datetime.datetime.now() # Get the message text raw_text = " ".join(call.args) + # Check if there's an image associated with the reply + photosizes: typing.Optional[typing.List[telegram.PhotoSize]] = message.photo + if photosizes: + # Python is doing some weird stuff here, self._telegram_to_imgur appears to be unbound? + # noinspection PyArgumentList + media_url = await self._telegram_to_imgur(self, photosizes, raw_text if raw_text is not None else "") + else: + media_url = None # Parse the text, if it exists if raw_text: # Pass the sentence through the diario regex @@ -167,16 +177,8 @@ class DiarioCommand(Command): quoted_account = None spoiler = False context = None - # Check if there's an image associated with the reply - photosizes: typing.Optional[typing.List[telegram.PhotoSize]] = message.photo - if photosizes: - # Python is doing some weird stuff here, self._telegram_to_imgur appears to be unbound? - # noinspection PyArgumentList - media_url = await self._telegram_to_imgur(self, photosizes, text if text is not None else "") - else: - media_url = None # Ensure there is a text or an image - if not text or media_url: + if not (text or media_url): raise InvalidInputError("Missing text.") # Create the diario quote diario = call.alchemy.Diario(creator=creator,