Skip to content

Commit

Permalink
Merge pull request #8 from UltronDevelopment/feat/testmode
Browse files Browse the repository at this point in the history
Adds a testmode
  • Loading branch information
RappyTV authored May 8, 2023
2 parents 806b2a6 + 54ac111 commit 489a076
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
40 changes: 36 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -79,6 +79,39 @@ 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: Math.floor(Math.random() * 99) + 1,
level: 3,
nsfw: false,
invite: `https://discord.com/invite/discord`,
channelName: `welcome`,
inviteChannel: `https://discord.com/channels/${id}/1234567890`
});
} else {
res.render(`any`, { id, created });
}
return;
}

const user = await server.util.fetchUser(id);
const invite = await server.util.fetchGuild(id);
Expand All @@ -104,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,
Expand All @@ -113,7 +145,7 @@ app.get(`/:id`, async (req, res, next) => {
name: guild.name,
created,
boosts,
level,
nsfw: guild.nsfw,
invite: code,
channelName: channel.name,
inviteChannel
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"port": 10000,
"token": "",
"testmode": false,
"theme": "#ff0000",
"hover": "#ff7777",
"ssl": {
Expand Down
2 changes: 1 addition & 1 deletion views/guild.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<% } %>
<p><span class="fas fa-hashtag"></span> <strong>Guild ID</strong>: <span class="resulth"><%= locals.id %></span></p>
<p><span class="fas fa-tag"></span> <strong>Guild Name</strong>: <span class="resulth" style="color: #e49aff;"><%= locals.name %></span></p>
<p><span class="fas fa-diamond"></span> <strong>Boosts</strong>: <span class="resulth"><%= locals.boosts %> (Level <%= locals.level %>)</span></p>
<p><span class="fas fa-diamond"></span> <strong>Boosts</strong>: <span class="resulth"><%= locals.boosts %> (Level <%= locals.boosts > 13 ? 3 : boosts > 6 ? 2 : boosts > 1 ? 1 : 0 %>)</span></p>
<p><span class="fas fa-envelope"></span> <strong>Instant Invite</strong>: <span class="resulth"><a href="<%= locals.invite %>"><%= locals.invite?.split('/')[4] %></a></span></p>
<p><span class="fas fa-channel"></span> <strong>Instant Invite Channel</strong>: <span class="resulth"><a href="<%= locals.inviteChannel %>"><%= locals.channelName %></a></span></p>
<p><span class="fas fa-x"></span> <strong>NSFW</strong>: <span class="resulth" style="color: #FFD966;"><%= locals.nsfw ? `Yes` : `No` %></span></p>
Expand Down

0 comments on commit 489a076

Please sign in to comment.