2023-01-18 00:35:24 +00:00
|
|
|
/* eslint-disable no-case-declarations */
|
|
|
|
/* eslint-disable indent */
|
|
|
|
// dotenv for handling environment variables
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
const token = process.env.TOKEN;
|
2023-02-20 01:42:14 +00:00
|
|
|
const statusChannelId = process.env.STATUSCHANNELID;
|
2023-01-18 00:35:24 +00:00
|
|
|
|
|
|
|
// Discord.JS
|
2023-01-24 01:50:14 +00:00
|
|
|
const { Client, GatewayIntentBits, Partials, ActivityType } = require('discord.js');
|
2023-01-18 00:35:24 +00:00
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
GatewayIntentBits.GuildMessages,
|
|
|
|
GatewayIntentBits.GuildMessageReactions,
|
2023-01-18 01:27:04 +00:00
|
|
|
GatewayIntentBits.MessageContent
|
2023-01-18 00:35:24 +00:00
|
|
|
],
|
|
|
|
partials: [
|
|
|
|
Partials.Channel,
|
2023-01-18 01:27:04 +00:00
|
|
|
Partials.Message
|
2023-01-18 00:35:24 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
// Various imports
|
2023-01-19 17:44:49 +00:00
|
|
|
const fn = require('./modules/functions.js');
|
|
|
|
const strings = require('./data/strings.json');
|
2023-02-01 03:51:10 +00:00
|
|
|
const dbfn = require('./modules/dbfn.js');
|
2023-02-20 01:42:14 +00:00
|
|
|
const isDev = process.env.DEBUG;
|
2023-01-18 00:35:24 +00:00
|
|
|
|
2023-02-20 01:42:14 +00:00
|
|
|
client.once('ready', async () => {
|
2023-02-20 19:07:38 +00:00
|
|
|
fn.collectionBuilders.slashCommands(client);
|
2023-02-20 01:42:14 +00:00
|
|
|
await fn.collectionBuilders.guildInfos(client);
|
2023-02-20 19:07:38 +00:00
|
|
|
await fn.collectionBuilders.messageCollectors(client);
|
2023-02-26 17:09:04 +00:00
|
|
|
// checkRateLimits();
|
2023-01-18 00:35:24 +00:00
|
|
|
console.log('Ready!');
|
2023-01-24 01:50:14 +00:00
|
|
|
client.user.setActivity({ name: strings.activity.name, type: ActivityType.Watching });
|
2023-02-01 03:51:10 +00:00
|
|
|
if (isDev == 'false') {
|
|
|
|
client.channels.fetch(statusChannelId).then(channel => {
|
|
|
|
channel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`);
|
|
|
|
});
|
|
|
|
}
|
2023-01-18 00:35:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// slash-commands
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
|
|
if (interaction.isCommand()) {
|
2023-02-20 01:42:14 +00:00
|
|
|
if (isDev) {
|
|
|
|
console.log(interaction);
|
|
|
|
}
|
2023-01-18 00:35:24 +00:00
|
|
|
const { commandName } = interaction;
|
|
|
|
|
|
|
|
if (client.slashCommands.has(commandName)) {
|
|
|
|
client.slashCommands.get(commandName).execute(interaction);
|
|
|
|
} else {
|
|
|
|
interaction.reply('Sorry, I don\'t have access to that command.');
|
2023-01-21 14:58:32 +00:00
|
|
|
console.error('Slash command attempted to run but not found: ' + commandName);
|
2023-01-18 00:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 01:42:14 +00:00
|
|
|
if (interaction.isButton()) {
|
|
|
|
switch (interaction.component.customId) {
|
|
|
|
case 'refresh':
|
|
|
|
// console.log(JSON.stringify(interaction));
|
|
|
|
await fn.refresh(interaction).catch(err => {
|
|
|
|
interaction.channel.send(fn.builders.errorEmbed(err));
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'deleteping':
|
|
|
|
if (interaction.message.deletable) {
|
|
|
|
await interaction.message.delete().catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'waterpingrole':
|
|
|
|
const waterPingStatus = await fn.buttonHandlers.waterPing(interaction);
|
|
|
|
await interaction.reply(waterPingStatus).catch(e => console.error(e));
|
|
|
|
break;
|
|
|
|
case 'fruitpingrole':
|
|
|
|
const fruitPingStatus = await fn.buttonHandlers.fruitPing(interaction);
|
|
|
|
await interaction.reply(fruitPingStatus).catch(e => console.error(e));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2023-02-01 03:51:10 +00:00
|
|
|
}
|
2023-01-18 00:35:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-21 23:41:47 +00:00
|
|
|
async function checkRateLimits(hi) {
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
// Make a GET request to the Discord API
|
|
|
|
await axios.get('https://discord.com/api/v10/users/@me', {
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bot ${token}`
|
|
|
|
}
|
|
|
|
}).then(response => {
|
|
|
|
// Get the rate limit headers
|
|
|
|
const remaining = response.headers['x-ratelimit-remaining'];
|
|
|
|
const reset = response.headers['x-ratelimit-reset'];
|
|
|
|
|
|
|
|
// Log the rate limit headers
|
|
|
|
console.log(`Remaining requests: ${remaining}`);
|
|
|
|
console.log(`Reset time (Unix epoch seconds): ${reset}`);
|
|
|
|
}).catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
await fn.sleep(500).then(async () =>{
|
|
|
|
await checkRateLimits();
|
|
|
|
})
|
|
|
|
}
|
2023-02-20 19:07:38 +00:00
|
|
|
|
2023-01-25 08:07:41 +00:00
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
console.error('Unhandled promise rejection:', error);
|
|
|
|
});
|
|
|
|
|
2023-01-18 00:35:24 +00:00
|
|
|
client.login(token);
|