Alter SQL column names to be distinct

This commit is contained in:
Cadence Ember 2023-10-05 12:32:05 +13:00
parent a49b46381c
commit 28abdac5b6
14 changed files with 40 additions and 25 deletions

View file

@ -22,7 +22,7 @@ async function editToChanges(message, guild, api) {
// Figure out what events we will be replacing
const roomID = select("channel_room", "room_id", "WHERE channel_id = ?").pluck().get(message.channel_id)
let senderMxid = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(message.author.id) || null
let senderMxid = select("sim", "mxid", "WHERE user_id = ?").pluck().get(message.author.id) || null
if (senderMxid) {
const senderIsInRoom = select("sim_member", "mxid", "WHERE room_id = ? AND mxid = ?").get(roomID, senderMxid)
if (!senderIsInRoom) {

View file

@ -35,11 +35,11 @@ const Rlottie = (async () => {
/**
* @param {DiscordTypes.APIStickerItem} stickerItem
* @returns {Promise<{mxc: string, info: typeof INFO}>}
* @returns {Promise<{mxc_url: string, info: typeof INFO}>}
*/
async function convert(stickerItem) {
const existingMxc = select("lottie", "mxc", "WHERE id = ?").pluck().get(stickerItem.id)
if (existingMxc) return {mxc: existingMxc, info: INFO}
const existingMxc = select("lottie", "mxc_url", "WHERE sticker_id = ?").pluck().get(stickerItem.id)
if (existingMxc) return {mxc_url: existingMxc, info: INFO}
const r = await Rlottie
const res = await fetch(file.DISCORD_IMAGES_BASE + file.sticker(stickerItem))
if (res.status !== 200) throw new Error("Sticker data file not found.")
@ -67,8 +67,8 @@ async function convert(stickerItem) {
}
})
assert(root.content_uri)
db.prepare("INSERT INTO lottie (id, mxc) VALUES (?, ?)").run(stickerItem.id, root.content_uri)
return {mxc: root.content_uri, info: INFO}
db.prepare("INSERT INTO lottie (sticker_id, mxc_url) VALUES (?, ?)").run(stickerItem.id, root.content_uri)
return {mxc_url: root.content_uri, info: INFO}
}
module.exports.convert = convert

View file

@ -19,7 +19,7 @@ function getDiscordParseCallbacks(message, useHTML) {
return {
/** @param {{id: string, type: "discordUser"}} node */
user: node => {
const mxid = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(node.id)
const mxid = select("sim", "mxid", "WHERE user_id = ?").pluck().get(node.id)
const username = message.mentions.find(ment => ment.id === node.id)?.username || node.id
if (mxid && useHTML) {
return `<a href="https://matrix.to/#/${mxid}">@${username}</a>`
@ -405,13 +405,13 @@ async function messageToEvent(message, guild, options = {}, di) {
const format = file.stickerFormat.get(stickerItem.format_type)
if (format?.mime === "lottie") {
try {
const {mxc, info} = await lottie.convert(stickerItem)
const {mxc_url, info} = await lottie.convert(stickerItem)
return {
$type: "m.sticker",
"m.mentions": mentions,
body: stickerItem.name,
info,
url: mxc
url: mxc_url
}
} catch (e) {
return {

View file

@ -53,7 +53,7 @@ function userToSimName(user) {
assert.notEqual(user.discriminator, "0000", "cannot create user for a webhook")
// 1. Is sim user already registered?
const existing = select("sim", "sim_name", "WHERE discord_id = ?").pluck().get(user.id)
const existing = select("sim", "sim_name", "WHERE user_id = ?").pluck().get(user.id)
if (existing) return existing
// 2. Register based on username (could be new or old format)