Added banner in api

This commit is contained in:
CorwinDev committed 2022-08-13 20:05:01 +02:00
1 parent c348212aa9
commit b774ae1192
7 files changed
+1069 -10

No files matched your search

+995
View File
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"start": "ode index.js",
"css": "postcss website/public/css/tailwind.css -o website/public/css/style.css"
},
"repository": {
@@ -28,6 +28,7 @@
"dependencies": {
"autoprefixer": "^10.4.8",
"body-parser": "^1.20.0",
"canvas": "^2.9.3",
"colors": "^1.4.0",
"cookie-session": "^2.0.0",
"discord.js": "^14.1.1",
Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

+65 -1
View File
@@ -10,7 +10,7 @@ router.get('/', function (req, res) {
})
});
router.get('/search/:id', function (req, res) {
bots.find({ $or: [{ id: { $regex: req.params.id } }, { name: { $regex: req.params.id } }] },async function (err, bot) {
bots.find({ $or: [{ id: { $regex: req.params.id } }, { name: { $regex: req.params.id } }] }, async function (err, bot) {
if (err) throw err;
if (!bot) {
return
@@ -36,6 +36,69 @@ router.get('/search/:id', function (req, res) {
}
})
})
const applyText = (canvas, text) => {
const context = canvas.getContext('2d');
let fontSize = 70;
do {
context.font = `30px sans-serif`;
} while (context.measureText(text).width > canvas.width - 300);
return context.font;
};
const { createCanvas, loadImage, Image } = require('canvas')
const { readFile } = require('fs/promises');
router.get('/server/:id', function (req, res) {
// Get one server and draw it on the canvas
servers.findOne({ id: req.params.id }, async function (err, server) {
if (err) throw err;
if (!server) {
return
} else {
const serverr = await global.bsl.guilds.cache.get(req.params.id)
if(!serverr)return
const serverName = server.name
const serverDescription = server.description
const serverMembers = serverr.memberCount
// Load the image
const avatar = await loadImage(`https://cdn.discordapp.com/icons/${serverr.id}/${serverr.icon}.jpg`)
// Draw the image
const canvas = createCanvas(700, 250);
const context = canvas.getContext('2d');
const background = await readFile('./website/public/img/wallpaper.jpg');
const backgroundImage = new Image();
backgroundImage.src = background;
context.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
context.strokeStyle = '#0099ff';
context.strokeRect(0, 0, canvas.width, canvas.height);
context.font = '15px sans-serif';
context.fillStyle = '#fff';
context.fillText('©️ BotsCord.xyz', canvas.width / 1.2, canvas.height / 1.05);
context.font = '30px sans-serif';
context.fillStyle = '#ffffff';
context.fillText(`BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB`, canvas.width / 2.7, canvas.height / 1.8);
context.font = '18px sans-serif';
context.fillText(`🙍‍♂️ ${serverMembers}`, canvas.width / 2.7, canvas.height / 1.1);
context.fillText(`❤️ ${server.votes}`, canvas.width / 2.1, canvas.height / 1.1);
context.beginPath();
context.arc(125, 125, 100, 0, Math.PI * 2, true);
context.closePath();
context.clip();
context.drawImage(avatar, 25, 25, 200, 200);
res.setHeader('Content-Type', 'image/png');
canvas.pngStream().pipe(res);
}
})
})
router.use(function (req, res, next) {
if (!req.headers.authorization) {
return res.status(403).json({ error: 'No credentials sent!' });
@@ -145,4 +208,5 @@ router.get('/bots/check/:id', function (req, res) {
});
})
module.exports = router;
-3
View File
@@ -43,7 +43,6 @@ router.post('/add', async function (req, res) {
req.session.error = "Server already exists";
return res.redirect('/');
}
//check if member has admin permissions
if (!checkServer.members.cache.get(req.user.id).permissions.has("ADMINISTRATOR")) {
req.session.error = "You do not have admin permissions";
return res.redirect('/');
@@ -55,8 +54,6 @@ router.post('/add', async function (req, res) {
req.session.error = "Could not create invite";
return res.redirect('/');
} else {
channel.createInvite({
maxAge: 0,
maxUses: 0,
+4 -2
View File
@@ -25,7 +25,7 @@
<% if(typeof server !="undefined" ) { %>
<meta property="og:title" content="BotsCord.xyz" />
<meta property="og:url" content="http://botscord.xyz/server/<%=server.id %>" />
<meta property="og:image" content="<%= server.icon %>" />
<meta property="og:image" content="https://cdn.discordapp.com/avatars/<%=server.id %>/<%=global.bsl.guilds.cache.get(server.id).icon %>.png" />
<meta property="og:description" content="<%= server.description %>
­
🟢 <%= global.bsl.guilds.cache.get(server.id).members.cache.filter(a => a.presence?.status).size %> onlineᅠᅠᅠᅠ⚫ <%= global.bsl.guilds.cache.get(server.id).memberCount %> members">
@@ -88,9 +88,11 @@
<li class="fa fa-server mr-1"></li>Edit server
</a>
</div>
<div class="py-1" role="none">
<a target=”_blank” href="https://docs.botscord.xyz" class="text-gray-700 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-2"><i class="fa fa-solid fa-book"></i>Docs</a>
</div>
</div>
</div>
<!-- dropdown menu with tailwindcss -->
</div>
<% if (typeof user=="undefined" ) { %>
<a href="/auth" class="inline-block text-sm px-4 py-2 leading-none border rounded text-white border-white hover:border-transparent hover:text-blue-color hover:bg-white mt-4 lg:mt-0 w-fit h-fit">Login</a>
+3 -3
View File
@@ -18,7 +18,6 @@
</svg>
</div>
<input type="text" id="simple-search" class="bg-primary-color border border-gray-300 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-primary-color dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Search" required>
<div id="search-results" class="hidden bg-primary-color border border-gray-300 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 w-full pl-10 p-2.5 dark:bg-primary-color dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"></div>
</div>
</form><br>
@@ -35,14 +34,15 @@
type: 'GET',
success: function(data) {
var html = '';
if(!data.serverArray.length) html = '<div class="text-center">No results found</div>';
for (var i = 0; i < data.serverArray.length; i++) {
if (i == 5) {
break;
}
if (data.serverArray[i].type == 'server') {
html += '<a href="/server/' + data.serverArray[i].id + '" class="flex items-center p-2 border-b border-gray-300 hover:bg-primary-color hover:text-white"><img title="botscord.site" class="mr-2" width="48" onError="this.src = ' + "'/img/logo.webp'" + '" style="border-radius: 8px;" src="' + data.serverArray[i].avatar + '" />' + data.serverArray[i].name + '</a>';
html += '<a href="/server/' + data.serverArray[i].id + '" class="flex items-center p-2 border-b border-gray-300 hover:bg-primary-color hover:text-white"><img title="botscord.site" class="mr-2" width="48" onError="this.src = ' + "'/img/logo.webp'" + '" style="border-radius: 8px;" src="' + data.serverArray[i].avatar + '" />' + data.serverArray[i].name + ' | Server</a>';
} else {
html += '<a href="/bot/' + data.serverArray[i].id + '" class="flex items-center p-2 border-b border-gray-300 hover:bg-primary-color hover:text-white"><img title="botscord.site" class="mr-2" width="48" onError="this.src = ' + " '/img/logo.webp'" + '" style="border-radius: 8px;" src="' + data.serverArray[i].avatar + '" />' + data.serverArray[i].name + '</a>';
html += '<a href="/bot/' + data.serverArray[i].id + '" class="flex items-center p-2 border-b border-gray-300 hover:bg-primary-color hover:text-white"><img title="botscord.site" class="mr-2" width="48" onError="this.src = ' + " '/img/logo.webp'" + '" style="border-radius: 8px;" src="' + data.serverArray[i].avatar + '" />' + data.serverArray[i].name + ' | Bot </a>';
}
}
var searchr = document.getElementById('search-results');