tinify webpacks (#1975)

* tinify webpack

* meme

* fix long version

* more changes

* even smoler

* fix up logic

* fix build

* undo changes to user agent manager because its not webpack'd anymore

* the heck

* fix stupid

* clean up browser rules

* typo
This commit is contained in:
Gus Caplan
2017-09-26 00:18:12 -05:00
committed by Crawl
parent 4d4d2f2db7
commit 27ccad1f1c
21 changed files with 85 additions and 80 deletions

View File

@@ -178,7 +178,7 @@ class ClientUser extends User {
* .catch(console.error);
*/
async setAvatar(avatar) {
return this.edit({ avatar: await DataResolver.resolveImage(avatar, this.client.browser) });
return this.edit({ avatar: await DataResolver.resolveImage(avatar) });
}
/**
@@ -294,7 +294,7 @@ class ClientUser extends User {
);
}
return DataResolver.resolveImage(icon, this.client.browser)
return DataResolver.resolveImage(icon)
.then(data => this.createGuild(name, { region, icon: data || null }));
}

View File

@@ -161,7 +161,7 @@ class GroupDMChannel extends Channel {
* @returns {Promise<GroupDMChannel>}
*/
async setIcon(icon) {
return this.edit({ icon: await DataResolver.resolveImage(icon, this.client.browser) });
return this.edit({ icon: await DataResolver.resolveImage(icon) });
}
/**

View File

@@ -3,7 +3,7 @@ const GuildAuditLogs = require('./GuildAuditLogs');
const Webhook = require('./Webhook');
const GuildMember = require('./GuildMember');
const VoiceRegion = require('./VoiceRegion');
const { ChannelTypes, Events } = require('../util/Constants');
const { ChannelTypes, Events, browser } = require('../util/Constants');
const Collection = require('../util/Collection');
const Util = require('../util/Util');
const DataResolver = require('../util/DataResolver');
@@ -315,7 +315,7 @@ class Guild extends Base {
* @readonly
*/
get voiceConnection() {
if (this.client.browser) return null;
if (browser) return null;
return this.client.voice.connections.get(this.id) || null;
}
@@ -717,7 +717,7 @@ class Guild extends Base {
* .catch(console.error);
*/
async setIcon(icon, reason) {
return this.edit({ icon: await DataResolver.resolveImage(icon, this.client.browser), reason });
return this.edit({ icon: await DataResolver.resolveImage(icon), reason });
}
/**
@@ -747,7 +747,7 @@ class Guild extends Base {
* .catch(console.error);
*/
async setSplash(splash, reason) {
return this.edit({ splash: await DataResolver.resolveImage(splash, this.client.browser), reason });
return this.edit({ splash: await DataResolver.resolveImage(splash), reason });
}
/**
@@ -1036,7 +1036,7 @@ class Guild extends Base {
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji);
}
return DataResolver.resolveImage(attachment, this.client.browser)
return DataResolver.resolveImage(attachment)
.then(image => this.createEmoji(image, name, { roles, reason }));
}

View File

@@ -64,7 +64,7 @@ class TextChannel extends GuildChannel {
*/
async createWebhook(name, { avatar, reason } = {}) {
if (typeof avatar === 'string' && !avatar.startsWith('data:')) {
avatar = await DataResolver.resolveImage(avatar, this.client.browser);
avatar = await DataResolver.resolveImage(avatar);
}
return this.client.api.channels[this.id].webhooks.post({ data: {
name, avatar,

View File

@@ -1,5 +1,6 @@
const GuildChannel = require('./GuildChannel');
const Collection = require('../util/Collection');
const { browser } = require('../util/Constants');
const { Error } = require('../errors');
/**
@@ -59,7 +60,7 @@ class VoiceChannel extends GuildChannel {
* @readonly
*/
get joinable() {
if (this.client.browser) return false;
if (browser) return false;
if (!this.permissionsFor(this.client.user).has('CONNECT')) return false;
if (this.full && !this.permissionsFor(this.client.user).has('MOVE_MEMBERS')) return false;
return true;
@@ -115,7 +116,7 @@ class VoiceChannel extends GuildChannel {
* .catch(console.error);
*/
join() {
if (this.client.browser) return Promise.reject(new Error('VOICE_NO_BROWSER'));
if (browser) return Promise.reject(new Error('VOICE_NO_BROWSER'));
return this.client.voice.joinChannel(this);
}
@@ -126,7 +127,7 @@ class VoiceChannel extends GuildChannel {
* voiceChannel.leave();
*/
leave() {
if (this.client.browser) return;
if (browser) return;
const connection = this.client.voice.connections.get(this.guild.id);
if (connection && connection.channel.id === this.id) connection.disconnect();
}

View File

@@ -1,9 +1,9 @@
const path = require('path');
const Util = require('../util/Util');
const DataResolver = require('../util/DataResolver');
const Embed = require('./MessageEmbed');
const MessageAttachment = require('./MessageAttachment');
const MessageEmbed = require('./MessageEmbed');
const { browser } = require('../util/Constants');
/**
* Represents a webhook.
@@ -151,14 +151,14 @@ class Webhook {
if (options.files) {
for (let i = 0; i < options.files.length; i++) {
let file = options.files[i];
if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file };
if (typeof file === 'string' || (!browser && Buffer.isBuffer(file))) file = { attachment: file };
if (!file.name) {
if (typeof file.attachment === 'string') {
file.name = path.basename(file.attachment);
file.name = Util.basename(file.attachment);
} else if (file.attachment && file.attachment.path) {
file.name = path.basename(file.attachment.path);
file.name = Util.basename(file.attachment.path);
} else if (file instanceof MessageAttachment) {
file = { attachment: file.file, name: path.basename(file.file) || 'file.jpg' };
file = { attachment: file.file, name: Util.basename(file.file) || 'file.jpg' };
} else {
file.name = 'file.jpg';
}
@@ -169,7 +169,7 @@ class Webhook {
}
return Promise.all(options.files.map(file =>
DataResolver.resolveFile(file.attachment, this.client.browser).then(resource => {
DataResolver.resolveFile(file.attachment).then(resource => {
file.file = resource;
return file;
})
@@ -249,9 +249,7 @@ class Webhook {
*/
edit({ name = this.name, avatar }, reason) {
if (avatar && (typeof avatar === 'string' && !avatar.startsWith('data:'))) {
return DataResolver.resolveImage(avatar, this.client.browser).then(image =>
this.edit({ name, avatar: image }, reason)
);
return DataResolver.resolveImage(avatar).then(image => this.edit({ name, avatar: image }, reason));
}
return this.client.api.webhooks(this.id, this.token).patch({
data: { name, avatar },

View File

@@ -1,6 +1,7 @@
const path = require('path');
const MessageCollector = require('../MessageCollector');
const Shared = require('../shared');
const Util = require('../../util/Util');
const { browser } = require('../../util/Constants');
const Snowflake = require('../../util/Snowflake');
const Collection = require('../../util/Collection');
const DataResolver = require('../../util/DataResolver');
@@ -106,14 +107,14 @@ class TextBasedChannel {
if (options.files) {
for (let i = 0; i < options.files.length; i++) {
let file = options.files[i];
if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file };
if (typeof file === 'string' || (!browser && Buffer.isBuffer(file))) file = { attachment: file };
if (!file.name) {
if (typeof file.attachment === 'string') {
file.name = path.basename(file.attachment);
file.name = Util.basename(file.attachment);
} else if (file.attachment && file.attachment.path) {
file.name = path.basename(file.attachment.path);
file.name = Util.basename(file.attachment.path);
} else if (file instanceof MessageAttachment) {
file = { attachment: file.file, name: path.basename(file.file) || 'file.jpg' };
file = { attachment: file.file, name: Util.basename(file.file) || 'file.jpg' };
} else {
file.name = 'file.jpg';
}
@@ -124,7 +125,7 @@ class TextBasedChannel {
}
return Promise.all(options.files.map(file =>
DataResolver.resolveFile(file.attachment, this.client.browser).then(resource => {
DataResolver.resolveFile(file.attachment).then(resource => {
file.file = resource;
return file;
})