diff --git a/.gitignore b/.gitignore index e43b0f9..d8f07bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .DS_Store +node_modules/ +yarn.lock +package-lock.json +*.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9ef0fde --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "lts/*" diff --git a/communities.json b/communities.json index 429502b..8454a4f 100644 --- a/communities.json +++ b/communities.json @@ -591,6 +591,13 @@ "inviteCode": "qbRAuy7", "githubUrl": "https://github.com/AtlasNX/Kosmos" }, + { + "logo": "IntellectualSites.svg", + "title": "IntellectualSites", + "quote": "Discord provides us a platform to help people resolving issues, discussing possible features and communicating with other contributors.", + "inviteCode": "ngZCzbU", + "githubUrl": "https://github.com/IntellectualSites" + }, { "logo": "enginehub.svg", "title": "EngineHub", @@ -602,8 +609,8 @@ "logo": "adafruit.svg", "title": "Adafruit", "quote": "Adafruit, a USA manufacturer of educational open-source hardware and software, uses Discord for creating Code + Community.", - "quoteSourceUrl": "https://www.adafruit.com/about/.", - "inviteCode": "https://discord.gg/adafruit", + "quoteSourceUrl": "https://www.adafruit.com/about/", + "inviteCode": "adafruit", "githubUrl": "https://github.com/adafruit" } ] diff --git a/logos/IntellectualSites.svg b/logos/IntellectualSites.svg new file mode 100644 index 0000000..1a7072f --- /dev/null +++ b/logos/IntellectualSites.svg @@ -0,0 +1 @@ + diff --git a/package.json b/package.json index 0d1f2e6..a2c95ed 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,16 @@ { "name": "discord-open-source", "version": "1.0.0", - "main": "communities.json" + "main": "communities.json", + "scripts": { + "test": "npm run fmt-check && npm run validate-codes", + "validate-codes": "node ./validate.js", + "fmt-check": "prettier -c communities.json || (npm run fmt && git diff && exit 1)", + "fmt": "prettier --write communities.json" + }, + "devDependencies": { + "chalk": "^2.4.2", + "node-fetch": "^2.3.0", + "prettier": "^1.16.1" + } } diff --git a/validate.js b/validate.js new file mode 100644 index 0000000..71ff690 --- /dev/null +++ b/validate.js @@ -0,0 +1,51 @@ +const util = require('util'); +const chalk = require('chalk'); +const fetch = require('node-fetch'); +const discordCommunities = require('./communities.json'); + +const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); + +async function validateCommunity(community) { + while (true) { + const req = await fetch(`https://discordapp.com/api/invite/${community.inviteCode}`); + const response = await req.json(); + + if (response.guild) break; + + if (response.retry_after) { + console.log(chalk.yellow(`Rate limited for ${response.retry_after}ms, waiting`)); + await delay(response.retry_after); + continue; + } + + throw new Error( + `${chalk.yellow.bold(community.title)} (${community.inviteCode}): ${util.inspect(response)}` + ); + } +} + +async function validate() { + console.log(chalk.underline.bold.white('Validating open source community invite codes')); + + const failedCommunities = []; + + for (const community of discordCommunities.data) { + console.log(`${community.title} (${community.inviteCode})`); + try { + await validateCommunity(community); + } catch (err) { + failedCommunities.push(err.message); + } + } + + if (failedCommunities.length) { + console.error(chalk.red.bold('Could not validate some community codes!\n')); + console.error(failedCommunities.join('\n') + '\n'); + throw new Error('Failed to validate invite codes'); + } +} + +validate().catch(err => { + console.error(err.message); + process.exit(1); +});