1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00

Some images bugfixes

This commit is contained in:
Steffo 2019-04-07 15:48:27 +02:00
parent 7e53864173
commit af3dcb2f7f
2 changed files with 17 additions and 12 deletions

View file

@ -107,10 +107,13 @@ class TelegramBot:
if update.message is None: if update.message is None:
return return
message: telegram.Message = update.message message: telegram.Message = update.message
# Skip no-text messages
if message.text is None:
return
text: str = message.text 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 # Find and clean parameters
command_text, *parameters = text.split(" ") command_text, *parameters = text.split(" ")
command_text.replace(f"@{self.bot.username}", "") command_text.replace(f"@{self.bot.username}", "")

View file

@ -108,6 +108,8 @@ class DiarioCommand(Command):
# Check if there's an image associated with the reply # Check if there's an image associated with the reply
photosizes: typing.Optional[typing.List[telegram.PhotoSize]] = reply.photo photosizes: typing.Optional[typing.List[telegram.PhotoSize]] = reply.photo
if photosizes: if photosizes:
# Text is a caption
text = reply.caption
# Python is doing some weird stuff here, self._telegram_to_imgur appears to be unbound? # Python is doing some weird stuff here, self._telegram_to_imgur appears to be unbound?
# noinspection PyArgumentList # noinspection PyArgumentList
media_url = await self._telegram_to_imgur(self, photosizes, text if text is not None else "") 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() timestamp = datetime.datetime.now()
# Get the message text # Get the message text
raw_text = " ".join(call.args) 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 # Parse the text, if it exists
if raw_text: if raw_text:
# Pass the sentence through the diario regex # Pass the sentence through the diario regex
@ -167,16 +177,8 @@ class DiarioCommand(Command):
quoted_account = None quoted_account = None
spoiler = False spoiler = False
context = None 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 # Ensure there is a text or an image
if not text or media_url: if not (text or media_url):
raise InvalidInputError("Missing text.") raise InvalidInputError("Missing text.")
# Create the diario quote # Create the diario quote
diario = call.alchemy.Diario(creator=creator, diario = call.alchemy.Diario(creator=creator,