Added webapp

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

View File

@ -41,7 +41,7 @@ module.exports = {
const embed = new EmbedBuilder()
.setColor("#03FC20")
.setTitle("🐺 count")
.setDescription(`I have counted ${basecount} wolf messages`)
.setDescription(`[I have counted ${basecount} wolf messages](https://wolfcount.skywolfteam.nl/)`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });

18
commands/Info/wolfinv.js Normal file
View File

@ -0,0 +1,18 @@
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: "wolfinv",
private: false,
description: "Returns the invite of wolfcount.",
run: async (client, interaction) => {
const embed = new EmbedBuilder()
.setColor("#03FC20")
.setTitle("🐺 count")
.setDescription(`[invite botcounter](https://discord.com/oauth2/authorize?client_id=1100390424381751328&permissions=327744&scope=bot%20applications.commands)`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });
},
};

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}`)
});
};

1264
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,8 @@
"dependencies": {
"discord.js": "^14.0.3",
"dotenv": "^16.0.0",
"ejs": "^3.1.9",
"express": "^4.18.2",
"glob": "^7.2.0",
"moment": "^2.29.4",
"mongoose": "^7.1.0",

60
public---/index.ejs Normal file
View File

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" sizes="192x192" href="/wolf.png">
<title><%= basecount %> Wolfs</title>
<style>
body {
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
.wolf {
width: 2em;
height: 2em;
vertical-align: middle;
}
</style>
</head>
<body>
<!-- <h1><span>${basecount} wolfs</span><img class="wolf" src="images/wolf.png"></h1> -->
<h1><span><%= basecount %> wolfs</span><img class="wolf" src="/wolf.png"></h1>
</body>
</html>
<!-- <head>
<title>${basecount} Wolfs</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#c16a4f">
<link rel="icon" sizes="192x192" href="../site/assets/wolf.png">
<style>
body {
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
.wolf {
width: 2em;
height: 2em;
vertical-align: middle;
}
</style>
</head>
<body>
<h1><span>${basecount} wolfs</span><img class="wolf" src="../site/assets/wolf.png"></h1>
</body> -->

BIN
views/images/wolf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

133
views/index.ejs Normal file
View File

@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" sizes="192x192" href="/wolf.png">
<title><%= basecount %> Wolfs</title>
<style>
body {
background-color: #c2c2c2 !important;
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
.wolf {
width: 2em;
height: 2em;
vertical-align: middle;
}
h1 {
background-image: linear-gradient(to right, #c2c2c2, #6b6a6a);
animation: wiggle 4s linear infinite;
}
/* Keyframes */
@keyframes wiggle {
0%, 7% {
transform: rotateZ(0);
}
15% {
transform: rotateZ(-25deg);
}
20% {
transform: rotateZ(20deg);
}
25% {
transform: rotateZ(-20deg);
}
30% {
transform: rotateZ(10deg);
}
35% {
transform: rotateZ(-10deg);
}
40% {
transform: rotateZ(6deg);
}
45% {
transform: rotateZ(-4deg);
}
50%,100% {
transform: rotateZ(0deg);
}
}
.wolfcounting {
padding: 20% 0;
}
@media screen and (max-width: 1024px) {
.wolfcounting {
padding: 30% 0;
}
}
@media screen and (max-width: 768px) {
.wolfcounting {
padding: 38% 0;
}
}
@media screen and (max-width: 717px) {
.wolfcounting {
padding: 25% 0;
}
}
@media screen and (max-width: 425px) {
.wolfcounting {
padding: 72% 0;
}
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<!-- <h1><span>${basecount} wolfs</span><img class="wolf" src="images/wolf.png"></h1> -->
<div class="wolfcounting"><h1 style="box-shadow: 4px 6px; border: 3px solid grey; padding: 0.2vh 5px;"><span style="text-shadow: 2px 1px grey;"><%= basecount %> wolfs</span><img class="wolf" src="/wolf.png"></h1></div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
</body>
</html>
<!-- <head>
<title>${basecount} Wolfs</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#c16a4f">
<link rel="icon" sizes="192x192" href="../site/assets/wolf.png">
<style>
body {
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
.wolf {
width: 2em;
height: 2em;
vertical-align: middle;
}
</style>
</head>
<body>
<h1><span>${basecount} wolfs</span><img class="wolf" src="../site/assets/wolf.png"></h1>
</body> -->

43
views/info.ejs Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" sizes="192x192" href="/wolf.png">
<title>Wolfcount info</title>
<style>
body {
background-color: #c2c2c2 !important;
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container" style="padding: 10px">
<h1>Some information about this bot.</h1>
<p>The bot counts how many times the set letters are found, this will be once per message. So if someone says in this case wolf bla wolf the bot only counts one (the first one). Data refreshes every 2 minutes based on cron time (so 02, 04, 06, etc...).</p>
<p>You can add this bot by going to <a href="/invite">this page</a>. It will ofcourse ask you to go through some steps set by Discord to safely add it to the wanted server (Only 100 guilds possible, it may not be verified for more).</p>
<br><br>
<a href="/">Back to count</a><br>
<a href="/privacy">Privacy policy</a><br>
<a href="/tos">Terms of Service</a>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
</body>
</html>

49
views/privacy.ejs Normal file
View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" sizes="192x192" href="/wolf.png">
<title>Wolfcount privacy information</title>
<style>
body {
background-color: #c2c2c2 !important;
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container" style="padding: 10px">
<h1>Privacy statement</h1>
<h2>Data we collect</h2>
<p>The following data will get collected by using this bot.
<ul><li>Messages containing the letters set. In this case mainly messages containing "w", "o", "l" and "f".</li></ul>
</p>
<h2>Why we collect it?</h2>
<p>It will only get used for counting the number of messages.</p>
<h2>Does the data get shared?</h2>
<p>The message data is not shared to public, only the count is given on the page and the /wolfcount command.</p>
<br><br>
<a href="/">Back to count</a><br>
<a href="/info">Some more information</a><br>
<a href="/tos">Terms of Service</a>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
</body>
</html>

33
views/script.js--- Normal file
View File

@ -0,0 +1,33 @@
require("dotenv").config();
const mongoose = require('mongoose');
const wolfcount = require('../models/wolfcount');
const moment = require('moment');
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('');
console.log(`Connected to the database`);
}).catch((error) => {
console.log(`Failed to connect to the database`);
console.log(error);
});
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`)
const basecount = countdocument.count
console.log('');
}).catch((error) => {
console.error(error);
});
console.log(`${moment(Date.now()).format('DD/MM/YY H:mm:ss')} Refreshed wolfcount on cron`);

43
views/tos.ejs Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" sizes="192x192" href="/wolf.png">
<title>Wolfcount Terms of Service</title>
<style>
body {
background-color: #c2c2c2 !important;
margin: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
</style>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container" style="padding: 10px">
<h1>Terms of Service</h1>
<p>This bot kinda collects messages of Discord servers, so please mind the <a href="https://discord.com/terms">Terms of Service</a> and <a href="Community Guidelines">https://discord.com/guidelines</a> of Discord.
(The bot does not store the messages like Discord does, but it is better to follow the TOS and of Discord to avoid termination)</p>
<br><br>
<a href="/">Back to count</a><br>
<a href="/info">Some more information</a><br>
<a href="/privacy">Privacy policy</a>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
</body>
</html>