fixed jumbo cmd, simplified checks and fixed ping cmd

This commit is contained in:
almeidx 2021-07-29 01:43:50 +01:00
parent 80f2dacb7f
commit a8298d4faa
No known key found for this signature in database
GPG key ID: 8558FBFF849BD664
4 changed files with 20 additions and 24 deletions

View file

@ -1,3 +1,4 @@
import { MessageAttachment } from "discord.js";
import fs from "fs"; import fs from "fs";
import sharp from "sharp"; import sharp from "sharp";
import twemoji from "twemoji"; import twemoji from "twemoji";
@ -39,8 +40,8 @@ export const JumboCmd = utilityCmd({
const size = config.jumbo_size > 2048 ? 2048 : config.jumbo_size; const size = config.jumbo_size > 2048 ? 2048 : config.jumbo_size;
const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`); const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`);
const results = emojiRegex.exec(args.emoji); const results = emojiRegex.exec(args.emoji);
let extention = ".png"; let extension = ".png";
let file; let file: MessageAttachment | undefined;
if (!isEmoji(args.emoji)) { if (!isEmoji(args.emoji)) {
sendErrorMessage(pluginData, msg.channel, "Invalid emoji"); sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
@ -50,25 +51,19 @@ export const JumboCmd = utilityCmd({
if (results) { if (results) {
let url = "https://cdn.discordapp.com/emojis/"; let url = "https://cdn.discordapp.com/emojis/";
if (results[1] === "<a:") { if (results[1] === "<a:") {
extention = ".gif"; extension = ".gif";
} }
url += `${results[2]}${extention}`; url += `${results[2]}${extension}`;
if (extention === ".png") { if (extension === ".png") {
const image = await resizeBuffer(await getBufferFromUrl(url), size, size); const image = await resizeBuffer(await getBufferFromUrl(url), size, size);
file = { file = new MessageAttachment(image, `emoji${extension}`);
name: `emoji${extention}`,
file: image,
};
} else { } else {
const image = await getBufferFromUrl(url); const image = await getBufferFromUrl(url);
file = { file = new MessageAttachment(image, `emoji${extension}`);
name: `emoji${extention}`,
file: image,
};
} }
} else { } else {
let url = CDN_URL + `/${twemoji.convert.toCodePoint(args.emoji)}.svg`; let url = CDN_URL + `/${twemoji.convert.toCodePoint(args.emoji)}.svg`;
let image; let image: Buffer | undefined;
try { try {
image = await resizeBuffer(await getBufferFromUrl(url), size, size); image = await resizeBuffer(await getBufferFromUrl(url), size, size);
} catch { } catch {
@ -77,12 +72,14 @@ export const JumboCmd = utilityCmd({
image = await resizeBuffer(await getBufferFromUrl(url), size, size); image = await resizeBuffer(await getBufferFromUrl(url), size, size);
} }
} }
file = { if (!image) {
name: `emoji.png`, sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
file: image, return;
}; }
file = new MessageAttachment(image, "emoji.png");
} }
msg.channel.send({ content: "", files: [file] }); msg.channel.send({ files: [file] });
}, },
}); });

View file

@ -29,8 +29,6 @@ export const PingCmd = utilityCmd({
const lowest = Math.round(Math.min(...times)); const lowest = Math.round(Math.min(...times));
const mean = Math.round(times.reduce((total, ms) => total + ms, 0) / times.length); const mean = Math.round(times.reduce((total, ms) => total + ms, 0) / times.length);
// const shard = pluginData.client.shards.get(pluginData.client.guildShardMap[pluginData.guild.id])!; FIXME sharding stuff
msg.channel.send( msg.channel.send(
trimLines(` trimLines(`
**Ping:** **Ping:**
@ -38,7 +36,8 @@ export const PingCmd = utilityCmd({
Highest: **${highest}ms** Highest: **${highest}ms**
Mean: **${mean}ms** Mean: **${mean}ms**
Time between ping command and first reply: **${msgToMsgDelay!}ms** Time between ping command and first reply: **${msgToMsgDelay!}ms**
`), // Omitted line: Shard latency: **${shard.latency}ms** Shard latency: **${pluginData.client.ws.ping}ms**
`),
); );
// Clean up test messages // Clean up test messages

View file

@ -25,7 +25,7 @@ export const VcdisconnectCmd = utilityCmd({
return; return;
} }
if (!args.member.voice || !args.member.voice.channelId) { if (!args.member.voice?.channelId) {
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel"); sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
return; return;
} }

View file

@ -57,7 +57,7 @@ export const VcmoveCmd = utilityCmd({
channel = closestMatch; channel = closestMatch;
} }
if (!args.member.voice || !args.member.voice.channelId) { if (!args.member.voice?.channelId) {
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel"); sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
return; return;
} }