MOOver.js/main.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-01-25 23:16:51 +00:00
/**
List of intents
https://discord.com/developers/docs/topics/gateway#privileged-intents
*/
2023-02-25 12:42:21 +00:00
require('dotenv').config()
2022-01-25 23:16:51 +00:00
2023-02-08 16:38:31 +00:00
var http = require('http')
2023-02-08 14:44:57 +00:00
http.createServer(function (req, res) {
2023-02-08 16:38:31 +00:00
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,
2023-02-25 12:42:21 +00:00
GatewayIntentBits
2023-02-08 16:38:31 +00:00
} = 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,
],
2023-02-08 16:38:31 +00:00
})
2023-02-08 16:38:31 +00:00
const fs = require('fs')
client.commands = new Collection()
const commandFiles = fs.readdirSync('./commands')
2023-02-08 16:38:31 +00:00
.filter(file => !file.includes('WIP'))
for (const file of commandFiles) {
2023-02-08 16:38:31 +00:00
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
2023-02-08 16:38:31 +00:00
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')
}).catch((err) => {
console.log(err)
})
}
2023-02-25 12:42:21 +00:00
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-02-08 18:03:24 +00:00
if (client.user.username != 'MOOver Debug') {
const turnOnMsg = ['AAAAAAAAAAAAA', 'Just turned on!',
'Just woke up!', 'May have crashed... sowwyyy >.<',
'Heyyyy!', 'I\'m baaaack', 'Whom\'st have summoned the ancient one?']
2023-02-08 18:03:24 +00:00
client.channels.cache.get('780439236867653635').send(turnOnMsg[help.RNG(turnOnMsg.length)]);
}
2023-02-08 16:38:31 +00:00
cron.schedule('0 13 * * *', async function () {
2023-02-25 12:42:21 +00:00
ping()
2023-02-08 16:38:31 +00:00
})
await dbConnect();
2023-02-25 12:42:21 +00:00
const { eModel } = require('./database/schemas');
eModel.updateMany({}, { $set: { specialMessage: "" }}).exec()
2023-02-08 16:38:31 +00:00
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)
});
2021-12-24 11:58:33 +00:00
client.on('interactionCreate', async interaction => {
2023-02-08 16:38:31 +00:00
if (!interaction.isCommand()) return
2023-02-08 16:38:31 +00:00
const command = client.commands.get(interaction.commandName)
2023-02-08 16:38:31 +00:00
if (!command) return
try {
2023-02-08 16:38:31 +00:00
await command.execute(interaction)
}
catch (error) {
2023-02-08 16:38:31 +00:00
console.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
2023-02-08 16:38:31 +00:00
})
}
2023-02-08 16:38:31 +00:00
})
2020-10-30 21:52:39 +00:00
2023-02-08 16:38:31 +00:00
client.login(process.env.TOKEN)
2023-02-25 12:42:21 +00:00
module.exports = client