diff --git a/.env.example b/.env.example index b80efbc6..12f52a18 100644 --- a/.env.example +++ b/.env.example @@ -55,6 +55,8 @@ FACEPLUSPLUS_SECRET= FLICKR_KEY= GIPHY_KEY= GITHUB_ACCESS_TOKEN= +GODADDY_KEY= +GODADDY_SECRET= GOOGLE_CALENDAR_ID= GOOGLE_KEY= GOV_KEY= diff --git a/commands/analyze/domain-available.js b/commands/analyze/domain-available.js new file mode 100644 index 00000000..03b06265 --- /dev/null +++ b/commands/analyze/domain-available.js @@ -0,0 +1,52 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { parseDomain, ParseResultType } = require('parse-domain'); +const { GODADDY_KEY, GODADDY_SECRET } = process.env; + +module.exports = class DomainAvailableCommand extends Command { + constructor(client) { + super(client, { + name: 'domain-available', + aliases: ['domain', 'buy-domain'], + group: 'analyze', + memberName: 'domain-available', + description: 'Determines if a domain is available for purchase.', + credit: [ + { + name: 'GoDaddy', + url: 'https://www.godaddy.com/', + reason: 'API', + reasonURL: 'https://developer.godaddy.com/' + } + ], + args: [ + { + key: 'url', + prompt: 'What URL do you want to test?', + type: 'url' + } + ] + }); + } + + async run(msg, { url }) { + const { type, domain, topLevelDomains } = parseDomain(parsed.hostname); + if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.'); + try { + const { body } = await request + .get('https://api.godaddy.com/v1/domains/available') + .set({ Authorization: `sso-key ${GODADDY_KEY}:${GODADDY_SECRET}` }) + .query({ + domain: `${domain}.${topLevelDomains.join('.')}`, + checkType: 'FAST', + forTransfer: false + }); + if (!body.definitive) return msg.reply('❔ This domain might be available, but I\'m not sure.'); + if (body.available) return msg.reply('👍 This domain is available.'); + return msg.reply('👎 This domain is taken.'); + } catch (err) { + if (err.status === 422) return msg.reply('This domain is not supported.'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 51979cf7..f1d93398 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "136.2.0", + "version": "136.3.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true,