feat(music): implement Song Announce Feature

- Extend metadata property in ExtendedGuildQueuePlayerNode type to include lastMessage property.
- Enable music bot to announce the start of a new song by sending a message to the channel.
- Add new event, playerFinish, to fetch and delete the last song-announce message if possible.
- Modify play command to accommodate these changes.
This commit is contained in:
Aaron Sandoval committed 2024-01-15 00:57:46 -07:00
1 parent ce3de4ea2d
commit 99c3cd006f
5 files changed
+94 -15

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
import { randomUUID as uuidv4 } from 'node:crypto';
import loggerModule from '../../services/logger';
import { Track } from 'discord-player';
import { Snowflake } from 'discord.js';
import { Logger } from 'pino';
// Emitted when the audio player finish playing a track.
module.exports = {
name: 'playerFinish',
isDebug: false,
isPlayerEvent: true,
execute: async (queue: ExtendedGuildQueuePlayerNode, track: Track) => {
const executionId: string = uuidv4();
const logger: Logger = loggerModule.child({
module: 'event',
name: 'playerFinish',
executionId: executionId,
shardId: queue.metadata?.client.shard?.ids[0],
guildId: queue.metadata?.channel.guild.id
});
logger.debug(
`playerFinish event: Track [${track.url}] finished playing, deleting previous now-playing message.`
);
const { lastMessage } = queue.metadata || {};
const fetchLastAnnounceMessage =
(await queue.metadata?.channel.messages.fetch(lastMessage?.id as Snowflake)) || undefined;
if (fetchLastAnnounceMessage && fetchLastAnnounceMessage.deletable) {
try {
await fetchLastAnnounceMessage.delete();
} catch (error) {
logger.error(error, 'playerFinish event: Error deleting previous now-playing message.');
}
}
logger.debug('playerFinish event: Previous now-playing message deleted.');
}
};