forked from cadence/out-of-your-element
Add new WHERE feature to my funny orm
This commit is contained in:
parent
28abdac5b6
commit
475cd5b724
30 changed files with 149 additions and 105 deletions
|
@ -14,9 +14,9 @@ const emoji = sync.require("../converters/emoji")
|
|||
* @param {Ty.Event.Outer<Ty.Event.M_Reaction>} event
|
||||
*/
|
||||
async function addReaction(event) {
|
||||
const channelID = select("channel_room", "channel_id", "WHERE room_id = ?").pluck().get(event.room_id)
|
||||
const channelID = select("channel_room", "channel_id", {room_id: event.room_id}).pluck().get()
|
||||
if (!channelID) return // We just assume the bridge has already been created
|
||||
const messageID = select("event_message", "message_id", "WHERE event_id = ? AND part = 0").pluck().get(event.content["m.relates_to"].event_id) // 0 = primary
|
||||
const messageID = select("event_message", "message_id", {event_id: event.content["m.relates_to"].event_id, part: 0}).pluck().get() // 0 = primary
|
||||
if (!messageID) return // Nothing can be done if the parent message was never bridged.
|
||||
|
||||
const key = event.content["m.relates_to"].key // TODO: handle custom text or emoji reactions
|
||||
|
|
|
@ -14,7 +14,7 @@ const {discord, db, select} = passthrough
|
|||
*/
|
||||
async function ensureWebhook(channelID, forceCreate = false) {
|
||||
if (!forceCreate) {
|
||||
const row = select("webhook", ["webhook_id", "webhook_token"], "WHERE channel_id = ?").get(channelID)
|
||||
const row = select("webhook", ["webhook_id", "webhook_token"], {channel_id: channelID}).get()
|
||||
if (row) {
|
||||
return {
|
||||
id: row.webhook_id,
|
||||
|
|
|
@ -12,7 +12,7 @@ const utils = sync.require("../converters/utils")
|
|||
* @param {Ty.Event.Outer_M_Room_Redaction} event
|
||||
*/
|
||||
async function deleteMessage(event) {
|
||||
const rows = from("event_message").join("message_channel", "message_id").select("channel_id", "message_id").and("WHERE event_id = ?").all(event.redacts)
|
||||
const rows = from("event_message").join("message_channel", "message_id").select("channel_id", "message_id").where({event_id: event.redacts}).all()
|
||||
for (const row of rows) {
|
||||
discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ async function deleteMessage(event) {
|
|||
*/
|
||||
async function removeReaction(event) {
|
||||
const hash = utils.getEventIDHash(event.redacts)
|
||||
const row = from("reaction").join("message_channel", "message_id").select("channel_id", "message_id", "encoded_emoji").and("WHERE hashed_event_id = ?").get(hash)
|
||||
// TODO: this works but fix the type
|
||||
const row = from("reaction").join("message_channel", "message_id").select("channel_id", "message_id", "encoded_emoji").where({hashed_event_id: hash}).get()
|
||||
if (!row) return
|
||||
await discord.snow.channel.deleteReactionSelf(row.channel_id, row.message_id, row.encoded_emoji)
|
||||
db.prepare("DELETE FROM reaction WHERE hashed_event_id = ?").run(hash)
|
||||
|
|
|
@ -58,7 +58,7 @@ 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) {
|
||||
const row = select("channel_room", ["channel_id", "thread_parent"], "WHERE room_id = ?").get(event.room_id)
|
||||
const row = select("channel_room", ["channel_id", "thread_parent"], {room_id: event.room_id}).get()
|
||||
if (!row) return // allow the bot to exist in unbridged rooms, just don't do anything with it
|
||||
let channelID = row.channel_id
|
||||
let threadID = undefined
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue