Don't delete our reaction on Discord unless we have 0 of that reaction coming from Matrix #85
3 changed files with 16 additions and 1 deletions
|
|
@ -104,6 +104,16 @@ class From {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluckUnsafe(col) {
|
||||||
|
/** @type {Pluck<Table, any>} */
|
||||||
|
// @ts-ignore
|
||||||
|
const r = this
|
||||||
|
r.cols = [col]
|
||||||
|
r.makeColsSafe = false
|
||||||
|
r.isPluck = true
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} sql
|
* @param {string} sql
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -68,3 +68,8 @@ test("orm: select unsafe works (to select complex column names that can't be typ
|
||||||
.all()
|
.all()
|
||||||
t.equal(results[0].power_level, 150)
|
t.equal(results[0].power_level, 150)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("orm: pluck unsafe works (to select complex column names that can't be type verified)", t => {
|
||||||
|
const result = from("channel_room").where({guild_id: "112760669178241024"}).pluckUnsafe("count(*)").get()
|
||||||
|
t.equal(result, 7)
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ async function removeReaction(event) {
|
||||||
.select("reference_channel_id", "message_id", "encoded_emoji").where({hashed_event_id: hash}).get()
|
.select("reference_channel_id", "message_id", "encoded_emoji").where({hashed_event_id: hash}).get()
|
||||||
if (!row) return
|
if (!row) return
|
||||||
// See how many Matrix-side reactions there are, and delete if it's the last one
|
// See how many Matrix-side reactions there are, and delete if it's the last one
|
||||||
const numberOfReactions = from("reaction").selectUnsafe("count(*)").where({message_id: row.message_id, encoded_emoji: row.encoded_emoji}).prepare().pluck().get()
|
const numberOfReactions = from("reaction").where({message_id: row.message_id, encoded_emoji: row.encoded_emoji}).pluckUnsafe("count(*)").get()
|
||||||
if (numberOfReactions === 1) {
|
if (numberOfReactions === 1) {
|
||||||
await discord.snow.channel.deleteReactionSelf(row.reference_channel_id, row.message_id, row.encoded_emoji)
|
await discord.snow.channel.deleteReactionSelf(row.reference_channel_id, row.message_id, row.encoded_emoji)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue