emotedump command

This commit is contained in:
Jill 2022-08-26 19:42:48 +03:00
parent 52bafc6f09
commit e2ff3e9594
2 changed files with 50 additions and 0 deletions

40
src/commands/emotedump.ts Normal file
View File

@ -0,0 +1,40 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { CommandInteraction, GuildMember, MessageEmbed } from 'discord.js';
import { writeTmpFile } from '../lib/util';
module.exports = {
data: new SlashCommandBuilder()
.setName('emotedump')
.setDescription('Dump every emote in the server for Gitea')
.addIntegerOption((option) =>
option
.setName('size')
.setRequired(false)
.setDescription('Image size to output the emojis as, leave unset if unsure')
.setMinValue(16)
.setMaxValue(512)
),
execute: async (interaction: CommandInteraction, member: GuildMember) => {
const size = interaction.options.getNumber('size') || 64;
const emojis = member.guild.emojis;
const embed = new MessageEmbed()
.setDescription(`names: \`${emojis.cache.map(emote => emote.name).join(',')}\``);
const commands = [
...emojis.cache.map(emote =>
`wget -q "https://cdn.discordapp.com/emojis/${emote.id}.${emote.animated ? 'gif' : 'png'}?size=${size}&quality=lossless" -O "${emote.name}.png"`
),
'chown gitea:gitea ./*'
].join('\n');
const attach = await writeTmpFile(commands, 'commands', 'sh');
interaction.reply({
embeds: [embed],
files: [attach],
ephemeral: true
});
}
};

View File

@ -1,4 +1,7 @@
import * as fsp from 'fs/promises';
import { tmpdir } from 'os';
import { join } from 'path';
import { randomBytes } from 'crypto';
export async function exists(file: string) {
try {
@ -13,4 +16,11 @@ export function getSign(n: number) {
if (n > 0) return '+';
if (n < 0) return '-';
return ' ';
}
export async function writeTmpFile(data: string | Buffer, filename?: string, extension?: string): Promise<string> {
const file = `${filename ? filename + '-' : ''}${randomBytes(8).toString('hex')}${extension ? '.' + extension : (typeof data === 'string' ? '.txt' : '')}`;
const path = join(tmpdir(), file);
await fsp.writeFile(path, data);
return path;
}