|
1 |
| -const { Command } = require('discord-akairo'); |
2 |
| -const Canvas = require('canvas'); |
3 |
| -const fetch = require('node-fetch'); |
4 |
| -const parseInput = require('../util/parseInput.js'); |
5 |
| -const validators = require('../util/validators.js'); |
6 |
| -const regexes = require('../util/regexes.js'); |
| 1 | +const { Command } = require('discord-akairo') |
| 2 | +const Canvas = require('canvas') |
| 3 | +const fetch = require('node-fetch') |
| 4 | +const parseInput = require('../util/parseInput.js') |
| 5 | +const validators = require('../util/validators.js') |
| 6 | +const regexes = require('../util/regexes.js') |
7 | 7 |
|
8 | 8 | module.exports = class AddCommand extends Command {
|
9 | 9 | constructor() {
|
@@ -33,122 +33,122 @@ module.exports = class AddCommand extends Command {
|
33 | 33 | ],
|
34 | 34 | },
|
35 | 35 | },
|
36 |
| - }); |
| 36 | + }) |
37 | 37 | }
|
38 | 38 |
|
39 | 39 | async exec(message, args) {
|
40 |
| - let validatedArgs; |
41 |
| - const { hubServer } = this.client; |
| 40 | + let validatedArgs |
| 41 | + const { hubServer } = this.client |
42 | 42 |
|
43 | 43 | try {
|
44 |
| - validatedArgs = await this.validate(message, args); |
| 44 | + validatedArgs = await this.validate(message, args) |
45 | 45 | } catch (error) {
|
46 |
| - return message.channel.send(error.message || error); |
| 46 | + return message.channel.send(error.message || error) |
47 | 47 | }
|
48 | 48 |
|
49 |
| - let { name, url, imageData } = validatedArgs; |
| 49 | + let { name, url, imageData } = validatedArgs |
50 | 50 |
|
51 | 51 | if (message.util.parsed.alias === 'reverse' || args.reverse) {
|
52 | 52 | if (!name.toLowerCase().endsWith('reverse')) {
|
53 |
| - name = await this.modifyEmojiName(message, name); |
| 53 | + name = await this.modifyEmojiName(message, name) |
54 | 54 | }
|
55 | 55 |
|
56 |
| - url = this.reverseImage(await imageData.buffer(), url); |
| 56 | + url = this.reverseImage(await imageData.buffer(), url) |
57 | 57 | }
|
58 | 58 |
|
59 | 59 | try {
|
60 |
| - await hubServer.polls.emoji.create({ message, name, url }); |
| 60 | + await hubServer.polls.emoji.create({ message, name, url }) |
61 | 61 | } catch (error) {
|
62 |
| - const owner = await this.client.users.fetch(this.client.ownerID); |
63 |
| - const anger = ['tch', 'meguAngry', 'angry', 'nyanrage', 'WeebRage']; |
64 |
| - const angryEmoji = this.client.emojis.cache.filter(emoji => anger.includes(emoji.name)).random(); |
65 |
| - return message.channel.send(`<@${owner.id}>: ${error.message} ${angryEmoji}`); |
| 62 | + const owner = await this.client.users.fetch(this.client.ownerID) |
| 63 | + const anger = ['tch', 'meguAngry', 'angry', 'nyanrage', 'WeebRage'] |
| 64 | + const angryEmoji = this.client.emojis.cache.filter(emoji => anger.includes(emoji.name)).random() |
| 65 | + return message.channel.send(`<@${owner.id}>: ${error.message} ${angryEmoji}`) |
66 | 66 | }
|
67 | 67 |
|
68 |
| - const response = [`Done! Others can now vote on your request in ${hubServer.votingChannel}.`]; |
| 68 | + const response = [`Done! Others can now vote on your request in ${hubServer.votingChannel}.`] |
69 | 69 |
|
70 | 70 | if (message.guild.id !== hubServer.guild.id) {
|
71 |
| - response[0] = `${response[0].slice(0, -1)} in **${hubServer.guild.name}**.`; |
72 |
| - response.push(`If you can\'t open the channel link, send \`${this.handler.prefix}server 1\` for an invite.`); |
| 71 | + response[0] = `${response[0].slice(0, -1)} in **${hubServer.guild.name}**.` |
| 72 | + response.push(`If you can\'t open the channel link, send \`${this.handler.prefix}server 1\` for an invite.`) |
73 | 73 | }
|
74 | 74 |
|
75 |
| - return message.channel.send(response.join('\n')); |
| 75 | + return message.channel.send(response.join('\n')) |
76 | 76 | }
|
77 | 77 |
|
78 | 78 | async validate(message, { name, url }) {
|
79 | 79 | if (!name && !url) {
|
80 | 80 | throw new Error([
|
81 | 81 | 'You need to provide: an emoji, a name and an emoji, a name and an image URL, or a name and an image file!',
|
82 | 82 | `For example: \`${this.handler.prefix}add AiSmug https://i.imgur.com/8jGJzmd.png\`.`,
|
83 |
| - ].join('\n')); |
| 83 | + ].join('\n')) |
84 | 84 | }
|
85 | 85 |
|
86 |
| - const { name: emojiName, url: imageURL } = parseInput.fromAny({ first: name, last: url, attachments: message.attachments }); |
| 86 | + const { name: emojiName, url: imageURL } = parseInput.fromAny({ first: name, last: url, attachments: message.attachments }) |
87 | 87 |
|
88 | 88 | if (emojiName.length < 2 || emojiName.length > 32) {
|
89 |
| - throw new RangeError('An emoji name needs to be between 2 and 32 characters long.'); |
| 89 | + throw new RangeError('An emoji name needs to be between 2 and 32 characters long.') |
90 | 90 | }
|
91 | 91 |
|
92 |
| - const imageData = await fetch(imageURL); |
| 92 | + const imageData = await fetch(imageURL) |
93 | 93 |
|
94 | 94 | if (!imageData.ok) {
|
95 |
| - throw new Error('That image link doesn\'t seem to be working.'); |
| 95 | + throw new Error('That image link doesn\'t seem to be working.') |
96 | 96 | } else if (imageData.headers.get('content-length') > (256 * 1024)) {
|
97 |
| - throw new RangeError('That file surpasses the 256kb file size limit! Please resize it and try again.'); |
| 97 | + throw new RangeError('That file surpasses the 256kb file size limit! Please resize it and try again.') |
98 | 98 | }
|
99 | 99 |
|
100 | 100 | if (regexes.blobInit.test(emojiName) && !regexes.blob.test(emojiName)) {
|
101 |
| - validators.blobs(emojiName, imageURL, imageData); |
| 101 | + validators.blobs(emojiName, imageURL, await imageData.buffer()) |
102 | 102 | }
|
103 | 103 |
|
104 |
| - await validators.duplicates(message, emojiName); |
| 104 | + await validators.duplicates(message, emojiName) |
105 | 105 |
|
106 |
| - return { name: emojiName, url: imageURL, imageData }; |
| 106 | + return { name: emojiName, url: imageURL, imageData } |
107 | 107 | }
|
108 | 108 |
|
109 | 109 | reverseImage(imageData, url) {
|
110 | 110 | if (!regexes.png.test(url)) {
|
111 |
| - throw new RangeError('I can only reverse PNG images!'); |
| 111 | + throw new RangeError('I can only reverse PNG images!') |
112 | 112 | }
|
113 | 113 |
|
114 |
| - const canvas = new Canvas.createCanvas(128, 128); |
115 |
| - const ctx = canvas.getContext('2d'); |
| 114 | + const canvas = new Canvas.createCanvas(128, 128) |
| 115 | + const ctx = canvas.getContext('2d') |
116 | 116 |
|
117 |
| - const image = new Canvas.Image(); |
118 |
| - image.src = imageData; |
| 117 | + const image = new Canvas.Image() |
| 118 | + image.src = imageData |
119 | 119 |
|
120 |
| - canvas.width = image.width; |
121 |
| - canvas.height = image.height; |
| 120 | + canvas.width = image.width |
| 121 | + canvas.height = image.height |
122 | 122 |
|
123 |
| - ctx.translate(canvas.width, 0); |
124 |
| - ctx.scale(-1, 1); |
125 |
| - ctx.drawImage(image, 0, 0); |
| 123 | + ctx.translate(canvas.width, 0) |
| 124 | + ctx.scale(-1, 1) |
| 125 | + ctx.drawImage(image, 0, 0) |
126 | 126 |
|
127 |
| - return canvas.toBuffer(); |
| 127 | + return canvas.toBuffer() |
128 | 128 | }
|
129 | 129 |
|
130 | 130 | async modifyEmojiName(message, name) {
|
131 | 131 | await message.channel.send([
|
132 | 132 | 'Your emoji name doesn\'t end with "reverse". Do you want me to modify it for you?',
|
133 | 133 | '1) Yes, with "reverse" - 2) Yes, with "Reverse" - 3) No',
|
134 |
| - ].join('\n')); |
| 134 | + ].join('\n')) |
135 | 135 |
|
136 |
| - const options = { max: 1, time: 20000, errors: ['time'] }; |
| 136 | + const options = { max: 1, time: 20000, errors: ['time'] } |
137 | 137 | const filter = m => {
|
138 |
| - return ['yes', 'y', 'no', 'n', '1', '2', '3'].includes(m.content.toLowerCase()) && m.author.id === message.author.id; |
139 |
| - }; |
| 138 | + return ['yes', 'y', 'no', 'n', '1', '2', '3'].includes(m.content.toLowerCase()) && m.author.id === message.author.id |
| 139 | + } |
140 | 140 |
|
141 | 141 | try {
|
142 |
| - const responses = await message.channel.awaitMessages(filter, options); |
143 |
| - const response = responses.first().content.toLowerCase(); |
| 142 | + const responses = await message.channel.awaitMessages(filter, options) |
| 143 | + const response = responses.first().content.toLowerCase() |
144 | 144 |
|
145 | 145 | if (response && ['yes', 'y', '1', '2'].includes(response)) {
|
146 |
| - return response !== '2' ? `${name}reverse` : `${name}Reverse`; |
| 146 | + return response !== '2' ? `${name}reverse` : `${name}Reverse` |
147 | 147 | }
|
148 | 148 | } catch (error) {
|
149 |
| - await message.channel.send('You didn\'t reply in time, leaving emoji name as is.'); |
| 149 | + await message.channel.send('You didn\'t reply in time, leaving emoji name as is.') |
150 | 150 | }
|
151 | 151 |
|
152 |
| - return name; |
| 152 | + return name |
153 | 153 | }
|
154 |
| -}; |
| 154 | +} |
0 commit comments