From 787f3ec54ab484e6b030f6af66b0259386eb0e65 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 2 Sep 2017 18:21:03 +0000 Subject: [PATCH] spoopy link command --- commands/random/spoopy-link.js | 36 ++++++++++++++++++++++++++++++++++ commands/search/discrim.js | 4 ++-- commands/search/github.js | 6 ++++-- commands/search/pokedex.js | 2 +- commands/search/reddit.js | 3 ++- commands/search/wikia.js | 3 ++- package.json | 2 +- 7 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 commands/random/spoopy-link.js diff --git a/commands/random/spoopy-link.js b/commands/random/spoopy-link.js new file mode 100644 index 00000000..6eaa919c --- /dev/null +++ b/commands/random/spoopy-link.js @@ -0,0 +1,36 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); +const { stripIndents } = require('common-tags'); + +module.exports = class SpoopyLinkCommand extends Command { + constructor(client) { + super(client, { + name: 'spoopy-link', + group: 'random', + memberName: 'spoopy-link', + description: 'Checks if a link is spoopy or not.', + args: [ + { + key: 'site', + prompt: 'What site do you think is spoopy?', + type: 'string', + parse: query => encodeURIComponent(query) + } + ] + }); + } + + async run(msg, args) { + const { site } = args; + try { + const { body } = await snekfetch + .get(`https://spoopy.link/api/${site}`); + return msg.say(stripIndents` + ${body.safe ? 'This site is safe!' : 'This site may not be safe...'} + ${body.chain.map(url => `<${url.url}> [${url.safe ? 'SAFE' : `UNSAFE: ${url.reasons.join(', ')}`}]`).join('\n')} + `); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/discrim.js b/commands/search/discrim.js index 7a572882..4c9faad6 100644 --- a/commands/search/discrim.js +++ b/commands/search/discrim.js @@ -17,8 +17,8 @@ module.exports = class DiscrimCommand extends Command { type: 'string', default: '', validate: discrim => { - if (/[0-9]+$/g.test(discrim) && discrim.length === 4) return true; - return 'Invalid Discriminator.'; + if (/^[0-9]+$/g.test(discrim) && discrim.length === 4) return true; + return 'Invalid discriminator.'; } } ] diff --git a/commands/search/github.js b/commands/search/github.js index fce813eb..1e868bd0 100644 --- a/commands/search/github.js +++ b/commands/search/github.js @@ -15,12 +15,14 @@ module.exports = class GitHubCommand extends Command { { key: 'author', prompt: 'Who is the author of the repository?', - type: 'string' + type: 'string', + parse: author => encodeURIComponent(author) }, { key: 'repository', prompt: 'What is the name of the repository?', - type: 'string' + type: 'string', + parse: repository => encodeURIComponent(repository) } ] }); diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 3cbc6d73..96e44aa2 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -18,7 +18,7 @@ module.exports = class PokedexCommand extends Command { key: 'pokemon', prompt: 'What Pokémon would you like to get information on?', type: 'string', - parse: pokemon => pokemon.toLowerCase().replace(/ /g, '-') + parse: pokemon => encodeURIComponent(pokemon.toLowerCase().replace(/ /g, '-')) } ] }); diff --git a/commands/search/reddit.js b/commands/search/reddit.js index c64f9e34..2d6cde09 100644 --- a/commands/search/reddit.js +++ b/commands/search/reddit.js @@ -14,7 +14,8 @@ module.exports = class RedditCommand extends Command { { key: 'subreddit', prompt: 'What subreddit would you like to get a post from?', - type: 'string' + type: 'string', + parse: subreddit => encodeURIComponent(subreddit) } ] }); diff --git a/commands/search/wikia.js b/commands/search/wikia.js index eef5b806..163b60a0 100644 --- a/commands/search/wikia.js +++ b/commands/search/wikia.js @@ -16,7 +16,8 @@ module.exports = class WikiaCommand extends Command { { key: 'wiki', prompt: 'What is the subdomain of the wiki you want to search?', - type: 'string' + type: 'string', + parse: wiki => encodeURIComponent(wiki) }, { key: 'query', diff --git a/package.json b/package.json index c9267c94..932a3b7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "35.0.0", + "version": "35.1.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {