From d15b619b2454598d3371a408ef7fd9475ab83128 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 14 Jun 2026 12:55:42 -0600 Subject: [PATCH] Ok, ppl can buy numbers now, good --- index.js | 80 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 3982472..2cb78ac 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ require("dotenv").config({ quiet: true }); const Discord = require("discord.js"); const client = new Discord.Client({ - intents: [ - Discord.IntentsBitField.Flags.Guilds, - Discord.IntentsBitField.Flags.GuildMembers - ] + intents: [ + Discord.IntentsBitField.Flags.Guilds, + Discord.IntentsBitField.Flags.GuildMembers + ] }) const bvs = require("./bvs"); @@ -39,37 +39,61 @@ global.db = { const { REST, Routes } = require("discord.js"); const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN); +function checkNitroBoosts() { + bvs.getPremiumDIDs().then(dids => { + // map to object userid: did + const userDIDs = {}; + dids.forEach(did => { + userDIDs[did.userId] = did; + }); + client.guilds.cache.get(process.env.HOME_GUILD).members.fetch().then(members => { + members.forEach(member => { + if (userDIDs[member.id] && !member.premiumSince) { + // I dont feel comfortable handling deletions automatically just yet, log to console + console.log(`User ${member.user.tag} (${member.id}) is no longer boosting but still has a DID ${bvs.formatPhoneNumber(userDIDs[member.id].did)}. Please investigate and delete the DID if necessary.`); + } + }); + }).catch(error => { + console.error("Error fetching guild members:", error); + }); + }).catch(error => { + console.error("Error fetching premium DIDs:", error); + }); +} + client.on("clientReady", () => { - console.log(`Logged in as ${client.user.tag}!`); + console.log(`Logged in as ${client.user.tag}!`); - // Check that HOME_GUILD is set, and actually exists (as far as the client can see) - if (!process.env.HOME_GUILD) { - console.error("HOME_GUILD environment variable is not set. Please set it to the ID of the guild you want to use for testing."); - process.exit(1); - } - const homeGuild = client.guilds.cache.get(process.env.HOME_GUILD); - if (!homeGuild) { - console.error(`Could not find guild with ID ${process.env.HOME_GUILD}. Please make sure the bot is in that guild and that the ID is correct.`); - process.exit(1); - } + // Check that HOME_GUILD is set, and actually exists (as far as the client can see) + if (!process.env.HOME_GUILD) { + console.error("HOME_GUILD environment variable is not set. Please set it to the ID of the guild you want to use for testing."); + process.exit(1); + } + const homeGuild = client.guilds.cache.get(process.env.HOME_GUILD); + if (!homeGuild) { + console.error(`Could not find guild with ID ${process.env.HOME_GUILD}. Please make sure the bot is in that guild and that the ID is correct.`); + process.exit(1); + } - const commands = require("./commands"); - rest.put(Routes.applicationGuildCommands(client.user.id, process.env.HOME_GUILD), { body: commands }) - .then(() => console.log("Successfully registered application commands.")) - .catch(console.error); + const commands = require("./commands"); + rest.put(Routes.applicationGuildCommands(client.user.id, process.env.HOME_GUILD), { body: commands }) + .then(() => console.log("Successfully registered application commands.")) + .catch(console.error); + checkNitroBoosts(); + setInterval(checkNitroBoosts, 60 * 60 * 1000) }); client.on('interactionCreate', async interaction => { - // Check if there is a handler for the interaction in interactions/{interaction.type}/{interaction.commandName}.js, and if so, run it. - if (interaction.isChatInputCommand()) { - try { - const handler = require(`./interactions/chatCommand/${interaction.commandName}.js`); - await handler(interaction, client, bvs); - } catch (error) { - console.error(`Error handling interaction ${interaction.id}:`, error); - } - } + // Check if there is a handler for the interaction in interactions/{interaction.type}/{interaction.commandName}.js, and if so, run it. + if (interaction.isChatInputCommand()) { + try { + const handler = require(`./interactions/chatCommand/${interaction.commandName}.js`); + await handler(interaction, client, bvs); + } catch (error) { + console.error(`Error handling interaction ${interaction.id}:`, error); + } + } }); client.login(process.env.DISCORD_TOKEN); \ No newline at end of file