102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
require('dotenv').config();
|
|
const {Client} = require('discord.js');
|
|
const mongoose = require('mongoose');
|
|
const Wolfcount = require('./models/wolfcount');
|
|
|
|
console.clear();
|
|
|
|
const uri = `mongodb+srv://${process.env.MONGODBUSER}:${process.env.MONGODBPASS}@${process.env.MONGODBCLUSTER}/${process.env.DATABASE}?retryWrites=true&w=majority`
|
|
|
|
mongoose.connect(uri, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true
|
|
}).then(() => {
|
|
console.log(`Connected to the database`);
|
|
}).catch((error) => {
|
|
console.log(`Failed to connect to the database`);
|
|
console.log(error);
|
|
});
|
|
|
|
const client = new Client({ intents: 34305 });
|
|
|
|
client.on("ready", () => {
|
|
// set the status to do not disturb
|
|
client.user.setStatus('dnd')
|
|
});
|
|
|
|
// client.once("ready", () => {
|
|
// // ensure that the bot stats document exists
|
|
// const wolfcount = new Wolfcount({
|
|
// count: 0,
|
|
// validation: "count"
|
|
// });
|
|
|
|
// wolfcount.save().then(() => {
|
|
// console.log('Count document saved successfully into the database!');
|
|
// }).catch(err => {
|
|
// console.log('Error while saving the count document', err);
|
|
// });
|
|
|
|
// });
|
|
|
|
// Error handling
|
|
client.on("error", (error) => {
|
|
console.error("Something went wrong:", error);
|
|
});
|
|
|
|
// When a message is sent, check if the message includes the letters of wolf
|
|
const wolfChars = ['w', 'o', 'l', 'f'];
|
|
|
|
// Find a document by validation
|
|
Wolfcount.findOne({ validation: 'count' }).then((countdocument) => {
|
|
console.log(countdocument);
|
|
}).catch((error) => {
|
|
console.error(error);
|
|
});
|
|
|
|
basecount = 0
|
|
|
|
// Reset the wolf count
|
|
Wolfcount.findByIdAndUpdate("6447da87681fd1bc486a4923", {count: basecount}).then(() => {
|
|
console.log('Count reset!');
|
|
}).catch((error) => {
|
|
console.error(error);
|
|
});
|
|
|
|
client.on("messageCreate", (message) => {
|
|
// convert the message to lowercase
|
|
const lowerMsg = message.content.toLowerCase();
|
|
// console.log(lowerMsg);
|
|
|
|
// check if the message has the letters
|
|
if (wolfChars.every(char=>lowerMsg.includes(char))) {
|
|
message.react("🐺").catch(err=>console.log(err));
|
|
|
|
newcount = basecount + 1;
|
|
basecount = newcount;
|
|
|
|
console.log('Live wolf count', newcount);
|
|
|
|
// update the wolf count
|
|
Wolfcount.findByIdAndUpdate("6447da87681fd1bc486a4923", {count: newcount}).then(() => {
|
|
console.log('Count updated!');
|
|
}).catch((error) => {
|
|
console.error(error);
|
|
});
|
|
|
|
// })
|
|
// Wolfcount.findByIdAndUpdate("6447da87681fd1bc486a4923", {count: newcount}, function(err, result){
|
|
// if(err){
|
|
// console.log('Something went wrong while updating the count:', err)
|
|
// }
|
|
// else{
|
|
// console.log('Successfully updated wolfcount to', result)
|
|
// }
|
|
|
|
// })
|
|
}
|
|
});
|
|
|
|
// Connect to Discord
|
|
client.login(process.env.BOT_TOKEN);
|