default emoji support for !jumbo

This commit is contained in:
roflmaoqwerty 2020-01-14 18:08:49 +11:00
parent 08c1a2e9ac
commit b092dda079
4 changed files with 72 additions and 28 deletions

View file

@ -548,9 +548,9 @@
} }
}, },
"@types/node": { "@types/node": {
"version": "12.12.5", "version": "12.12.24",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.5.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.24.tgz",
"integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A==" "integrity": "sha512-1Ciqv9pqwVtW6FsIUKSZNB82E5Cu1I2bBTj1xuIHXLe/1zYLl3956Nbhg2MzSYHVfl9/rmanjbQIb7LibfCnug=="
}, },
"@types/oauth": { "@types/oauth": {
"version": "0.9.1", "version": "0.9.1",
@ -627,6 +627,11 @@
"integrity": "sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=", "integrity": "sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=",
"dev": true "dev": true
}, },
"@types/twemoji": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@types/twemoji/-/twemoji-12.1.0.tgz",
"integrity": "sha512-dTHU1ZE83qUlF3oFWrdxKBmOimM+/3o9hzDBszcKjajmNu5G/DjWgQrRNkq+zxeR+zDN030ciAt5qTH+WXBD8A=="
},
"accepts": { "accepts": {
"version": "1.3.7", "version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
@ -2358,6 +2363,26 @@
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="
}, },
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
},
"dependencies": {
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
}
}
},
"fs-minipass": { "fs-minipass": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.0.0.tgz", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.0.0.tgz",
@ -2507,8 +2532,7 @@
"graceful-fs": { "graceful-fs": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
"dev": true
}, },
"has": { "has": {
"version": "1.0.3", "version": "1.0.3",
@ -2924,6 +2948,15 @@
"minimist": "^1.2.0" "minimist": "^1.2.0"
} }
}, },
"jsonfile": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-5.0.0.tgz",
"integrity": "sha512-NQRZ5CRo74MhMMC3/3r5g2k4fjodJ/wh8MxjFbCViWKFjxrnudWSY5vomh+23ZaXzAS7J3fBZIR2dV6WbmfM0w==",
"requires": {
"graceful-fs": "^4.1.6",
"universalify": "^0.1.2"
}
},
"keyv": { "keyv": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",
@ -4965,6 +4998,22 @@
"integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==", "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==",
"optional": true "optional": true
}, },
"twemoji": {
"version": "12.1.4",
"resolved": "https://registry.npmjs.org/twemoji/-/twemoji-12.1.4.tgz",
"integrity": "sha512-e37lUlVijmABF7wPCc09s1kKj3hcpzU8KL5zw2bBDIXOtOr4luLF+ODJaEqca8dZPmLR5ezrJYI93nhPovKBiQ==",
"requires": {
"fs-extra": "^8.0.1",
"jsonfile": "^5.0.0",
"twemoji-parser": "12.1.1",
"universalify": "^0.1.2"
}
},
"twemoji-parser": {
"version": "12.1.1",
"resolved": "https://registry.npmjs.org/twemoji-parser/-/twemoji-parser-12.1.1.tgz",
"integrity": "sha512-XFUB4ReEvPbNPtiuyo/+crM4RldYbRRAhyE7Hw6EnfBdXECGydw7a49EGADayRvaeierP/m4DSv/OZQObh0LGA=="
},
"type-fest": { "type-fest": {
"version": "0.5.2", "version": "0.5.2",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz",
@ -5089,6 +5138,11 @@
"uid2": "0.0.3" "uid2": "0.0.3"
} }
}, },
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"unpipe": { "unpipe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

View file

@ -21,6 +21,7 @@
}, },
"dependencies": { "dependencies": {
"@types/sharp": "^0.23.1", "@types/sharp": "^0.23.1",
"@types/twemoji": "^12.1.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"deep-diff": "^1.0.2", "deep-diff": "^1.0.2",
@ -55,6 +56,7 @@
"tmp": "0.0.33", "tmp": "0.0.33",
"transliteration": "^2.1.7", "transliteration": "^2.1.7",
"tsconfig-paths": "^3.9.0", "tsconfig-paths": "^3.9.0",
"twemoji": "^12.1.4",
"typeorm": "^0.2.14", "typeorm": "^0.2.14",
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },
@ -65,7 +67,7 @@
"@types/js-yaml": "^3.12.1", "@types/js-yaml": "^3.12.1",
"@types/lodash.at": "^4.6.3", "@types/lodash.at": "^4.6.3",
"@types/moment-timezone": "^0.5.6", "@types/moment-timezone": "^0.5.6",
"@types/node": "^12.7.5", "@types/node": "^12.12.24",
"@types/passport": "^1.0.0", "@types/passport": "^1.0.0",
"@types/passport-oauth2": "^1.4.8", "@types/passport-oauth2": "^1.4.8",
"@types/passport-strategy": "^0.2.35", "@types/passport-strategy": "^0.2.35",

View file

@ -64,6 +64,7 @@ import escapeStringRegexp from "escape-string-regexp";
import safeRegex from "safe-regex"; import safeRegex from "safe-regex";
import fs from "fs"; import fs from "fs";
import sharp from "sharp"; import sharp from "sharp";
import twemoji from "twemoji";
import { Url, URL, URLSearchParams } from "url"; import { Url, URL, URLSearchParams } from "url";
const ConfigSchema = t.type({ const ConfigSchema = t.type({
@ -99,6 +100,7 @@ const SEARCH_EXPORT_LIMIT = 1_000_000;
const activeReloads: Map<string, TextChannel> = new Map(); const activeReloads: Map<string, TextChannel> = new Map();
const fsp = fs.promises; const fsp = fs.promises;
const CDN_URL = "https://twemoji.maxcdn.com/2/svg";
type MemberSearchParams = { type MemberSearchParams = {
query?: string; query?: string;
@ -1481,21 +1483,16 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.permission("can_jumbo") @d.permission("can_jumbo")
async jumboCmd(msg: Message, args: { emoji: string }) { async jumboCmd(msg: Message, args: { emoji: string }) {
// Get emoji url // Get emoji url
const config = this.getConfig();
const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`); const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`);
const results = emojiRegex.exec(args.emoji); const results = emojiRegex.exec(args.emoji);
const config = this.getConfig(); let extention = ".png";
let extention;
let file; let file;
if (results) { if (results) {
let url = "https://cdn.discordapp.com/emojis/"; let url = "https://cdn.discordapp.com/emojis/";
switch (results[1]) { if (results[1] === "<a:") {
case "<:": extention = ".gif";
extention = ".png";
break;
case "<a:":
extention = ".gif";
break;
} }
url += `${results[2]}${extention}`; url += `${results[2]}${extention}`;
if (extention === ".png") { if (extention === ".png") {
@ -1512,17 +1509,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
}; };
} }
} else { } else {
const regexAstralSymbols = /[Dd][C-Fc-f][0-9A-Fa-f]{2}/g; const url = CDN_URL + `/${twemoji.convert.toCodePoint(args.emoji)}.svg`;
let emojiArray = [];
for (let i = 0; i < args.emoji.length; i++) {
const char = args.emoji.codePointAt(i).toString(16);
if (!regexAstralSymbols.test(char)) {
emojiArray = emojiArray.concat(args.emoji.codePointAt(i).toString(16));
}
}
const result = emojiArray.join(`-`);
const url = `https://twemoji.maxcdn.com/2/72x72/${result}.png`;
const image = await this.resizeBuffer(await this.getBufferFromUrl(url), config.jumbo_size, config.jumbo_size); const image = await this.resizeBuffer(await this.getBufferFromUrl(url), config.jumbo_size, config.jumbo_size);
file = { file = {
name: `emoji.png`, name: `emoji.png`,
@ -1534,7 +1521,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
} }
async resizeBuffer(input: Buffer, width: number, height: number): Promise<Buffer> { async resizeBuffer(input: Buffer, width: number, height: number): Promise<Buffer> {
return sharp(input) return sharp(input, { density: 800 })
.resize(width, height, { .resize(width, height, {
fit: "inside", fit: "inside",
}) })

View file

@ -8,7 +8,8 @@
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"target": "es2018", "target": "es2018",
"lib": [ "lib": [
"esnext" "esnext",
"DOM"
], ],
"baseUrl": ".", "baseUrl": ".",
"resolveJsonModule": true, "resolveJsonModule": true,