From 0c4fbf15fe9a0439b9a1611a9311fada83300d7e Mon Sep 17 00:00:00 2001 From: CorwinDev <88144943+CorwinDev@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:50:00 +0100 Subject: [PATCH] Fixed bug with invites & solved bug, DM=crash --- src/bot.js | 11 +++- src/commands/bot/links.js | 6 -- src/commands/developers/args.js | 2 +- src/handlers/functions/inviteTracker.js | 50 ++++++++++----- src/handlers/games/counting.js | 2 +- src/handlers/linkspanel/botInvite.js | 8 +-- src/handlers/linkspanel/botInvite2.js | 72 ---------------------- src/handlers/linkspanel/communityServer.js | 8 +-- src/handlers/linkspanel/supportServer.js | 8 +-- src/handlers/linkspanel/topGG.js | 8 +-- src/handlers/security/antiad.js | 15 ++--- src/handlers/security/blacklist.js | 5 +- src/index.js | 5 +- 13 files changed, 58 insertions(+), 142 deletions(-) delete mode 100644 src/handlers/linkspanel/botInvite2.js diff --git a/src/bot.js b/src/bot.js index 62004d3..8f4b1e7 100644 --- a/src/bot.js +++ b/src/bot.js @@ -169,11 +169,13 @@ process.on('unhandledRejection', error => { username: 'Bot Logs', embeds: [embed], }).catch(() => { + console.log('Error sending unhandledRejection to webhook') console.log(error) }) }); process.on('warning', warn => { + console.warn("Warning:", warn); const embed = new Discord.EmbedBuilder() .setTitle(`πŸš¨γƒ»New warning found`) .addFields([ @@ -187,12 +189,16 @@ process.on('warning', warn => { username: 'Bot Logs', embeds: [embed], }).catch(() => { - + console.log('Error sending warning to webhook') + console.log(warn) }) }); client.on(Discord.ShardEvents.Error, error => { console.log(error) + if (error) if (error.length > 950) error = error.slice(0, 950) + '... view console for details'; + if (error.stack) if (error.stack.length > 950) error.stack = error.stack.slice(0, 950) + '... view console for details'; + if (!error.stack) return const embed = new Discord.EmbedBuilder() .setTitle(`πŸš¨γƒ»A websocket connection encountered an error`) .addFields([ @@ -210,5 +216,4 @@ client.on(Discord.ShardEvents.Error, error => { username: 'Bot Logs', embeds: [embed], }); -}); - +}); \ No newline at end of file diff --git a/src/commands/bot/links.js b/src/commands/bot/links.js index 7702c8a..a9df653 100644 --- a/src/commands/bot/links.js +++ b/src/commands/bot/links.js @@ -19,12 +19,6 @@ module.exports = async (client, interaction, args) => { emoji: "πŸ“¨", value: "invite-linkspanel", }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, { label: `Community Server`, description: `Join the community server!`, diff --git a/src/commands/developers/args.js b/src/commands/developers/args.js index 6b2d4f7..cba50af 100644 --- a/src/commands/developers/args.js +++ b/src/commands/developers/args.js @@ -255,7 +255,7 @@ module.exports = async (client, interaction, args) => { }, { name: `πŸ“¨β”†How do I invite the bots?`, - value: `You can invite the bots by doing \`/invite\` or by clicking on the links below \n\n**Bot** - [Invite here](https://discord.com/oauth2/authorize?&client_id=798144456528363550&scope=applications.commands+bot&permissions=8) \n**Bot 2** - [Invite here](https://discord.com/oauth2/authorize?&client_id=896842236002713673&scope=applications.commands+bot&permissions=8)`, + value: `You can invite the bots by doing \`/invite\` or by clicking on the links below \n\n**Bot** - [Invite here](${client.config.discord.botInvite})`, }, { name: `πŸŽ«β”†How do I get help when needed?`, diff --git a/src/handlers/functions/inviteTracker.js b/src/handlers/functions/inviteTracker.js index db7e827..54c5269 100644 --- a/src/handlers/functions/inviteTracker.js +++ b/src/handlers/functions/inviteTracker.js @@ -16,31 +16,47 @@ module.exports = async (client) => { }) client.once(Discord.Events.ClientReady, async () => { + setTimeout(() => { + try { + client.guilds.cache.forEach(async (guild) => { + if (!guild || !guild.invites) return; + + guild.invites.fetch().then(rawGuildInvites => { + const codeUses = new Map(); + Array.from(rawGuildInvites).forEach(i => { + codeUses.set(i[1].code, i[1].uses); + }) + guildInvites.set(guild.id, codeUses); + }).catch(() => { }); + }); + } catch (e) { } + }, 1000); + }); + + client.on(Discord.Events.GuildCreate, async guild => { try { - const Guilds = client.guilds.cache.map(guild => guild.id); - let i = 0; - let interval = setInterval(async function () { - const guild = await client.guilds.fetch(Guilds[i]).catch(() => { }); - if (!guild || !guild.invites) return i++; + if (!guild || !guild.invites) return; - guild.invites.fetch().then(rawGuildInvites => { - const codeUses = new Map(); - Array.from(rawGuildInvites).forEach(i => { - codeUses.set(i[1].code, i[1].uses); - }) - guildInvites.set(guild.id, codeUses); - }).catch(() => { }); - i++; + guild.invites.fetch().then(rawGuildInvites => { + const codeUses = new Map(); + Array.from(rawGuildInvites).forEach(i => { + codeUses.set(i[1].code, i[1].uses); + }) + guildInvites.set(guild.id, codeUses); + }).catch(() => { }); + } catch (e) { } + }); - if (i === Guilds.size) clearInterval(interval); - }, 1500); + client.on(Discord.Events.GuildDelete, async guild => { + try { + guildInvites.delete(guild.id); } catch (e) { } }); client.on(Discord.Events.GuildMemberAdd, async member => { try { - const cachedInvites = guildInvites.get(member.guild.id) - const newInvites = await member.guild.invites.fetch().catch(() => { console.log}); + const cachedInvites = await guildInvites.get(member.guild.id) + const newInvites = await member.guild.invites.fetch().catch(() => { console.log }); guildInvites.set(member.guild.id, newInvites) diff --git a/src/handlers/games/counting.js b/src/handlers/games/counting.js index b41f0f0..35fbf92 100644 --- a/src/handlers/games/counting.js +++ b/src/handlers/games/counting.js @@ -11,7 +11,7 @@ module.exports = async (client) => { if ( isNaN(message.content) || message.attachments.size > 0 || - message.type == "PINS_ADD" + message.type == Discord.MessageType.ChannelPinnedMessage ) return; diff --git a/src/handlers/linkspanel/botInvite.js b/src/handlers/linkspanel/botInvite.js index 8b9aa3e..4be50e5 100644 --- a/src/handlers/linkspanel/botInvite.js +++ b/src/handlers/linkspanel/botInvite.js @@ -26,12 +26,6 @@ module.exports = async (client) => { emoji: "πŸ“¨", value: "invite-linkspanel", }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, { label: `Community Server`, description: `Join the community server!`, @@ -65,7 +59,7 @@ module.exports = async (client) => { }, interaction.message) } } - }).setMaxListeners(0); + }) } \ No newline at end of file diff --git a/src/handlers/linkspanel/botInvite2.js b/src/handlers/linkspanel/botInvite2.js deleted file mode 100644 index 0df8422..0000000 --- a/src/handlers/linkspanel/botInvite2.js +++ /dev/null @@ -1,72 +0,0 @@ -const Discord = require('discord.js'); - -module.exports = async (client) => { - client.on(Discord.Events.InteractionCreate, async (interaction) => { - if (!interaction.isStringSelectMenu()) return; - - if (interaction.customId == "Bot-linkspanel") { - if (interaction.values == "invite2-linkspanel") { - interaction.deferUpdate(); - - const row2 = new Discord.ActionRowBuilder() - .addComponents( - new Discord.StringSelectMenuBuilder() - .setCustomId('Bot-linkspanel') - .setPlaceholder('βŒβ”†Nothing selected') - .addOptions([ - { - label: `Support server`, - description: `Join the suppport server`, - emoji: "❓", - value: "support-linkspanel", - }, - { - label: `Invite Bot`, - description: `Invite Bot to your server`, - emoji: "πŸ“¨", - value: "invite-linkspanel", - }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, - { - label: `Community Server`, - description: `Join the community server!`, - emoji: "🌍", - value: "community-linkspanel", - }, - { - label: `Top.gg`, - description: `Show the top.gg link`, - emoji: "πŸ“ƒ", - value: "top.gg-linkspanel", - }, - ]), - ); - - let row = new Discord.ActionRowBuilder() - .addComponents( - new Discord.ButtonBuilder() - .setLabel("Bot Invite") - .setURL("https://discord.com/oauth2/authorize?&client_id=896842236002713673&scope=applications.commands+bot&permissions=8") - .setStyle(Discord.ButtonStyle.Link), - ); - - client.embed({ - title: `πŸ“¨γƒ»Bot 2 Invite`, - desc: `Make your voice calls better with Bot 2!`, - image: "https://media.discordapp.net/attachments/843487478881976381/894709307784986684/Bot2_banner_invite.png?width=812&height=238", - url: client.config.discord.serverInvite, - components: [row2, row], - type: 'edit', - color: client.config.colors.error - }, interaction.message) - } - } - }).setMaxListeners(0); -} - - \ No newline at end of file diff --git a/src/handlers/linkspanel/communityServer.js b/src/handlers/linkspanel/communityServer.js index a9e8f5c..603e44a 100644 --- a/src/handlers/linkspanel/communityServer.js +++ b/src/handlers/linkspanel/communityServer.js @@ -26,12 +26,6 @@ module.exports = async (client) => { emoji: "πŸ“¨", value: "invite-linkspanel", }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, { label: `Community Server`, description: `Join the community server!`, @@ -66,7 +60,7 @@ module.exports = async (client) => { }, interaction.message) } } - }).setMaxListeners(0); + }) } \ No newline at end of file diff --git a/src/handlers/linkspanel/supportServer.js b/src/handlers/linkspanel/supportServer.js index 5f3ef4d..0dc8cc4 100644 --- a/src/handlers/linkspanel/supportServer.js +++ b/src/handlers/linkspanel/supportServer.js @@ -26,12 +26,6 @@ module.exports = async (client) => { emoji: "πŸ“¨", value: "invite-linkspanel", }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, { label: `Community Server`, description: `Join the community server!`, @@ -65,7 +59,7 @@ module.exports = async (client) => { }, interaction.message) } } - }).setMaxListeners(0); + }) } \ No newline at end of file diff --git a/src/handlers/linkspanel/topGG.js b/src/handlers/linkspanel/topGG.js index 5eebaf0..5dfb0a9 100644 --- a/src/handlers/linkspanel/topGG.js +++ b/src/handlers/linkspanel/topGG.js @@ -26,12 +26,6 @@ module.exports = async (client) => { emoji: "πŸ“¨", value: "invite-linkspanel", }, - { - label: `Invite Bot 2`, - description: `Invite Bot 2 to your server`, - emoji: "πŸ“•", - value: "invite2-linkspanel", - }, { label: `Community Server`, description: `Join the community server!`, @@ -66,7 +60,7 @@ module.exports = async (client) => { }, interaction.message) } } - }).setMaxListeners(0); + }) } \ No newline at end of file diff --git a/src/handlers/security/antiad.js b/src/handlers/security/antiad.js index ecf2bb0..0cbed48 100644 --- a/src/handlers/security/antiad.js +++ b/src/handlers/security/antiad.js @@ -5,12 +5,11 @@ const Schema2 = require("../../database/models/channelList"); module.exports = (client) => { client.on(Discord.Events.MessageCreate, async (message) => { - if (message.channel.type === Discord.ChannelType.DM) return; - if (message.author.bot) return; + if (message.channel.type === Discord.ChannelType.DM || message.author.bot) return; Schema.findOne({ Guild: message.guild.id }, async (err, data) => { if (data) { if (data.AntiInvite == true) { - const { guild, member, content } = message + const { content } = message const code = content.split('discord.gg/')[1] if (code) { @@ -44,7 +43,7 @@ module.exports = (client) => { } } else if (data.AntiLinks == true) { - const { guild, member, content } = message + const { content } = message if (content.includes('http://') || content.includes('https://') || content.includes('www.')) { Schema2.findOne({ Guild: message.guild.id }, async (err, data2) => { @@ -80,15 +79,13 @@ module.exports = (client) => { }) }).setMaxListeners(0); - client.on('messageUpdate', async (oldMessage, newMessage) => { - if (oldMessage.content === newMessage.content) { - return; - } + client.on(Discord.Events.MessageUpdate, async (oldMessage, newMessage) => { + if (oldMessage.content === newMessage.content || newMessage.channel.type === Discord.ChannelType.DM) return; Schema.findOne({ Guild: newMessage.guild.id }, async (err, data) => { if (data) { if (data.AntiInvite == true) { - const { guild, member, content } = newMessage + const { content } = newMessage const code = content.split('discord.gg/')[1] if (code) { diff --git a/src/handlers/security/blacklist.js b/src/handlers/security/blacklist.js index 5f84664..fd31da7 100644 --- a/src/handlers/security/blacklist.js +++ b/src/handlers/security/blacklist.js @@ -31,10 +31,7 @@ module.exports = async (client) => { }).setMaxListeners(0); client.on(Discord.Events.MessageUpdate, async (oldMessage, newMessage) => { - if (oldMessage.content === newMessage.content) { - return; - } - + if (oldMessage.content === newMessage.content || newMessage.channel.type === Discord.ChannelType.DM) return; try { BlackList.findOne({ Guild: oldMessage.guild.id }, async (err, data) => { if (data) { diff --git a/src/index.js b/src/index.js index a1db2e0..9b059c7 100644 --- a/src/index.js +++ b/src/index.js @@ -173,11 +173,13 @@ process.on('unhandledRejection', error => { username: 'Bot Logs', embeds: [embed], }).catch(() => { + console.log('Error sending unhandled promise rejection to webhook') console.log(error) }) }); process.on('warning', warn => { + console.warn("Warning:", warn); const embed = new Discord.EmbedBuilder() .setTitle(`πŸš¨γƒ»New warning found`) .addFields([ @@ -190,6 +192,7 @@ process.on('warning', warn => { username: 'Bot Logs', embeds: [embed], }).catch(() => { - + console.log('Error sending warning to webhook') + console.log(warn) }) }); \ No newline at end of file