Added webapp

This commit is contained in:
2023-05-02 13:29:51 +00:00
parent 0f4cecf9b0
commit 1a2a90d09e
12 changed files with 1705 additions and 25 deletions

View File

@ -6,6 +6,10 @@ const mongoose = require('mongoose');
const wolfcount = require('../models/wolfcount');
var cron = require('node-cron');
const moment = require('moment');
const express = require("express");
const app = express();
const port = 40005
const cwd = process.cwd()
module.exports = async (client) => {
@ -55,41 +59,42 @@ module.exports = async (client) => {
console.error(error);
});
// setInterval(function() {
// // Find a document by validation
// wolfcount.findOne({ validation: 'wolfcount' }).then((countdocument) => {
// console.log('');
// //console.log(countdocument);
// console.log(`Refreshed count`)
// basecount = countdocument.count
// setInterval(function() {
// // Find a document by validation
// wolfcount.findOne({ validation: 'wolfcount' }).then((countdocument) => {
// console.log('');
// //console.log(countdocument);
// console.log(`Refreshed count`)
// basecount = countdocument.count
// console.log('');
// }).catch((error) => {
// console.error(error);
// });
// }, 30000);
// console.log('');
// }).catch((error) => {
// console.error(error);
// });
// }, 30000);
cron.schedule('*/2 * * * *', async () => {
// Slash Commands Register
client.on("ready", async () => {
cron.schedule('*/2 * * * *', async () => {
console.log(`${moment(Date.now()).format('DD/MM/YY H:mm:ss')} Starting count refresh...`);
// Find a document by validation
wolfcount.findOne({ validation: 'wolfcount' }).then((countdocument) => {
console.log('');
//console.log(countdocument);
console.log(`Refreshed count`)
basecount = countdocument.count
let basecount = countdocument.count;
console.log('');
}).catch((error) => {
console.error(error);
return basecount;
}).catch((error) => {
console.error(error);
});
console.log(`${moment(Date.now()).format('DD/MM/YY H:mm:ss')} Refreshed wolfcount on cron`);
});
console.log(`${moment(Date.now()).format('DD/MM/YY H:mm:ss')} Refreshed wolfcount on cron`);
});
// Slash Commands Register
client.on("ready", async () => {
// Register for a single guild
await client.guilds.cache.get("239352426451304449").commands.set(arrayOfSlashCommands);
// Register for a single guild
@ -105,4 +110,34 @@ cron.schedule('*/2 * * * *', async () => {
console.error("Something went wrong:", error);
});
app.set('view engine', 'ejs');
app.use(express.static(`${cwd}/views/images`));
// The root of the webapp
app.get("/", (req, res) => {
res.render('index', {basecount});
});
app.get("/info", (req, res) => {
res.render('info');
});
app.get("/privacy", (req, res) => {
res.render('privacy');
});
app.get("/tos", (req, res) => {
res.render('tos');
});
// redirect /invite to the discord invite
app.get('/invite', async (req, res) => {
res.redirect(`https://discord.com/oauth2/authorize?client_id=${client.user.id}&permissions=327744&scope=bot%20applications.commands`);
});
app.listen(port, () => {
console.log(`Webapp listening on port ${port}`)
});
};