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

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

View file

@ -25,7 +25,7 @@ export const VcdisconnectCmd = utilityCmd({
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");
return;
}

View file

@ -57,7 +57,7 @@ export const VcmoveCmd = utilityCmd({
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");
return;
}