Compare commits

...

3 Commits

Author SHA1 Message Date
6ded01b046 handle message/channel deletion 2024-02-07 21:02:37 +01:00
3339d7a244 initialize deletion events 2024-02-07 20:27:16 +01:00
0ffb68fd96 prepare for better event grouping 2024-02-07 20:26:57 +01:00
5 changed files with 32 additions and 1 deletions

View File

@ -11,10 +11,13 @@ const sequelize = new Sequelize({
dialect: 'sqlite', dialect: 'sqlite',
logging: false logging: false
}); });
const RoleEmojiPair = defineRoleEmojiPair(sequelize); const RoleEmojiPair = defineRoleEmojiPair(sequelize);
const VoiceChannel = defineVoiceChannel(sequelize); const VoiceChannel = defineVoiceChannel(sequelize);
const Message = defineMessage(sequelize); const Message = defineMessage(sequelize);
Message.hasMany(RoleEmojiPair, { foreignKey: 'message', onDelete: 'CASCADE' });
sequelize.sync(); sequelize.sync();
export { sequelize, RoleEmojiPair, VoiceChannel, Message }; export { sequelize, RoleEmojiPair, VoiceChannel, Message };

View File

@ -0,0 +1,14 @@
import { Events } from 'discord.js';
import { VoiceChannel } from '../../database.js';
export const name = Events.ChannelDelete;
export async function execute(channel) {
// Delete channel entry once channel is deleted itself
const count = await VoiceChannel.destroy({
where: {
id: channel.id
}
});
if (count > 0)
console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`);
}

View File

@ -0,0 +1,14 @@
import { Events } from 'discord.js';
import { Message } from '../../database.js';
export const name = Events.MessageDelete;
export async function execute(message) {
// Delete message entry once message is deleted itself
const count = await Message.destroy({
where: {
id: message.id
}
});
if (count > 0)
console.info(`[INFO] Reaction Roles Message with ID '${message.id}' was deleted.`);
}