From 42ca43e1bad5b732fcdefc5b49fdd9e73c53c0bc Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 29 Aug 2018 23:53:42 +0000 Subject: [PATCH] Make webhook a part of client --- .env.example | 4 ++-- commands/text-edit/webhook.js | 8 ++------ package.json | 2 +- structures/Client.js | 3 +++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 90512032..81df6287 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,8 @@ XIAO_TOKEN= OWNERS= XIAO_PREFIX= INVITE= +XIAO_WEBHOOK_ID= +XIAO_WEBHOOK_TOKEN= # Emoji IDs GOLD_FISH_EMOJI_ID= @@ -33,8 +35,6 @@ TUMBLR_KEY= TWITTER_KEY= TWITTER_SECRET= WATTPAD_KEY= -WEBHOOK_ID= -WEBHOOK_TOKEN= WHATANIME_KEY= WORDNIK_KEY= XIAO_GITHUB_REPO_NAME= diff --git a/commands/text-edit/webhook.js b/commands/text-edit/webhook.js index 8754367d..a91d1ffe 100644 --- a/commands/text-edit/webhook.js +++ b/commands/text-edit/webhook.js @@ -1,6 +1,4 @@ const Command = require('../../structures/Command'); -const request = require('node-superfetch'); -const { WEBHOOK_ID, WEBHOOK_TOKEN } = process.env; module.exports = class WebhookCommand extends Command { constructor(client) { @@ -9,7 +7,7 @@ module.exports = class WebhookCommand extends Command { aliases: ['rin', 'rin-say'], group: 'text-edit', memberName: 'webhook', - description: 'Posts a message to the webhook defined in your `process.env`.', + description: 'Posts a message to the webhook defined in the bot owner\'s `process.env`.', details: 'Only the bot owner(s) may use this command.', ownerOnly: true, clientPermissions: ['MANAGE_MESSAGES'], @@ -26,9 +24,7 @@ module.exports = class WebhookCommand extends Command { async run(msg, { content }) { try { if (msg.channel.type === 'text' && msg.deletable) await msg.delete(); - await request - .post(`https://discordapp.com/api/webhooks/${WEBHOOK_ID}/${WEBHOOK_TOKEN}`) - .send({ content }); + await this.client.webhook.send(content); return null; } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/package.json b/package.json index f4749b05..8be20228 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "88.1.1", + "version": "88.1.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Client.js b/structures/Client.js index a2839509..a924caf3 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -1,10 +1,13 @@ const { CommandoClient } = require('discord.js-commando'); +const { WebhookClient } = require('discord.js'); const PokemonStore = require('./PokemonStore'); +const { XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN } = process.env; module.exports = class XiaoClient extends CommandoClient { constructor(options) { super(options); + this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableEveryone: true }); this.pokemon = new PokemonStore(); } };