Fixed Invite Accordion
This commit is contained in:
49
discord-bot/events/inviteCreate.js
Normal file
49
discord-bot/events/inviteCreate.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const api = require('../api');
|
||||
|
||||
module.exports = {
|
||||
name: 'inviteCreate',
|
||||
async execute(invite) {
|
||||
try {
|
||||
// Only track invites created by the bot or in channels the bot can access
|
||||
const guildId = invite.guild.id;
|
||||
|
||||
// Check if this invite was created by our bot
|
||||
const isBotCreated = invite.inviter && invite.inviter.id === invite.client.user.id;
|
||||
|
||||
if (isBotCreated) {
|
||||
// Add to database if created by bot
|
||||
const inviteData = {
|
||||
code: invite.code,
|
||||
guildId: guildId,
|
||||
url: invite.url,
|
||||
channelId: invite.channel.id,
|
||||
createdAt: invite.createdAt ? invite.createdAt.toISOString() : new Date().toISOString(),
|
||||
maxUses: invite.maxUses || 0,
|
||||
maxAge: invite.maxAge || 0,
|
||||
temporary: invite.temporary || false
|
||||
};
|
||||
|
||||
// Use the API to add the invite to database
|
||||
await api.addInvite(inviteData);
|
||||
|
||||
// Publish SSE event for real-time frontend updates
|
||||
const bot = require('..');
|
||||
if (bot && bot.publishEvent) {
|
||||
bot.publishEvent(guildId, 'inviteCreated', {
|
||||
code: invite.code,
|
||||
url: invite.url,
|
||||
channelId: invite.channel.id,
|
||||
maxUses: invite.maxUses || 0,
|
||||
maxAge: invite.maxAge || 0,
|
||||
temporary: invite.temporary || false,
|
||||
createdAt: invite.createdAt ? invite.createdAt.toISOString() : new Date().toISOString()
|
||||
});
|
||||
}
|
||||
}
|
||||
// Note: We don't automatically add invites created by other users to avoid spam
|
||||
// Only bot-created invites are tracked for the web interface
|
||||
} catch (error) {
|
||||
console.error('Error handling inviteCreate:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user