embed images on Discord
This commit is contained in:
parent
c793120903
commit
1c1bb7de97
1 changed files with 11 additions and 7 deletions
18
main.py
18
main.py
|
@ -124,7 +124,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def webhook_send(self, author, avatar, message,
|
async def webhook_send(self, author, avatar, message,
|
||||||
event_id, channel_id):
|
event_id, channel_id, embed=None):
|
||||||
channel = channel_store[channel_id]
|
channel = channel_store[channel_id]
|
||||||
|
|
||||||
# Create webhook if it doesn't exist
|
# Create webhook if it doesn't exist
|
||||||
|
@ -137,8 +137,10 @@ class MatrixClient(nio.AsyncClient):
|
||||||
# Username must be between 1 and 80 characters in length
|
# Username must be between 1 and 80 characters in length
|
||||||
# 'wait=True' allows us to store the sent message
|
# 'wait=True' allows us to store the sent message
|
||||||
try:
|
try:
|
||||||
hook = await hook.send(username=author[:80], avatar_url=avatar,
|
hook = await hook.send(
|
||||||
content=message, wait=True)
|
username=author[:80], avatar_url=avatar,
|
||||||
|
content=message, embed=embed, wait=True
|
||||||
|
)
|
||||||
message_store[event_id] = hook
|
message_store[event_id] = hook
|
||||||
message_store[hook.id] = event_id
|
message_store[hook.id] = event_id
|
||||||
except discord.errors.HTTPException as e:
|
except discord.errors.HTTPException as e:
|
||||||
|
@ -301,14 +303,16 @@ class Callbacks(object):
|
||||||
|
|
||||||
message = await self.process_message(message, channel_id)
|
message = await self.process_message(message, channel_id)
|
||||||
|
|
||||||
|
embed = None
|
||||||
# Get attachments
|
# Get attachments
|
||||||
try:
|
try:
|
||||||
attachment = event.url.split("/")[-1]
|
attachment = event.url.split("/")[-1]
|
||||||
|
attachment = f"{url}/{homeserver}/{attachment}"
|
||||||
|
|
||||||
# Highlight attachment name
|
embed = discord.Embed(colour=discord.Colour.blue(), title=message)
|
||||||
message = f"`{message}`"
|
embed.set_image(url=attachment)
|
||||||
|
|
||||||
message += f"\n{url}/{homeserver}/{attachment}"
|
message = None
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -321,7 +325,7 @@ class Callbacks(object):
|
||||||
break
|
break
|
||||||
|
|
||||||
await self.matrix_client.webhook_send(
|
await self.matrix_client.webhook_send(
|
||||||
author, avatar, message, event.event_id, channel_id
|
author, avatar, message, event.event_id, channel_id, embed=embed
|
||||||
)
|
)
|
||||||
|
|
||||||
async def redaction_callback(self, room, event):
|
async def redaction_callback(self, room, event):
|
||||||
|
|
Loading…
Reference in a new issue