Ok, ppl can buy numbers now, good
This commit is contained in:
parent
7f99c0ac29
commit
d15b619b24
80
index.js
80
index.js
|
|
@ -1,10 +1,10 @@
|
||||||
require("dotenv").config({ quiet: true });
|
require("dotenv").config({ quiet: true });
|
||||||
const Discord = require("discord.js");
|
const Discord = require("discord.js");
|
||||||
const client = new Discord.Client({
|
const client = new Discord.Client({
|
||||||
intents: [
|
intents: [
|
||||||
Discord.IntentsBitField.Flags.Guilds,
|
Discord.IntentsBitField.Flags.Guilds,
|
||||||
Discord.IntentsBitField.Flags.GuildMembers
|
Discord.IntentsBitField.Flags.GuildMembers
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const bvs = require("./bvs");
|
const bvs = require("./bvs");
|
||||||
|
|
@ -39,37 +39,61 @@ global.db = {
|
||||||
const { REST, Routes } = require("discord.js");
|
const { REST, Routes } = require("discord.js");
|
||||||
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN);
|
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", () => {
|
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)
|
// Check that HOME_GUILD is set, and actually exists (as far as the client can see)
|
||||||
if (!process.env.HOME_GUILD) {
|
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.");
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const homeGuild = client.guilds.cache.get(process.env.HOME_GUILD);
|
const homeGuild = client.guilds.cache.get(process.env.HOME_GUILD);
|
||||||
if (!homeGuild) {
|
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.`);
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commands = require("./commands");
|
const commands = require("./commands");
|
||||||
rest.put(Routes.applicationGuildCommands(client.user.id, process.env.HOME_GUILD), { body: commands })
|
rest.put(Routes.applicationGuildCommands(client.user.id, process.env.HOME_GUILD), { body: commands })
|
||||||
.then(() => console.log("Successfully registered application commands."))
|
.then(() => console.log("Successfully registered application commands."))
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
checkNitroBoosts();
|
||||||
|
setInterval(checkNitroBoosts, 60 * 60 * 1000)
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('interactionCreate', async interaction => {
|
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.
|
// Check if there is a handler for the interaction in interactions/{interaction.type}/{interaction.commandName}.js, and if so, run it.
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
try {
|
try {
|
||||||
const handler = require(`./interactions/chatCommand/${interaction.commandName}.js`);
|
const handler = require(`./interactions/chatCommand/${interaction.commandName}.js`);
|
||||||
await handler(interaction, client, bvs);
|
await handler(interaction, client, bvs);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error handling interaction ${interaction.id}:`, error);
|
console.error(`Error handling interaction ${interaction.id}:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
||||||
Loading…
Reference in a new issue