finalise message editing

This commit is contained in:
Cadence Ember 2023-08-29 01:31:52 +12:00
parent 53b5438756
commit 56fe710392
4 changed files with 157 additions and 63 deletions

View file

@ -58,6 +58,20 @@ async function sendMessageWithWebhook(channelID, data, threadID) {
return result
}
/**
* @param {string} channelID
* @param {string} messageID
* @param {DiscordTypes.RESTPatchAPIWebhookWithTokenMessageJSONBody & {files?: {name: string, file: Buffer}[]}} data
* @param {string} [threadID]
*/
async function editMessageWithWebhook(channelID, messageID, data, threadID) {
const result = await withWebhook(channelID, async webhook => {
return discord.snow.webhook.editWebhookMessage(webhook.id, webhook.token, messageID, {...data, thread_id: threadID})
})
return result
}
module.exports.ensureWebhook = ensureWebhook
module.exports.withWebhook = withWebhook
module.exports.sendMessageWithWebhook = sendMessageWithWebhook
module.exports.editMessageWithWebhook = editMessageWithWebhook

View file

@ -34,9 +34,11 @@ async function sendEvent(event) {
/** @type {DiscordTypes.APIMessage[]} */
const messageResponses = []
let eventPart = 0 // 0 is primary, 1 is supporting
// for (const message of messagesToEdit) {
// eventPart = 1
// TODO ...
for (const data of messagesToEdit) {
const messageResponse = await channelWebhook.editMessageWithWebhook(channelID, data.id, data.message, threadID)
eventPart = 1
messageResponses.push(messageResponse)
}
for (const message of messagesToSend) {
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID)
db.prepare("REPLACE INTO message_channel (message_id, channel_id) VALUES (?, ?)").run(messageResponse.id, channelID)