Pārlūkot izejas kodu

Improve emoji support

Alex Taber 6 gadus atpakaļ
vecāks
revīzija
66aa62a11f
1 mainītis faili ar 12 papildinājumiem un 0 dzēšanām
  1. 12
    0
      app.py

+ 12
- 0
app.py Parādīt failu

@@ -36,13 +36,23 @@ unmatched_messages_cache = {}
36 36
 message_delete_queue = []
37 37
 
38 38
 def prepare_matrix_content(message):
39
+	reg = re.match(r"^<a?:\w+:\d*>$", message.content)
40
+
41
+	if reg:
42
+		try:
43
+			return emoji_urls[message.content]
44
+		except:
45
+			pass
46
+
39 47
 	attachments = "\n".join([x.url for x in message.attachments])
40 48
 	content = message.clean_content + ("\n" + attachments if attachments != "" else "")
49
+	content = re.sub(r"<a?(:\w+:)\d*>", r"\g<1>", content)
41 50
 	return content
42 51
 
43 52
 guild = None
44 53
 channel = None
45 54
 emojis = {}
55
+emoji_urls = {}
46 56
 
47 57
 @discord_client.event
48 58
 async def on_ready():
@@ -55,8 +65,10 @@ async def on_ready():
55 65
 	for emoji in guild.emojis:
56 66
 		if not emoji.animated:
57 67
 			emojis[":{}:".format(emoji.name)] = "<:{}:{}>".format(emoji.name, emoji.id)
68
+			emoji_urls["<:{}:{}>".format(emoji.name, emoji.id)] = emoji.url + "?size=32"
58 69
 		else:
59 70
 			emojis[":{}:".format(emoji.name)] = "<a:{}:{}>".format(emoji.name, emoji.id)
71
+			emoji_urls["<a:{}:{}>".format(emoji.name, emoji.id)] = emoji.url + "?size=32"
60 72
 
61 73
 @discord_client.event
62 74
 async def on_message(message):