Skip to content

Commit

Permalink
fix(Split/Webhook): readd message chunk sending and fix webhook avata…
Browse files Browse the repository at this point in the history
…r/username (#2085)
  • Loading branch information
SpaceEEC authored and iCrawl committed Nov 6, 2017
1 parent 21d09f3 commit 05a41b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ class Webhook {

const { data, files } = await createMessage(this, options);

if (data.content instanceof Array) {
const messages = [];
for (let i = 0; i < data.content.length; i++) {
const opt = i === data.content.length - 1 ? { embeds: data.embeds, files } : {};
Object.assign(opt, { avatarURL: data.avatar_url, content: data.content[i], username: data.username });
// eslint-disable-next-line no-await-in-loop
const message = await this.send(data.content[i], opt);
messages.push(message);
}
return messages;
}


return this.client.api.webhooks(this.id, this.token).post({
data, files,
query: { wait: true },
Expand Down
11 changes: 4 additions & 7 deletions src/structures/shared/CreateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = async function createMessage(channel, options) {
const User = require('../User');
const GuildMember = require('../GuildMember');
const Webhook = require('../Webhook');
const WebhookClient = require('../../client/WebhookClient');

const webhook = channel instanceof Webhook;
const webhook = channel instanceof Webhook || channel instanceof WebhookClient;

if (typeof options.nonce !== 'undefined') {
options.nonce = parseInt(options.nonce);
Expand Down Expand Up @@ -88,15 +89,11 @@ module.exports = async function createMessage(channel, options) {
return file;
})
));
delete options.files;
}

if (webhook) {
if (!options.username) options.username = this.name;
if (options.avatarURL) {
options.avatar_url = options.avatarURL;
options.avatarURL = null;
}
if (options.avatarURL) options.avatar_url = options.avatarURL;
}

return { data: {
Expand All @@ -106,6 +103,6 @@ module.exports = async function createMessage(channel, options) {
embed: options.embed,
embeds: options.embeds,
username: options.username,
avatar_url: options.avatarURL,
avatar_url: options.avatar_url,
}, files };
};
11 changes: 11 additions & 0 deletions src/structures/shared/SendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ module.exports = async function sendMessage(channel, options) { // eslint-disabl

const { data, files } = await createMessage(channel, options);

if (data.content instanceof Array) {
const messages = [];
for (let i = 0; i < data.content.length; i++) {
const opt = i === data.content.length - 1 ? { tts: data.tts, embed: data.embed, files } : { tts: data.tts };
// eslint-disable-next-line no-await-in-loop
const message = await channel.send(data.content[i], opt);
messages.push(message);
}
return messages;
}

return channel.client.api.channels[channel.id].messages.post({ data, files })
.then(d => channel.client.actions.MessageCreate.handle(d).message);
};

0 comments on commit 05a41b5

Please sign in to comment.