Created
December 2, 2021 15:38
-
-
Save Awoocado/1c97e9afe1ac5e10faae782b393536d4 to your computer and use it in GitHub Desktop.
Otter holding an emoji
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Canvas = require('canvas') | |
| const emojip = require('twemoji-parser') | |
| module.exports = { | |
| data: { | |
| name: 'otter', | |
| description: 'make an otter hold an emoji', | |
| options: [{ | |
| type: 3, | |
| name: 'emoji', | |
| description: 'emoji to parse', | |
| required: true | |
| }, | |
| { | |
| type: 4, | |
| name: 'x', | |
| description: 'x axis (default 128)', | |
| min_value: -256, | |
| max_value: 256 | |
| }, | |
| { | |
| type: 4, | |
| name: 'y', | |
| description: 'y axis (default 128)', | |
| min_value: -256, | |
| max_value: 256 | |
| }, | |
| { | |
| type: 4, | |
| name: 'rotate', | |
| description: 'rotate degrees (default -45)', | |
| min_value: -360, | |
| max_value: 360 | |
| }, | |
| { | |
| type: 4, | |
| name: 'size', | |
| description: 'size (default 90)', | |
| min_value: -256, | |
| max_value: 256 | |
| }], | |
| type: 1 | |
| }, | |
| /** | |
| * @param {import('Eris').Client} client | |
| * @param {import('Eris').CommandInteraction} interaction | |
| * */ | |
| async execute(client, interaction) { | |
| const emoji = interaction.data.options.find(x => x.name == 'emoji') | |
| const cx = interaction.data.options.find(x => x.name == 'x')?.value ?? 128 | |
| const cy = interaction.data.options.find(x => x.name == 'y')?.value ?? 128 | |
| const rotate = interaction.data.options.find(x => x.name == 'rotate')?.value ?? -45 | |
| const size = interaction.data.options.find(x => x.name == 'size')?.value ?? 90 | |
| // not the best way to parse an emoji but it works | |
| const p = emojip.parse(emoji.value) | |
| if(!p) return interaction.createMessage({ content: `i couldn't parse that emoji: ${emoji.value}`, flags: 64 }) | |
| const res = emojiUnicode(emoji.value) | |
| interaction.createMessage({ content: '' }, [{ | |
| name: 'test.png', | |
| file: await createImage({ res, cx, cy, rotate, size }) | |
| }]) | |
| } | |
| } | |
| // https://twemoji.maxcdn.com/v/latest/svg/${res}.svg | |
| // https://twemoji.maxcdn.com/v/latest/72x72/${res}.png | |
| async function createImage({ res, cx, cy, rotate, size }) { | |
| const canvas = Canvas.createCanvas(256, 256) | |
| const ctx = canvas.getContext('2d') | |
| const otter = await loadSVG('./otter.svg') | |
| const image = await loadSVG(`https://twemoji.maxcdn.com/v/latest/svg/${res}.svg`) | |
| const otter_arms = await loadSVG('./otter-arms.svg') | |
| ctx.drawImage(otter, 0, 0, 256, 256) | |
| image.width = image.height = size | |
| drawRotated(canvas, ctx, image, rotate, cx, cy) | |
| ctx.drawImage(otter_arms, 0, 0, 256, 256) | |
| return canvas.toBuffer() | |
| } | |
| // just to rotate an image | |
| function drawRotated(canvas, ctx, image, degrees, x, y) { | |
| ctx.save() | |
| ctx.translate(x, y) | |
| ctx.rotate(degrees * Math.PI / 180) | |
| ctx.drawImage(image, -image.width / 2, -image.height / 2, image.width, image.height) | |
| ctx.restore() | |
| } | |
| // svg can be streched | |
| async function loadSVG(url, scale = 15) { | |
| const image = await Canvas.loadImage(url) | |
| image.width = image.naturalWidth * scale | |
| image.height = image.naturalHeight * scale | |
| return image | |
| } | |
| function emojiUnicode(e) { | |
| let comp | |
| if (e.length === 1) comp = e.charCodeAt(0) | |
| comp = (e.charCodeAt(0) - 0xD800) * 0x400 + (e.charCodeAt(1) - 0xDC00) + 0x10000 | |
| if (comp < 0) comp = e.charCodeAt(0) | |
| return comp.toString('16') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"> | |
| <path fill="#A78E81" | |
| d="M2.381 8.671c-1.573 0-2.359.786-1.573 1.573 1.573 1.573 3.145 1.573 3.931.786L2.381 8.671zm6.29-6.29c0-1.573.786-2.359 1.573-1.573 1.573 1.573 1.573 3.145.786 3.931L8.671 2.381zm-4.717 9.435s8.547 14.433 14.939 16.512c3.344 1.087 5.692.599 7.863-1.573s2.406-4.447 1.573-7.863C26.937 13.188 11.816 3.954 11.816 3.954l-7.862 7.862z" /> | |
| <path fill="#A78E81" | |
| d="M16.129 26.852c4.231 5.36 8.793 7.807 10.465 6.519 1.624-1.25-.324-2.578-2.174-6.954-1.936-4.58-10.526-2.397-8.291.435zM26.85 16.07c5.36 4.231 7.803 8.858 6.516 10.53-1.25 1.624-2.578-.324-6.954-2.174-4.581-1.936-2.394-10.591.438-8.356z" /> | |
| <path fill="#846659" | |
| d="M17.008 21.564c.699-1.287-.914-3.363-2.504-3.314-1.172.036-3.617 1.934-5.883-.746-.209.209-.304.496-.311.829 1.158 1.577 2.472 3.242 3.848 4.765 1.656.479 3.913.192 4.85-1.534zm1.242-7.06c-.049 1.589 2.028 3.203 3.314 2.504 1.712-.93 2.007-3.159 1.544-4.81-1.545-1.372-3.246-2.703-4.851-3.882-.3.02-.56.113-.753.306 2.679 2.265.782 4.71.746 5.882z" /> | |
| <path fill="#A78E81" | |
| d="M27.542 24.397c3.474 3.474 8.731 10.139 7.863 11.008-.868.868-7.534-4.389-11.008-7.863s-4.014-5.422-3.145-6.29c.868-.869 2.816-.329 6.29 3.145zM12.603 3.167c2.171 2.171 1.554 4.736-1.573 7.863s-5.692 3.744-7.863 1.573-2.34-5.523.787-8.649 6.477-2.958 8.649-.787z" /> | |
| <path fill="#CAB8AC" | |
| d="M13.738 4.303c1.223 1.223 1.991 5.173-1.136 8.3s-7.076 2.359-8.3 1.136c-1.93-1.93 1.223-5.067 2.796-6.64s4.71-4.726 6.64-2.796z" /> | |
| <path fill="#292F33" | |
| d="M9.457 6.312a2.225 2.225 0 01-3.145 3.145c-.868-.868-.082-1.49.787-2.358s1.49-1.655 2.358-.787z" /> | |
| <circle fill="#292F33" cx="4.74" cy="9.457" r="1.112" /> | |
| <circle fill="#292F33" cx="9.457" cy="4.74" r="1.112" /> | |
| <path fill="#A78E81" | |
| d="M10.655 10.401c-.426 0-.82-.101-1.132-.308a.412.412 0 01.454-.686c.452.299 1.339.188 2.019-.253.276-.179.906-.674.785-1.399a.411.411 0 11.811-.135c.139.836-.291 1.668-1.15 2.224-.565.368-1.205.557-1.787.557z" /> | |
| <path fill="#A78E81" | |
| d="M7.931 13.619c-.103 0-.207-.009-.31-.026a.41.41 0 11.135-.811c.722.121 1.22-.509 1.399-.786.441-.681.553-1.568.253-2.019a.411.411 0 01.686-.454c.489.739.387 1.939-.249 2.92-.488.753-1.187 1.176-1.914 1.176z" /> | |
| <path fill="#846659" | |
| d="M25.635 28.904c-1.021-1.634-1.501-3.563-.898-4.166.613-.613 2.073-.745 4.186.878-1.348-1.286-3.757-2.695-4.186-5.044.123 2.164-.419 4.625-4.125 4.043 2.082.614 5.023 4.289 5.023 4.289z" /> | |
| <g fill="#67757F"> | |
| <path | |
| d="M2.928 15.73a.486.486 0 01-.479-.572c.407-2.269 1.793-3.891 3.707-4.338a.486.486 0 11.221.947c-1.524.356-2.634 1.689-2.971 3.564a.486.486 0 01-.478.399z" /> | |
| <path | |
| d="M5.072 15.974a.485.485 0 01-.484-.451c-.079-1.078.493-2.498 1.586-3.008a.486.486 0 11.411.881c-.671.313-1.08 1.335-1.028 2.056a.485.485 0 01-.449.52c-.013.002-.024.002-.036.002zm6.208-9.209a.486.486 0 01-.474-.597c.448-1.914 2.07-3.299 4.338-3.707a.486.486 0 01.171.957c-1.875.337-3.207 1.447-3.564 2.971a.481.481 0 01-.471.376z" /> | |
| <path | |
| d="M12.944 6.877a.486.486 0 01-.44-.692c.51-1.093 1.919-1.664 3.008-1.586a.485.485 0 11-.071.969c-.712-.048-1.742.357-2.056 1.028a.487.487 0 01-.441.281z" /> | |
| </g> | |
| </svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment