Added source

This commit is contained in:
ultimateplayer1999 2023-04-26 07:26:55 +00:00
parent 2fa15c7070
commit 294e24058f
7 changed files with 1186 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
.env

101
client.js Normal file
View File

@ -0,0 +1,101 @@
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);

14
db.js Normal file
View File

@ -0,0 +1,14 @@
require('dotenv').config();
const mongoose = require('mongoose');
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);
});

7
example.env Normal file
View File

@ -0,0 +1,7 @@
BOT_TOKEN=<bottoken>
#Mongodb cloud
DB_URL=<optional>
MONGODBUSER=<Username>
MONGODBPASS=<Pass>
MONGODBCLUSTER=<cluster>
DATABASE=<dbname>

10
models/wolfcount.js Normal file
View File

@ -0,0 +1,10 @@
const mongoose = require('mongoose');
const wolfclountSchema = new mongoose.Schema({
count: Number,
validation: String
});
const Wolfcount = mongoose.model('Wolfcount', wolfclountSchema);
module.exports = Wolfcount;

1032
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "wolfbot",
"version": "1.0.0",
"description": "Counts wolfs",
"main": "client.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"wolf",
"count"
],
"author": "ultimateplayer1999",
"license": "ISC",
"dependencies": {
"discord.js": "^14.9.0",
"dotenv": "^16.0.3",
"mongoose": "^7.0.5"
}
}