Compare commits

...

2 Commits

Author SHA1 Message Date
semantic-release-bot
33ba5b1f61 chore(release): 1.1.0 [skip ci]
# @revanced/discord-bot [1.1.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.4...@revanced/discord-bot@1.1.0) (2025-04-14)

### Features

* **bots/discord:** delete and send sticky msg concurrently, add more logging ([247a00f](247a00f57f))
2025-04-14 14:01:23 +00:00
PalmDevs
247a00f57f feat(bots/discord): delete and send sticky msg concurrently, add more logging 2025-04-14 21:00:24 +07:00
3 changed files with 46 additions and 33 deletions

View File

@@ -1,3 +1,10 @@
# @revanced/discord-bot [1.1.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.4...@revanced/discord-bot@1.1.0) (2025-04-14)
### Features
* **bots/discord:** delete and send sticky msg concurrently, add more logging ([247a00f](https://github.com/revanced/revanced-bots/commit/247a00f57fc2a45fe828cc41e6f0e38e67e83a20))
## @revanced/discord-bot [1.0.4](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.3...@revanced/discord-bot@1.0.4) (2025-04-14)

View File

@@ -2,7 +2,7 @@
"name": "@revanced/discord-bot",
"type": "module",
"private": true,
"version": "1.0.4",
"version": "1.1.0",
"description": "🤖 Discord bot assisting ReVanced",
"main": "src/index.ts",
"scripts": {

View File

@@ -16,47 +16,53 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
`Channel ${channelId} in guild ${guildId} is not a text channel, sticky messages will not be sent`,
)
const send = async () => {
const store = discord.stickyMessages[guildId]![channelId]
if (!store) return
try {
const oldMsg = store.currentMessage
store.currentMessage = await channel.send({
...message,
embeds: message.embeds?.map(it => applyCommonEmbedStyles(it, true, true, true)),
})
await oldMsg?.delete()
} catch (e) {
logger.error(
`Error while sending sticky message to channel ${channelId} in guild ${guildId}:`,
e,
)
} finally {
// Clear any remaining timers
clearTimeout(store.timer)
clearTimeout(store.forceTimer)
store.forceTimerActive = store.timerActive = false
logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)
}
}
// Set up the store
discord.stickyMessages[guildId]![channelId] = {
// biome-ignore lint/suspicious/noAssignInExpressions: don't care
const store = (discord.stickyMessages[guildId]![channelId] = {
forceTimerActive: false,
timerActive: false,
forceTimerMs: forceSendTimeout,
timerMs: timeout,
send,
async send() {
try {
await Promise.all([
channel
.send({
...message,
embeds: message.embeds?.map(it => applyCommonEmbedStyles(it, true, true, true)),
})
.then(msg => {
this.currentMessage = msg
logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)
}),
this.currentMessage
?.delete()
?.then(() =>
logger.debug(
`Deleted old sticky message from channel ${channelId} in guild ${guildId}`,
),
),
])
} catch (e) {
logger.error(
`Error while managing sticky message of channel ${channelId} in guild ${guildId}:`,
e,
)
} finally {
// Clear any remaining timers
clearTimeout(this.timer)
clearTimeout(this.forceTimer)
this.forceTimerActive = this.timerActive = false
logger.debug(`Cleared sticky message timer for channel ${channelId} in guild ${guildId}`)
}
},
// If the store exists before the configuration refresh, take its current message
currentMessage: oldStore?.[channelId]?.currentMessage,
}
})
// Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
await send()
await store.send()
}
}
})