MOOver.js/main.js

103 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2022-01-25 23:16:51 +00:00
/**
List of intents
https://discord.com/developers/docs/topics/gateway#privileged-intents
*/
require('dotenv').config();
2022-01-25 23:16:51 +00:00
const http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(5000, '127.0.0.1');
2023-02-08 14:44:57 +00:00
const {
Client,
Collection,
GatewayIntentBits,
} = require('discord.js');
2023-02-25 12:42:21 +00:00
const client = new Client({
intents: [
2023-02-25 12:42:21 +00:00
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
});
const fs = require('fs');
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands')
.filter(file => !file.includes('WIP'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
2022-02-18 12:54:33 +00:00
const mongoose = require('mongoose');
async function dbConnect() {
mongoose.connect(process.env.DBSRV, {
useNewUrlParser: true,
useUnifiedTopology: true,
2023-02-25 12:42:21 +00:00
}).then(() => {
console.log('Connected to database');
2023-02-25 12:42:21 +00:00
}).catch((err) => {
console.log(err);
});
}
const help = require('./helpFunctions.js');
const cron = require('node-cron');
2023-02-25 12:42:21 +00:00
let gotMessage;
2022-02-18 12:54:33 +00:00
client.once('ready', async () => {
2023-02-25 12:42:21 +00:00
gotMessage = require('./messageHandler');
const ping = require('./ping');
2023-07-09 08:50:45 +00:00
2023-07-12 18:44:04 +00:00
if (process.env.DEBUG != 'ON') {
const turnOnMsg = ['AAAAAAAAAAAAA', 'Just turned on!',
'Just woke up!', 'May have crashed... sowwyyy >.<',
'Heyyyy!', 'I\'m baaaack', 'Whom\'st have summoned the ancient one?'];
const debugChannel = client.channels.cache.get('780439236867653635');
if (debugChannel) {
debugChannel.send(turnOnMsg[help.RNG(turnOnMsg.length)]);
}
2023-02-08 18:03:24 +00:00
}
2023-03-03 14:22:38 +00:00
await dbConnect();
cron.schedule('0 13 * * *', async function() {
ping();
});
console.log('Running!');
});
2020-10-30 21:52:39 +00:00
2023-02-25 12:42:21 +00:00
client.on('messageCreate', (message) => {
gotMessage(message);
2023-02-25 12:42:21 +00:00
});
2021-12-24 11:58:33 +00:00
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
}
catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
});
2020-10-30 21:52:39 +00:00
2023-04-23 20:26:22 +00:00
client.login(process.env.TOKEN);
2023-02-25 12:42:21 +00:00
2023-07-09 08:50:45 +00:00
module.exports = client;