Compare commits
No commits in common. "b1d959f944dc686b3204ffe5b01d1ee07bf1bf6c" and "0b5475e9a82cc8c2700516e05f93372bb19ee7b0" have entirely different histories.
b1d959f944
...
0b5475e9a8
3 changed files with 24 additions and 25 deletions
|
@ -60,7 +60,7 @@ test("edit2changes: bot response", async t => {
|
|||
msgtype: "m.text",
|
||||
body: "* :ae_botrac4r: @cadence asked ````, I respond: Stop drinking paint. (No)\n\nHit :bn_re: to reroll.",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '* <img data-mx-emoticon height="32" src="mxc://cadence.moe/skqfuItqxNmBYekzmVKyoLzs" title=":ae_botrac4r:" alt=":ae_botrac4r:"> @cadence asked <code></code>, I respond: Stop drinking paint. (No)<br><br>Hit <img data-mx-emoticon height="32" src="mxc://cadence.moe/OIpqpfxTnHKokcsYqDusxkBT" title=":bn_re:" alt=":bn_re:"> to reroll.',
|
||||
formatted_body: '* <img src="mxc://cadence.moe/551636841284108289" data-mx-emoticon alt=":ae_botrac4r:" title=":ae_botrac4r:" height="24"> @cadence asked <code></code>, I respond: Stop drinking paint. (No)<br><br>Hit <img src="mxc://cadence.moe/362741439211503616" data-mx-emoticon alt=":bn_re:" title=":bn_re:" height="24"> to reroll.',
|
||||
"m.mentions": {
|
||||
// Client-Server API spec 11.37.7: Copy Discord's behaviour by not re-notifying anyone that an *edit occurred*
|
||||
},
|
||||
|
@ -69,7 +69,7 @@ test("edit2changes: bot response", async t => {
|
|||
msgtype: "m.text",
|
||||
body: ":ae_botrac4r: @cadence asked ````, I respond: Stop drinking paint. (No)\n\nHit :bn_re: to reroll.",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<img data-mx-emoticon height="32" src="mxc://cadence.moe/skqfuItqxNmBYekzmVKyoLzs" title=":ae_botrac4r:" alt=":ae_botrac4r:"> @cadence asked <code></code>, I respond: Stop drinking paint. (No)<br><br>Hit <img data-mx-emoticon height="32" src="mxc://cadence.moe/OIpqpfxTnHKokcsYqDusxkBT" title=":bn_re:" alt=":bn_re:"> to reroll.',
|
||||
formatted_body: '<img src="mxc://cadence.moe/551636841284108289" data-mx-emoticon alt=":ae_botrac4r:" title=":ae_botrac4r:" height="24"> @cadence asked <code></code>, I respond: Stop drinking paint. (No)<br><br>Hit <img src="mxc://cadence.moe/362741439211503616" data-mx-emoticon alt=":bn_re:" title=":bn_re:" height="24"> to reroll.',
|
||||
"m.mentions": {
|
||||
// Client-Server API spec 11.37.7: This should contain the mentions for the final version of the event
|
||||
"user_ids": ["@cadence:cadence.moe"]
|
||||
|
|
|
@ -156,30 +156,11 @@ 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)
|
||||
|
||||
let html = markdown.toHTML(content, {
|
||||
discordCallback: getDiscordParseCallbacks(message, true)
|
||||
}, null, null)
|
||||
|
||||
// TODO: add a string return type to my discord-markdown library
|
||||
let body = markdown.toHTML(content, {
|
||||
discordCallback: getDiscordParseCallbacks(message, false),
|
||||
discordOnly: true,
|
||||
|
@ -228,6 +209,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
|
||||
|
|
|
@ -72,9 +72,7 @@ INSERT INTO file (discord_url, mxc_url) VALUES
|
|||
|
||||
INSERT INTO emoji (id, name, animated, mxc_url) VALUES
|
||||
('230201364309868544', 'hippo', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC'),
|
||||
('393635038903926784', 'hipposcope', 1, 'mxc://cadence.moe/WbYqNlACRuicynBfdnPYtmvc'),
|
||||
('362741439211503616', 'bn_re', 0, 'mxc://cadence.moe/OIpqpfxTnHKokcsYqDusxkBT'),
|
||||
('551636841284108289', 'ae_botrac4r', 0, 'mxc://cadence.moe/skqfuItqxNmBYekzmVKyoLzs');
|
||||
('393635038903926784', 'hipposcope', 1, 'mxc://cadence.moe/WbYqNlACRuicynBfdnPYtmvc');
|
||||
|
||||
INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES
|
||||
('!kLRqKKUQXcibIMtOpl:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue