From 6089f3228f48f00fffd071ebcedfd70e7d5fd353 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 12:16:43 +0200 Subject: [PATCH 1/7] Added config option 'testmode' --- src/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.json b/src/config.json index a97943c..5273d56 100644 --- a/src/config.json +++ b/src/config.json @@ -1,6 +1,7 @@ { "port": 10000, "token": "", + "testmode": false, "theme": "#ff0000", "hover": "#ff7777", "ssl": { From fec8e00e2a24f9cff5480588b968e886f3c3a737 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 12:19:02 +0200 Subject: [PATCH 2/7] Removed token checking when testmode option is disabled --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index a77f895..1d64a6c 100644 --- a/app.js +++ b/app.js @@ -14,7 +14,7 @@ server.version = require(`./package.json`).version; const options = {}; -if(server.cfg.token.trim() == ``) { +if(server.cfg.token.trim() == `` && !server.cfg.testmode) { console.log(`[ERROR] Please provide a valid token in src/config.json!`); process.exit(1); } @@ -34,7 +34,7 @@ if(server.cfg.ssl.useSSL) server.https = https.createServer(options, app).listen server.http = http.createServer(app).listen(server.cfg.port, async () => { const isTokenValid = await server.util.checkToken(server.cfg.token); - if(!isTokenValid) { + if(!isTokenValid && !server.cfg.testmode) { console.log(`[ERROR] Invalid token!`); process.exit(1); } From 52556b7863c4bdf9349f4d8d6241a8eb8d2058c7 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 13:26:11 +0200 Subject: [PATCH 3/7] Added testmode default values The id type is randomly chosen --- app.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app.js b/app.js index 1d64a6c..a34449b 100644 --- a/app.js +++ b/app.js @@ -79,6 +79,38 @@ app.get(`/:id`, async (req, res, next) => { const id = req.params.id; if(!id) return next({ status: 400, error: `You have to enter a valid ID!`, back: `/` }); if(!server.util.isSnowflake(id)) return next({ status: 400, error: `Invalid snowflake!`, back: `/` }); + if(server.cfg.testmode) { + // Testmode values + const random = Math.floor(Math.random() * 3); + const created = new Date(server.util.getTimestamp(id)).toUTCString(); + + if(random == 0) { + res.render(`user`, { + avatar: `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 6)}.png`, + id, + tag: `Clyde#0000`, + bot: false, + badges: ``, + created, + color: server.cfg.theme + }); + } else if(random == 1) { + res.render(`guild`, { + icon: `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 6)}.png`, + id, + name: `Discord Guild`, + created, + boosts: 69, + level: 3, + invite: `discord`, + channelName: `welcome`, + inviteChannel: `1234567890` + }); + } else { + res.render(`any`, { id, created }); + } + return; + } const user = await server.util.fetchUser(id); const invite = await server.util.fetchGuild(id); From 252caf33404143590e6447c01eec57700312f5a3 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 13:28:19 +0200 Subject: [PATCH 4/7] Fixed bug with not displaying nsfw guilds (#7) --- app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.js b/app.js index a34449b..8494959 100644 --- a/app.js +++ b/app.js @@ -102,6 +102,7 @@ app.get(`/:id`, async (req, res, next) => { created, boosts: 69, level: 3, + nsfw: false, invite: `discord`, channelName: `welcome`, inviteChannel: `1234567890` @@ -146,6 +147,7 @@ app.get(`/:id`, async (req, res, next) => { created, boosts, level, + nsfw: guild.nsfw, invite: code, channelName: channel.name, inviteChannel From 7b51105e4154b8ae56d114521e9053999aa5584e Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 13:49:38 +0200 Subject: [PATCH 5/7] Moved level display calculation to guild view --- app.js | 4 +--- views/guild.ejs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 8494959..c149e08 100644 --- a/app.js +++ b/app.js @@ -100,7 +100,7 @@ app.get(`/:id`, async (req, res, next) => { id, name: `Discord Guild`, created, - boosts: 69, + boosts: Math.floor(Math.random() * 99) + 1, level: 3, nsfw: false, invite: `discord`, @@ -137,7 +137,6 @@ app.get(`/:id`, async (req, res, next) => { const inviteChannel = `https://discord.com/channels/${id}/${channel.id}`; const created = new Date(server.util.getTimestamp(id)).toUTCString(); const boosts = guild.premium_subscription_count; - const level = boosts > 13 ? 3 : boosts > 6 ? 2 : boosts > 1 ? 1 : 0; res.render(`guild`, { icon, @@ -146,7 +145,6 @@ app.get(`/:id`, async (req, res, next) => { name: guild.name, created, boosts, - level, nsfw: guild.nsfw, invite: code, channelName: channel.name, diff --git a/views/guild.ejs b/views/guild.ejs index bbae8cd..1bfcae1 100644 --- a/views/guild.ejs +++ b/views/guild.ejs @@ -59,7 +59,7 @@ <% } %>

Guild ID: <%= locals.id %>

Guild Name: <%= locals.name %>

-

Boosts: <%= locals.boosts %> (Level <%= locals.level %>)

+

Boosts: <%= locals.boosts %> (Level <%= locals.boosts > 13 ? 3 : boosts > 6 ? 2 : boosts > 1 ? 1 : 0 %>)

Instant Invite: <%= locals.invite?.split('/')[4] %>

Instant Invite Channel: <%= locals.channelName %>

NSFW: <%= locals.nsfw ? `Yes` : `No` %>

From df4a224565d4c1165ab7c63affab0d081a7ae804 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 13:56:31 +0200 Subject: [PATCH 6/7] Fixed default invite and inviteChannel values --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index c149e08..3cd9e58 100644 --- a/app.js +++ b/app.js @@ -103,9 +103,9 @@ app.get(`/:id`, async (req, res, next) => { boosts: Math.floor(Math.random() * 99) + 1, level: 3, nsfw: false, - invite: `discord`, + invite: `https://discord.com/invite/discord`, channelName: `welcome`, - inviteChannel: `1234567890` + inviteChannel: `https://discord.com/channels/${id}/1234567890` }); } else { res.render(`any`, { id, created }); From 54ac111e1891d21c170881867b13962c0184d410 Mon Sep 17 00:00:00 2001 From: RappyTV Date: Mon, 8 May 2023 14:57:29 +0200 Subject: [PATCH 7/7] Added info to readme --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index bd827bc..222d238 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,7 @@ Your [src/config.json](https://github.com/UltronDevelopment/discord.id/blob/mast { "port": 10000, "token": "", + "testmode": false, "theme": "#ff0000", "hover": "#ff7777", "ssl": { @@ -28,6 +29,7 @@ Your [src/config.json](https://github.com/UltronDevelopment/discord.id/blob/mast ``` - `port` - The http port - `token` - Your bot's token (you can't fetch users without a bot token) +- `testmode` - Toggles the testmode (In testmode you don't need to provide a bot token) - `theme` - The color of the button and navbar - `hover` - The color of the button when hovering over it - `ssl.useSSL` - If the server should use an SSL certificate