summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-29 17:37:31 -0700
committer8cy <[email protected]>2020-04-29 17:37:31 -0700
commit30f2e6293defe4fa4090a009c9a9032c695630e3 (patch)
tree96406f0483073b209d72944c3c099858b51004c5 /src
parentadd contact cmds, qol updates/ formatting, v9.1.0 (diff)
downloaddep-core-30f2e6293defe4fa4090a009c9a9032c695630e3.tar.xz
dep-core-30f2e6293defe4fa4090a009c9a9032c695630e3.zip
The Memeification, v9.2.0
- fix goodbye - add more models - formatting - uncomment error loggers
Diffstat (limited to 'src')
-rw-r--r--src/assets/json/meme.json15
-rw-r--r--src/assets/json/month.json14
-rw-r--r--src/bot.ts8
-rw-r--r--src/commands/minecraft/getbody.ts2
-rw-r--r--src/commands/minecraft/getminime.ts4
-rw-r--r--src/commands/server/quotemessage.ts2
-rw-r--r--src/commands/utility/csgoserverstatus.ts2
-rw-r--r--src/commands/utility/gmodserverstatus.ts2
-rw-r--r--src/commands/utility/rustserverstatus.ts2
-rw-r--r--src/commands/utility/starboundserverstatus.ts2
-rw-r--r--src/config.json2
-rw-r--r--src/models/Client.ts26
-rw-r--r--src/models/Command.ts4
-rw-r--r--src/models/MemePoster.ts39
-rw-r--r--src/models/commands/AutoReply.ts17
-rw-r--r--src/models/commands/ImgurAlbum.ts43
-rw-r--r--src/types/image.ts38
-rw-r--r--src/types/month.ts21
-rw-r--r--src/utils/Canvas.ts183
19 files changed, 412 insertions, 14 deletions
diff --git a/src/assets/json/meme.json b/src/assets/json/meme.json
new file mode 100644
index 0000000..02687e0
--- /dev/null
+++ b/src/assets/json/meme.json
@@ -0,0 +1,15 @@
+[
+ "memes",
+ "wholesomememes",
+ "tumblr",
+ "meirl",
+ "historymemes",
+ "animemes",
+ "programmerhumor",
+ "programmeranimemes",
+ "bikinibottomtwitter",
+ "prequelmemes",
+ "mothmemes",
+ "meme",
+ "PoliticalHumor"
+] \ No newline at end of file
diff --git a/src/assets/json/month.json b/src/assets/json/month.json
new file mode 100644
index 0000000..d02be0a
--- /dev/null
+++ b/src/assets/json/month.json
@@ -0,0 +1,14 @@
+[
+ "january",
+ "february",
+ "march",
+ "april",
+ "may",
+ "june",
+ "july",
+ "august",
+ "september",
+ "october",
+ "november",
+ "december"
+] \ No newline at end of file
diff --git a/src/bot.ts b/src/bot.ts
index f06742a..e42197a 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -3,6 +3,7 @@ import { CommandoClient } from 'discord.js-commando';
//import WS from './ws/ws';
import Welcome from './models/welcome.js';
import Goodbye from './models/goodbye.js';
+require('dotenv').config()
import mongo from 'mongoose';
mongo.connect('mongodb://sin:[email protected]:47107/heroku_4qrjvmb9', { useNewUrlParser: true, useUnifiedTopology: true })
import path from 'path';
@@ -68,6 +69,7 @@ client.once('ready', () => {
client.on('error', console.error);
//client.on('debug', console.debug);
+client.on('warn', console.warn)
client.on('guildCreate', guild => {
console.log(`Joined server: ${guild.name}`)
@@ -84,20 +86,20 @@ client.on('guildMemberAdd', member => {
} else if (!guild) {
return
} else if (guild) {
- member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has joined **${member.guild.name}**! ` + emoji.random())
+ member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has joined **${member.guild.name}** the server! ` + emoji.random())
} else {
return
}
})
})
client.on('guildMemberRemove', member => {
- Welcome.findOne({ guildID: member.guild.id }, async (error, guild) => {
+ Goodbye.findOne({ guildID: member.guild.id }, async (error, guild) => {
if (error) {
console.log(error)
} else if (!guild) {
return
} else if (guild) {
- member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has joined **${member.guild.name}**! ` + emoji.random())
+ member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has left **${member.guild.name}** the server! ` + emoji.random())
} else {
return
}
diff --git a/src/commands/minecraft/getbody.ts b/src/commands/minecraft/getbody.ts
index 3fb6eec..d33192b 100644
--- a/src/commands/minecraft/getbody.ts
+++ b/src/commands/minecraft/getbody.ts
@@ -39,7 +39,7 @@ module.exports = class GetBodyMinecraft extends Command {
.setAuthor(uUsername, `https://minotar.net/body/${encodeURIComponent(uUsername)}`)
.setImage(`https://minotar.net/body/${encodeURIComponent(uUsername)}`)
- //console.debug(`URL for ${uUsername}:`, emb.image?.url)
+ console.debug(`URL for ${uUsername}:`, emb.image?.url)
msg.reply(emb)
}
}; \ No newline at end of file
diff --git a/src/commands/minecraft/getminime.ts b/src/commands/minecraft/getminime.ts
index c948d38..13352f0 100644
--- a/src/commands/minecraft/getminime.ts
+++ b/src/commands/minecraft/getminime.ts
@@ -40,7 +40,7 @@ module.exports = class GetMiniMeMinecraft extends Command {
});
}
async run(msg: CommandoMessage, { uUsername, uTrans }) {
- //console.debug('Transparency value:', uTrans)
+ console.debug('Transparency value:', uTrans)
let emb = new MessageEmbed()
.setColor(0xFFCC4D)
@@ -53,7 +53,7 @@ module.exports = class GetMiniMeMinecraft extends Command {
emb.setImage(`http://avatar.yourminecraftservers.com/avatar/rad/steve/tall/128/${encodeURIComponent(username)}.png`)
}
- //console.debug(`Image URL for ${uUsername}: ${emb.image?.url}`)
+ console.debug(`Image URL for ${uUsername}: ${emb.image?.url}`)
msg.reply(emb)
}
}; \ No newline at end of file
diff --git a/src/commands/server/quotemessage.ts b/src/commands/server/quotemessage.ts
index 7dc2965..315c581 100644
--- a/src/commands/server/quotemessage.ts
+++ b/src/commands/server/quotemessage.ts
@@ -49,7 +49,7 @@ module.exports = class QuoteMessageServer extends Command {
}
])
- // check if msg had content
+ // check if msg had content
console.debug('Does the message have content:', Boolean(mMsg.content))
if (mMsg.content) emb.setDescription(tt(mMsg.content))
diff --git a/src/commands/utility/csgoserverstatus.ts b/src/commands/utility/csgoserverstatus.ts
index 39b5c81..eba0aad 100644
--- a/src/commands/utility/csgoserverstatus.ts
+++ b/src/commands/utility/csgoserverstatus.ts
@@ -67,7 +67,7 @@ module.exports = class CSGOServerStatusUtility extends Command {
.catch(err => {
if (err === 'UDP Watchdog Timeout') return msg.reply('Server timed out, it\'s probably offline. ' + emoji.random())
- //console.error(err)
+ console.error(err)
return msg.reply('Woops, an unknown error has occured. ' + emoji.random())
})
} finally {
diff --git a/src/commands/utility/gmodserverstatus.ts b/src/commands/utility/gmodserverstatus.ts
index f7d3b35..cf59d4b 100644
--- a/src/commands/utility/gmodserverstatus.ts
+++ b/src/commands/utility/gmodserverstatus.ts
@@ -66,7 +66,7 @@ module.exports = class GModServerStatusUtility extends Command {
.catch(err => {
if (err === 'UDP Watchdog Timeout') return msg.reply('Server timed out, it\'s probably offline. ' + emoji.random())
- //console.error(err)
+ console.error(err)
return msg.reply('Woops, an unknown error has occured. ' + emoji.random())
})
} finally {
diff --git a/src/commands/utility/rustserverstatus.ts b/src/commands/utility/rustserverstatus.ts
index bce83cb..f7f58bc 100644
--- a/src/commands/utility/rustserverstatus.ts
+++ b/src/commands/utility/rustserverstatus.ts
@@ -66,7 +66,7 @@ module.exports = class RustServerStatusUtility extends Command {
.catch(err => {
if (err === 'UDP Watchdog Timeout') return msg.reply('Server timed out, it\'s probably offline. ' + emoji.random())
- //console.error(err)
+ console.error(err)
return msg.reply('Woops, an unknown error has occured. ' + emoji.random())
})
} finally {
diff --git a/src/commands/utility/starboundserverstatus.ts b/src/commands/utility/starboundserverstatus.ts
index 963f226..eaddfc8 100644
--- a/src/commands/utility/starboundserverstatus.ts
+++ b/src/commands/utility/starboundserverstatus.ts
@@ -85,7 +85,7 @@ module.exports = class StarboundServerStatusUtility extends Command {
.catch(err => {
if (err === 'UDP Watchdog Timeout') return msg.reply('Server timed out, it\'s probably offline. ' + emoji.random())
- //console.error(err)
+ console.error(err)
return msg.reply('Woops, an unknown error has occured. ' + emoji.random())
})
} finally {
diff --git a/src/config.json b/src/config.json
index 1f9cba8..ea1c0e6 100644
--- a/src/config.json
+++ b/src/config.json
@@ -1,7 +1,7 @@
{
"secret":"Njk5NDczMjYzOTk4MjcxNDg5.XpU5oQ.btZuxVudhNllSQY6CxrXXtMJm9A",
"yt-api-key":"AIzaSyCeG1lQAeInv4vjFv_eTL9IFAFNdQC9Nk8",
- "version":"9.1.0",
+ "version":"9.2.0",
"fortniteTrackerNetworkToken": "4cf21f95-5f1a-412a-b4a7-e5424adc314a",
"maxMultipler": 100,
"minMultipler": 1.01
diff --git a/src/models/Client.ts b/src/models/Client.ts
new file mode 100644
index 0000000..c24bcd9
--- /dev/null
+++ b/src/models/Client.ts
@@ -0,0 +1,26 @@
+// import { CommandoClient } from 'discord.js-commando';
+// import { WebhookClient } from 'discord.js';
+// import Collection from '@discordjs/collection';
+// import winston from 'winston';
+// const PokemonStore = require('./pokemon/PokemonStore');
+// import MemePoster from './MemePoster.js'
+// const { UWUFIER_WEBHOOK_ID, UWUFIER_WEBHOOK_TOKEN } = process.env;
+
+// module.exports = class UwufierClient extends CommandoClient {
+// constructor(options) {
+// super(options);
+
+// this.logger = winston.createLogger({
+// transports: [new winston.transports.Console()],
+// format: winston.format.combine(
+// winston.format.timestamp({ format: 'MM/DD/YYYY HH:mm:ss' }),
+// winston.format.printf(log => `[${log.timestamp}] [${log.level.toUpperCase()}]: ${log.message}`)
+// )
+// });
+// this.webhook = new WebhookClient(UWUFIER_WEBHOOK_ID, UWUFIER_WEBHOOK_TOKEN, { disableEveryone: true });
+// this.pokemon = new PokemonStore();
+// this.memePoster = new MemePoster(this);
+// this.games = new Collection();
+// this.phone = new Collection();
+// }
+// }; \ No newline at end of file
diff --git a/src/models/Command.ts b/src/models/Command.ts
index a6d6700..9a304a8 100644
--- a/src/models/Command.ts
+++ b/src/models/Command.ts
@@ -8,8 +8,8 @@ module.exports = class UwufierCommand extends Command {
this.throttling = info.throttling || { usages: 1, duration: 2 };
this.credit = info.credit || [];
this.credit.push({
- name: 'Dragon Fire',
- url: 'https://github.com/dragonfire535',
+ name: 'Sin',
+ url: 'https://github.com/8cy',
reason: 'Code'
});
}
diff --git a/src/models/MemePoster.ts b/src/models/MemePoster.ts
new file mode 100644
index 0000000..27ff726
--- /dev/null
+++ b/src/models/MemePoster.ts
@@ -0,0 +1,39 @@
+// const { POSTER_ID, POSTER_TOKEN, POSTER_TIME } = process.env;
+// import request from 'node-superfetch';
+// import { embedURL } from '../utils/Util.js';
+// import subreddits from '../assets/json/meme.json'
+// const types = ['image', 'rich:video'];
+
+// module.exports = class MemePoster {
+// constructor(client) {
+// Object.defineProperty(this, 'client', { value: client });
+
+// this.id = POSTER_ID;
+// this.token = POSTER_TOKEN;
+// this.time = Number.parseFloat(POSTER_TIME) || 3.6e+6;
+// }
+// async post() {
+// try {
+// const subreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
+// const post = await this.fetchMeme(subreddit);
+// if (!post) return;
+// const url = embedURL(post.title, `<https://www.reddit.com${post.permalink}>`);
+// await request
+// .post(`https://discordapp.com/api/webhooks/${this.id}/${this.token}`)
+// .send({ content: `**r/${subreddit}** ${url}\n${post.url}` });
+// } catch (err) {
+// this.client.logger.error(err);
+// }
+// }
+// async fetchMeme(subreddit) {
+// const { body } = await request
+// .get(`https://www.reddit.com/r/${subreddit}/hot.json`)
+// .query({ limit: 100 });
+// const posts = body.data.children.filter(post => {
+// if (!post.data) return false;
+// return types.includes(post.data.post_hint) && post.data.url && post.data.title && !post.data.over_18;
+// });
+// if (!posts.length) return null;
+// return posts[Math.floor(Math.random() * posts.length)].data;
+// }
+// }; \ No newline at end of file
diff --git a/src/models/commands/AutoReply.ts b/src/models/commands/AutoReply.ts
new file mode 100644
index 0000000..fbc7e46
--- /dev/null
+++ b/src/models/commands/AutoReply.ts
@@ -0,0 +1,17 @@
+// import Command from '../Command.js'
+
+// module.exports = class AutoReplyCommand extends Command {
+// constructor(client, info) {
+// super(client, info);
+
+// this.reply = info.reply || false;
+// }
+
+// run(msg, args, fromPattern) {
+// return this.reply ? msg.reply(this.generateText(fromPattern)) : msg.say(this.generateText(fromPattern));
+// }
+
+// generateText() {
+// throw new Error('The generateText method is required.');
+// }
+// }; \ No newline at end of file
diff --git a/src/models/commands/ImgurAlbum.ts b/src/models/commands/ImgurAlbum.ts
new file mode 100644
index 0000000..199c2a6
--- /dev/null
+++ b/src/models/commands/ImgurAlbum.ts
@@ -0,0 +1,43 @@
+// import request from 'node-superfetch';
+// import Command from '../Command.js'
+// const { IMGUR_KEY } = process.env;
+
+// module.exports = class ImgurAlbumCommand extends Command {
+// constructor(client, info) {
+// super(client, info);
+
+// this.albumID = info.albumID;
+// this.cache = null;
+// this.credit.push({
+// name: 'Imgur',
+// url: 'https://imgur.com/',
+// reason: 'API',
+// reasonURL: 'https://apidocs.imgur.com/'
+// });
+// }
+
+// async run(msg, { user }) {
+// try {
+// const image = await this.random();
+// if (!image) return msg.reply('This album has no images...');
+// return msg.say(this.generateText(msg, user), { files: [image] });
+// } catch (err) {
+// return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+// }
+// }
+
+// generateText() {
+// throw new Error('The generateText method is required.');
+// }
+
+// async random() {
+// if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)];
+// const { body } = await request
+// .get(`https://api.imgur.com/3/album/${this.albumID}`)
+// .set({ Authorization: `Client-ID ${IMGUR_KEY}` });
+// if (!body.data.images.length) return null;
+// this.cache = body.data.images.map(image => image.link);
+// setTimeout(() => { this.cache = null; }, 3.6e+6);
+// return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
+// }
+// }; \ No newline at end of file
diff --git a/src/types/image.ts b/src/types/image.ts
new file mode 100644
index 0000000..d872c44
--- /dev/null
+++ b/src/types/image.ts
@@ -0,0 +1,38 @@
+import { ArgumentType } from 'discord.js-commando';
+const fileTypeRe = /\.(jpe?g|png|gif)$/i;
+import request from 'node-superfetch';
+
+module.exports = class ImageArgumentType extends ArgumentType {
+ constructor(client) {
+ super(client, 'image');
+ }
+ async validate(value, msg, arg) {
+ const attachment = msg.attachments.first();
+ if (attachment) {
+ if (!attachment.height || !attachment.width) return false;
+ if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.';
+ if (!fileTypeRe.test(attachment.name)) return 'Please only send PNG, JPG, or GIF format images.';
+ return true;
+ }
+ if (fileTypeRe.test(value.toLowerCase())) {
+ try {
+ await request.get(value);
+ return true;
+ } catch {
+ return false;
+ }
+ }
+ return this.client.registry.types.get('user')?.validate(value, msg, arg);
+ }
+ async parse(value, msg, arg) {
+ const attachment = msg.attachments.first();
+ if (attachment) return attachment.url;
+ if (fileTypeRe.test(value.toLowerCase())) return value;
+ const user = await this.client.registry.types.get('user')?.parse(value, msg, arg);
+ return user.displayAvatarURL({ format: 'png', size: 512 });
+ }
+ isEmpty(value, msg, arg) {
+ if (msg.attachments.size) return false;
+ return this.client.registry.types.get('user')?.isEmpty(value, msg, arg);
+ }
+}; \ No newline at end of file
diff --git a/src/types/month.ts b/src/types/month.ts
new file mode 100644
index 0000000..6e85d8f
--- /dev/null
+++ b/src/types/month.ts
@@ -0,0 +1,21 @@
+import { ArgumentType } from 'discord.js-commando';
+import months from '../assets/json/month.json'
+
+module.exports = class MonthArgumentType extends ArgumentType {
+ constructor(client) {
+ super(client, 'month');
+ }
+
+ validate(value) {
+ const num = Number.parseInt(value, 10);
+ if (num > 0 && num < 13) return true;
+ if (months.includes(value.toLowerCase())) return true;
+ return false;
+ }
+
+ parse(value) {
+ const num = Number.parseInt(value, 10);
+ if (!Number.isNaN(num)) return num;
+ return months.indexOf(value.toLowerCase()) + 1;
+ }
+}; \ No newline at end of file
diff --git a/src/utils/Canvas.ts b/src/utils/Canvas.ts
new file mode 100644
index 0000000..4cbcac6
--- /dev/null
+++ b/src/utils/Canvas.ts
@@ -0,0 +1,183 @@
+import { createCanvas } from 'canvas'
+
+module.exports = class CanvasUtil {
+ static greyscale(ctx, x, y, width, height) {
+ const data = ctx.getImageData(x, y, width, height);
+ for (let i = 0; i < data.data.length; i += 4) {
+ const brightness = (0.34 * data.data[i]) + (0.5 * data.data[i + 1]) + (0.16 * data.data[i + 2]);
+ data.data[i] = brightness;
+ data.data[i + 1] = brightness;
+ data.data[i + 2] = brightness;
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static invert(ctx, x, y, width, height) {
+ const data = ctx.getImageData(x, y, width, height);
+ for (let i = 0; i < data.data.length; i += 4) {
+ data.data[i] = 255 - data.data[i];
+ data.data[i + 1] = 255 - data.data[i + 1];
+ data.data[i + 2] = 255 - data.data[i + 2];
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static silhouette(ctx, x, y, width, height) {
+ const data = ctx.getImageData(x, y, width, height);
+ for (let i = 0; i < data.data.length; i += 4) {
+ data.data[i] = 0;
+ data.data[i + 1] = 0;
+ data.data[i + 2] = 0;
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static sepia(ctx, x, y, width, height) {
+ const data = ctx.getImageData(x, y, width, height);
+ for (let i = 0; i < data.data.length; i += 4) {
+ const brightness = (0.34 * data.data[i]) + (0.5 * data.data[i + 1]) + (0.16 * data.data[i + 2]);
+ data.data[i] = brightness + 100;
+ data.data[i + 1] = brightness + 50;
+ data.data[i + 2] = brightness;
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static contrast(ctx, x, y, width, height) {
+ const data = ctx.getImageData(x, y, width, height);
+ const factor = (259 / 100) + 1;
+ const intercept = 128 * (1 - factor);
+ for (let i = 0; i < data.data.length; i += 4) {
+ data.data[i] = (data.data[i] * factor) + intercept;
+ data.data[i + 1] = (data.data[i + 1] * factor) + intercept;
+ data.data[i + 2] = (data.data[i + 2] * factor) + intercept;
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static distort(ctx, amplitude, x, y, width, height, strideLevel = 4) {
+ const data = ctx.getImageData(x, y, width, height);
+ const temp = ctx.getImageData(x, y, width, height);
+ const stride = width * strideLevel;
+ for (let i = 0; i < width; i++) {
+ for (let j = 0; j < height; j++) {
+ const xs = Math.round(amplitude * Math.sin(2 * Math.PI * 3 * (j / height)));
+ const ys = Math.round(amplitude * Math.cos(2 * Math.PI * 3 * (i / width)));
+ const dest = (j * stride) + (i * strideLevel);
+ const src = ((j + ys) * stride) + ((i + xs) * strideLevel);
+ data.data[dest] = temp.data[src];
+ data.data[dest + 1] = temp.data[src + 1];
+ data.data[dest + 2] = temp.data[src + 2];
+ }
+ }
+ ctx.putImageData(data, x, y);
+ return ctx;
+ }
+
+ static hasAlpha(image) {
+ const canvas = createCanvas(image.width, image.height);
+ const ctx = canvas.getContext('2d');
+ ctx.drawImage(image, 0, 0);
+ const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
+ let hasAlphaPixels = false;
+ for (let i = 3; i < data.data.length; i += 4) {
+ if (data.data[i] < 255) {
+ hasAlphaPixels = true;
+ break;
+ }
+ }
+ return hasAlphaPixels;
+ }
+
+ static drawImageWithTint(ctx, image, color, x, y, width, height) {
+ const { fillStyle, globalAlpha } = ctx;
+ ctx.fillStyle = color;
+ ctx.drawImage(image, x, y, width, height);
+ ctx.globalAlpha = 0.5;
+ ctx.fillRect(x, y, width, height);
+ ctx.fillStyle = fillStyle;
+ ctx.globalAlpha = globalAlpha;
+ }
+
+ static shortenText(ctx, text, maxWidth) {
+ let shorten = false;
+ while (ctx.measureText(text).width > maxWidth) {
+ if (!shorten) shorten = true;
+ text = text.substr(0, text.length - 1);
+ }
+ return shorten ? `${text}...` : text;
+ }
+
+ static wrapText(ctx, text, maxWidth) {
+ return new Promise(resolve => {
+ if (ctx.measureText(text).width < maxWidth) return resolve([text]);
+ if (ctx.measureText('W').width > maxWidth) return resolve(null);
+ const words = text.split(' ');
+ const lines = [];
+ let line = '';
+ while (words.length > 0) {
+ let split = false;
+ while (ctx.measureText(words[0]).width >= maxWidth) {
+ const temp = words[0];
+ words[0] = temp.slice(0, -1);
+ if (split) {
+ words[1] = `${temp.slice(-1)}${words[1]}`;
+ } else {
+ split = true;
+ words.splice(1, 0, temp.slice(-1));
+ }
+ }
+ if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) {
+ line += `${words.shift()} `;
+ } else {
+ lines.push(line.trim());
+ line = '';
+ }
+ if (words.length === 0) lines.push(line.trim());
+ }
+ return resolve(lines);
+ });
+ }
+
+ static centerImage(base, data) {
+ const dataRatio = data.width / data.height;
+ const baseRatio = base.width / base.height;
+ let { width, height } = data;
+ let x = 0;
+ let y = 0;
+ if (baseRatio < dataRatio) {
+ height = data.height;
+ width = base.width * (height / base.height);
+ x = (data.width - width) / 2;
+ y = 0;
+ } else if (baseRatio > dataRatio) {
+ width = data.width;
+ height = base.height * (width / base.width);
+ x = 0;
+ y = (data.height - height) / 2;
+ }
+ return { x, y, width, height };
+ }
+
+ static centerImagePart(data, maxWidth, maxHeight, widthOffset, heightOffest) {
+ let { width, height } = data;
+ if (width > maxWidth) {
+ const ratio = maxWidth / width;
+ width = maxWidth;
+ height *= ratio;
+ }
+ if (height > maxHeight) {
+ const ratio = maxHeight / height;
+ height = maxHeight;
+ width *= ratio;
+ }
+ const x = widthOffset + ((maxWidth / 2) - (width / 2));
+ const y = heightOffest + ((maxHeight / 2) - (height / 2));
+ return { x, y, width, height };
+ }
+}; \ No newline at end of file