Add support for redacting discord messages
This commit is contained in:
parent
a28deb82f5
commit
9ea7198291
1 changed files with 15 additions and 3 deletions
18
main.py
18
main.py
|
@ -70,12 +70,14 @@ async def on_message(message):
|
||||||
content += f"\n{attachment.url}"
|
content += f"\n{attachment.url}"
|
||||||
|
|
||||||
if str(message.channel.id) == config["channel_id"]:
|
if str(message.channel.id) == config["channel_id"]:
|
||||||
await message_send(content)
|
matrix_message = await message_send(content)
|
||||||
|
message_cache[message.id] = matrix_message
|
||||||
|
|
||||||
|
|
||||||
@discord_client.event
|
@discord_client.event
|
||||||
async def on_message_delete(message):
|
async def on_message_delete(message):
|
||||||
pass
|
if message.id in message_cache:
|
||||||
|
await message_redact(message_cache[message.id])
|
||||||
|
|
||||||
|
|
||||||
@discord_client.event
|
@discord_client.event
|
||||||
|
@ -202,7 +204,7 @@ async def create_matrix_client():
|
||||||
|
|
||||||
|
|
||||||
async def message_send(message):
|
async def message_send(message):
|
||||||
await matrix_client.room_send(
|
message = await matrix_client.room_send(
|
||||||
room_id=config["room_id"],
|
room_id=config["room_id"],
|
||||||
message_type="m.room.message",
|
message_type="m.room.message",
|
||||||
content={
|
content={
|
||||||
|
@ -211,6 +213,16 @@ async def message_send(message):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return message.event_id
|
||||||
|
|
||||||
|
|
||||||
|
async def message_redact(message):
|
||||||
|
await matrix_client.room_redact(
|
||||||
|
room_id=config["room_id"],
|
||||||
|
event_id=message,
|
||||||
|
reason="Message deleted"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def message_callback(room, event):
|
async def message_callback(room, event):
|
||||||
# Don't act on activities in other rooms
|
# Don't act on activities in other rooms
|
||||||
|
|
Loading…
Reference in a new issue