Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Add check-invite.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Gesugao-san committed Mar 27, 2022
1 parent fbef241 commit d42a0ae
Show file tree
Hide file tree
Showing 4 changed files with 1,103 additions and 36 deletions.
47 changes: 47 additions & 0 deletions legacy/code/researching/check-invite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

// https://stackoverflow.com/a/64648205/8175291
const fetch = require('node-fetch'); // [email protected]
//import fetch from "node-fetch";

const code_valid = 'discord-testers';
const code_invalid = 'this-is-invalid';
// https://discordapp.com/api/widget/0
// https://discordapp.com/api/invite/${code}

async function check_guild_widget(id) {
process.stdout.write(`guild "${id}": `);
await fetch(`https://discord.com/api/guilds/${id}/widget.json`)
.then((res) => res.json())
.then((json) => {
if (json.message === 'Unknown Guild') {
//console.log(`the invite is invalid`);
return Promise.reject(`the guild is unknown`); // Error 1015...
}
process.stdout.write(`valid, `);
if (json.message === 'Widget Disabled') {
return Promise.reject(`widget is disabled`);
}
console.log(`widget is enabled.`);
});
}

async function check_invite(code) {
process.stdout.write(`invite "${code}": `);
await fetch(`https://discordapp.com/api/invite/${code}`)
.then((res) => res.json())
.then((json) => {
if (json.message === 'Unknown Invite') {
console.log(`invalid`);
return;
} else {
console.log(`valid`);
}
});
await check_guild_widget(json.guild.id);
}


(async () => {
await check_invite(code_valid);
await check_invite(code_invalid);
})();
4 changes: 2 additions & 2 deletions legacy/code/researching/index_web.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

//const { Client } = require('discord.js');
const { Client, Collection, Intents } = require('discord.js');
const WS = require('./ws/ws');
const WS = require('./../../ws/ws');
var hbs = require('express-handlebars');

// load config.json
const config = require('./config_web.json');
const config = require('./../../config.json');

// Create Discord Bot Client
//var client = new Client();
Expand Down
Loading

0 comments on commit d42a0ae

Please sign in to comment.