From faa8567c0a0e6d3b15d591ac6cba23d977ea544d Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 13 Mar 2020 11:08:02 -0400 Subject: [PATCH] Company Command --- .env.example | 1 + README.md | 3 +++ commands/search/company.js | 51 ++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 commands/search/company.js diff --git a/.env.example b/.env.example index 14ef6361..cc6f937a 100644 --- a/.env.example +++ b/.env.example @@ -24,6 +24,7 @@ PORTAL_EMOJI_NAME= # API Keys, IDs, and Secrets ALPHA_VANTAGE_KEY= ANILIST_USERNAME= +CLEARBIT_KEY= CLEVERBOT_KEY= CUSTOM_SEARCH_ID= DEVIANTART_ID= diff --git a/README.md b/README.md index 0fc8cd9b..0bf9a183 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,7 @@ Total: 365 * **book:** Searches Google Books for a book. * **bulbapedia:** Searches Bulbapedia for your query. * **character:** Searches AniList for your query, getting character results. +* **company:** Responds with the name and logo of a company. * **define:** Defines a word. * **derpibooru:** Responds with an image from Derpibooru. * **deviantart:** Responds with an image from a DeviantArt section, with optional query. @@ -605,6 +606,8 @@ here. * captcha ([Moms Typewriter Font](https://www.fontsquirrel.com/fonts/MomsTypewriter)) - [Chuck Norris](https://chucknorris.com/) * chuck-norris (Himself) +- [Clearbit](https://clearbit.com/) + * company ([Autocomplete API](https://dashboard.clearbit.com/docs#autocomplete-api)) - [Cleverbot](https://www.cleverbot.com/) * cleverbot ([API](https://www.cleverbot.com/api/)) - [Clipart Library](http://clipart-library.com/) diff --git a/commands/search/company.js b/commands/search/company.js new file mode 100644 index 00000000..fb32611f --- /dev/null +++ b/commands/search/company.js @@ -0,0 +1,51 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { CLEARBIT_KEY } = process.env; + +module.exports = class CompanyCommand extends Command { + constructor(client) { + super(client, { + name: 'company', + aliases: ['clearbit', 'logo', 'company-logo'], + group: 'search', + memberName: 'company', + description: 'Responds with the name and logo of a company.', + credit: [ + { + name: 'Clearbit', + url: 'https://clearbit.com/', + reason: 'Autocomplete API', + reasonURL: 'https://dashboard.clearbit.com/docs#autocomplete-api' + } + ], + args: [ + { + key: 'query', + prompt: 'What company would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get(`https://autocomplete.clearbit.com/v1/companies/suggest`) + .query({ query }) + .set({ Authorization: `Bearer ${CLEARBIT_KEY}` }); + if (!body.length) return msg.say('Could not find any results.'); + const data = body[0]; + const embed = new MessageEmbed() + .setTitle(data.name) + .setImage(data.logo) + .setFooter('Logos provided by Clearbit') + .setURL('https://clearbit.com/') + .setColor(0x00AE86); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index f43932af..09a320a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.4.1", + "version": "112.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {