m->d message editing deletion
This commit is contained in:
parent
621a22df01
commit
5bef9ebfe2
2 changed files with 21 additions and 2 deletions
|
@ -71,7 +71,20 @@ async function editMessageWithWebhook(channelID, messageID, data, threadID) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} channelID
|
||||||
|
* @param {string} messageID
|
||||||
|
* @param {string} [threadID]
|
||||||
|
*/
|
||||||
|
async function deleteMessageWithWebhook(channelID, messageID, threadID) {
|
||||||
|
const result = await withWebhook(channelID, async webhook => {
|
||||||
|
return discord.snow.webhook.deleteWebhookMessage(webhook.id, webhook.token, messageID, threadID)
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.ensureWebhook = ensureWebhook
|
module.exports.ensureWebhook = ensureWebhook
|
||||||
module.exports.withWebhook = withWebhook
|
module.exports.withWebhook = withWebhook
|
||||||
module.exports.sendMessageWithWebhook = sendMessageWithWebhook
|
module.exports.sendMessageWithWebhook = sendMessageWithWebhook
|
||||||
module.exports.editMessageWithWebhook = editMessageWithWebhook
|
module.exports.editMessageWithWebhook = editMessageWithWebhook
|
||||||
|
module.exports.deleteMessageWithWebhook = deleteMessageWithWebhook
|
||||||
|
|
|
@ -31,20 +31,26 @@ async function sendEvent(event) {
|
||||||
|
|
||||||
const {messagesToEdit, messagesToSend, messagesToDelete} = await eventToMessage.eventToMessage(event, guild, {api})
|
const {messagesToEdit, messagesToSend, messagesToDelete} = await eventToMessage.eventToMessage(event, guild, {api})
|
||||||
|
|
||||||
|
let eventPart = 0 // 0 is primary, 1 is supporting
|
||||||
|
|
||||||
/** @type {DiscordTypes.APIMessage[]} */
|
/** @type {DiscordTypes.APIMessage[]} */
|
||||||
const messageResponses = []
|
const messageResponses = []
|
||||||
let eventPart = 0 // 0 is primary, 1 is supporting
|
|
||||||
for (const data of messagesToEdit) {
|
for (const data of messagesToEdit) {
|
||||||
const messageResponse = await channelWebhook.editMessageWithWebhook(channelID, data.id, data.message, threadID)
|
const messageResponse = await channelWebhook.editMessageWithWebhook(channelID, data.id, data.message, threadID)
|
||||||
eventPart = 1
|
eventPart = 1
|
||||||
messageResponses.push(messageResponse)
|
messageResponses.push(messageResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const id of messagesToDelete) {
|
||||||
|
await channelWebhook.deleteMessageWithWebhook(channelID, id, threadID)
|
||||||
|
}
|
||||||
|
|
||||||
for (const message of messagesToSend) {
|
for (const message of messagesToSend) {
|
||||||
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID)
|
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID)
|
||||||
db.prepare("REPLACE INTO message_channel (message_id, channel_id) VALUES (?, ?)").run(messageResponse.id, channelID)
|
db.prepare("REPLACE INTO message_channel (message_id, channel_id) VALUES (?, ?)").run(messageResponse.id, channelID)
|
||||||
db.prepare("INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES (?, ?, ?, ?, ?, 0)").run(event.event_id, event.type, event.content.msgtype || null, messageResponse.id, eventPart) // source 0 = matrix
|
db.prepare("INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES (?, ?, ?, ?, ?, 0)").run(event.event_id, event.type, event.content.msgtype || null, messageResponse.id, eventPart) // source 0 = matrix
|
||||||
|
|
||||||
eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting?
|
eventPart = 1
|
||||||
messageResponses.push(messageResponse)
|
messageResponses.push(messageResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue