Bladeren bron

Various Improvements

Convert del tags to ~~
Use usernames rather than nicknames on the matrix side
Attachments use the same prefix as normal messages
Alex Taber 6 jaren geleden
bovenliggende
commit
947b912163
1 gewijzigde bestanden met toevoegingen van 10 en 4 verwijderingen
  1. 10
    4
      app.py

+ 10
- 4
app.py Bestand weergeven

@@ -29,12 +29,17 @@ matrix_room = matrix_client.join_room(matrix_room_id)
29 29
 
30 30
 matrix_file_types = ('m.file', 'm.image', 'm.video', 'm.audio')
31 31
 
32
+def prepare_matrix_client(message):
33
+	attachments = "\n".join([x.url for x in message.attachments])
34
+	content = message.clean_content + ("\n" + attachments if attachments != "" else "")
35
+	return content
36
+
32 37
 @discord_client.event
33 38
 async def on_message(message):
34 39
 	if message.author.discriminator == "0000" or message.channel.id != discord_channel: return
35
-	username = message.author.display_name[:1] + "\u200B" + message.author.display_name[1:]
36
-	attachments = "\n".join([x.url for x in message.attachments])
37
-	matrix_room.send_text("<{}> {}".format(username, message.clean_content + ("\n" + attachments if attachments != "" else "")))
40
+	username = message.author.name[:1] + "\u200B" + message.author.name[1:] + "#" + message.author.discriminator
41
+	content = prepare_matrix_client(message)
42
+	matrix_room.send_text("<{}> {}".format(username, content))
38 43
 
39 44
 def send_webhook(username, avatar_url, content):
40 45
 	data = {'username': username, 'content': content}
@@ -45,6 +50,7 @@ def send_webhook(username, avatar_url, content):
45 50
 def prepare_discord_content(content):
46 51
 	content = content.replace("@everyone", "@\u200Beveryone")
47 52
 	content = content.replace("@here", "@\u200Bhere")
53
+	content = re.sub("</?del>", "~~", content)
48 54
 	mentions = re.findall("(^|\s)(@(\w*))", content)
49 55
 	guild = discord_client.get_channel(discord_channel).guild
50 56
 	for mention in mentions:
@@ -62,7 +68,7 @@ def on_matrix_message(room, event):
62 68
 			content = prepare_discord_content(event['content']['body'])
63 69
 			send_webhook(username, avatar, content)
64 70
 		if event['content']['msgtype'] in matrix_file_types:
65
-			username = "[Matrix] {}".format(user.get_display_name())
71
+			username = "{}{}".format(discord_prefix, user.get_display_name())
66 72
 			avatar = user.get_avatar_url()
67 73
 			content = matrix_homeserver + "/_matrix/media/v1/download/" + event['content']['url'][6:]
68 74
 			send_webhook(username, avatar, content)