d->m handle emojis we don't know about
This commit is contained in:
		| @@ -42,10 +42,9 @@ function getDiscordParseCallbacks(message, useHTML) { | ||||
| 		emoji: node => { | ||||
| 			if (useHTML) { | ||||
| 				const mxc = select("emoji", "mxc_url", "WHERE id = ?").pluck().get(node.id) | ||||
| 				// TODO: upload and register the emoji so it can be added no matter what | ||||
| 				if (mxc) { | ||||
| 					return `<img data-mx-emoticon height="32" src="${mxc}" title=":${node.name}:" alt=":${node.name}:">` | ||||
| 				} else { | ||||
| 				} else { // We shouldn't get here since all emojis should have been added ahead of time in the messageToEvent function. | ||||
| 					return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">` | ||||
| 				} | ||||
| 			} else { | ||||
| @@ -185,6 +184,26 @@ async function messageToEvent(message, guild, options = {}, di) { | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Handling emojis that we don't know about. The emoji has to be present in the DB for it to be picked up in the emoji markdown converter. | ||||
| 		// So we scan the message ahead of time for all its emojis and ensure they are in the DB. | ||||
| 		const emojiMatches = [...content.matchAll(/<(a?):([^:>]{2,20}):([0-9]+)>/g)] | ||||
| 		const emojiDownloads = [] | ||||
| 		for (const match of emojiMatches) { | ||||
| 			const id = match[3] | ||||
| 			const name = match[2] | ||||
| 			const animated = +!!match[1] | ||||
| 			const row = select("emoji", "id", "WHERE id = ?").pluck().get(id) | ||||
| 			if (!row) { | ||||
| 				// The custom emoji is not registered. We will register it and then add it. | ||||
| 				emojiDownloads.push( | ||||
| 					file.uploadDiscordFileToMxc(file.emoji(id, animated)).then(mxc => { | ||||
| 						db.prepare("INSERT OR IGNORE INTO emoji (id, name, animated, mxc_url) VALUES (?, ?, ?, ?)").run(id, name, animated, mxc) | ||||
| 					}) | ||||
| 				) | ||||
| 			} | ||||
| 		} | ||||
| 		await Promise.all(emojiDownloads) | ||||
|  | ||||
| 		// Star * prefix for fallback edits | ||||
| 		if (options.includeEditFallbackStar) { | ||||
| 			body = "* " + body | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Cadence Ember
					Cadence Ember