forked from cadence/out-of-your-element
Finish moving from SQL to New Funny ORM
This commit is contained in:
parent
4e1e590c3a
commit
79bd0254f0
19 changed files with 87 additions and 87 deletions
|
@ -4,15 +4,15 @@ const assert = require("assert").strict
|
|||
const Ty = require("../../types")
|
||||
|
||||
const passthrough = require("../../passthrough")
|
||||
const { discord, sync, db } = passthrough
|
||||
const {discord, sync, db, select} = passthrough
|
||||
|
||||
/**
|
||||
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>} event
|
||||
*/
|
||||
async function addReaction(event) {
|
||||
const channelID = db.prepare("SELECT channel_id FROM channel_room WHERE room_id = ?").pluck().get(event.room_id)
|
||||
const channelID = select("channel_room", "channel_id", "WHERE room_id = ?").pluck().get(event.room_id)
|
||||
if (!channelID) return // We just assume the bridge has already been created
|
||||
const messageID = db.prepare("SELECT message_id FROM event_message WHERE event_id = ? AND part = 0").pluck().get(event.content["m.relates_to"].event_id) // 0 = primary
|
||||
const messageID = select("event_message", "message_id", "WHERE event_id = ? AND part = 0").pluck().get(event.content["m.relates_to"].event_id) // 0 = primary
|
||||
if (!messageID) return // Nothing can be done if the parent message was never bridged.
|
||||
|
||||
// no need to sync the matrix member to the other side. but if I did need to, this is where I'd do it
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const assert = require("assert").strict
|
||||
const DiscordTypes = require("discord-api-types/v10")
|
||||
const passthrough = require("../../passthrough")
|
||||
const {discord, db} = passthrough
|
||||
const {discord, db, select} = passthrough
|
||||
|
||||
/**
|
||||
* Look in the database to find webhook credentials for a channel.
|
||||
|
@ -14,10 +14,13 @@ const {discord, db} = passthrough
|
|||
*/
|
||||
async function ensureWebhook(channelID, forceCreate = false) {
|
||||
if (!forceCreate) {
|
||||
/** @type {{id: string, token: string} | null} */
|
||||
const row = db.prepare("SELECT webhook_id as id, webhook_token as token FROM webhook WHERE channel_id = ?").get(channelID)
|
||||
const row = select("webhook", ["webhook_id", "webhook_token"], "WHERE channel_id = ?").get(channelID)
|
||||
if (row) {
|
||||
return {created: false, ...row}
|
||||
return {
|
||||
id: row.webhook_id,
|
||||
token: row.webhook_token,
|
||||
created: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ const {promisify} = require("util")
|
|||
const Ty = require("../../types")
|
||||
const DiscordTypes = require("discord-api-types/v10")
|
||||
const passthrough = require("../../passthrough")
|
||||
const {sync, discord, db} = passthrough
|
||||
const {sync, discord, db, select} = passthrough
|
||||
|
||||
/** @type {import("./channel-webhook")} */
|
||||
const channelWebhook = sync.require("./channel-webhook")
|
||||
|
@ -53,7 +53,8 @@ async function resolvePendingFiles(message) {
|
|||
/** @param {Ty.Event.Outer_M_Room_Message | Ty.Event.Outer_M_Room_Message_File | Ty.Event.Outer_M_Sticker} event */
|
||||
async function sendEvent(event) {
|
||||
// TODO: we just assume the bridge has already been created, is that really ok?
|
||||
const row = db.prepare("SELECT channel_id, thread_parent FROM channel_room WHERE room_id = ?").get(event.room_id)
|
||||
const row = select("channel_room", ["channel_id", "thread_parent"], "WHERE room_id = ?").get(event.room_id)
|
||||
assert(row)
|
||||
let channelID = row.channel_id
|
||||
let threadID = undefined
|
||||
if (row.thread_parent) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue