3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

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": {
"version": "12.12.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.5.tgz",
"integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A=="
"version": "12.12.24",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.24.tgz",
"integrity": "sha512-1Ciqv9pqwVtW6FsIUKSZNB82E5Cu1I2bBTj1xuIHXLe/1zYLl3956Nbhg2MzSYHVfl9/rmanjbQIb7LibfCnug=="
},
"@types/oauth": {
"version": "0.9.1",
@ -627,6 +627,11 @@
"integrity": "sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=",
"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": {
"version": "1.3.7",
"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",
"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": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.0.0.tgz",
@ -2507,8 +2532,7 @@
"graceful-fs": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz",
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==",
"dev": true
"integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ=="
},
"has": {
"version": "1.0.3",
@ -2924,6 +2948,15 @@
"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": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",
@ -4965,6 +4998,22 @@
"integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==",
"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": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz",
@ -5089,6 +5138,11 @@
"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": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

View file

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

View file

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

View file

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