mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Convert !avatar, !jumbo, and !reload_guild
This commit is contained in:
parent
a0e46df19d
commit
302987cb17
5 changed files with 155 additions and 1 deletions
|
@ -20,6 +20,11 @@ import { VcmoveCmd } from "./commands/VcmoveCmd";
|
|||
import { HelpCmd } from "./commands/HelpCmd";
|
||||
import { AboutCmd } from "./commands/AboutCmd";
|
||||
import { PluginOptions } from "knub";
|
||||
import { activeReloads } from "./guildReloads";
|
||||
import { sendSuccessMessage } from "../../pluginUtils";
|
||||
import { ReloadGuildCmd } from "./commands/ReloadGuildCmd";
|
||||
import { JumboCmd } from "./commands/JumboCmd";
|
||||
import { AvatarCmd } from "./commands/AvatarCmd";
|
||||
|
||||
const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||
config: {
|
||||
|
@ -91,9 +96,14 @@ export const UtilityPlugin = zeppelinPlugin<UtilityPluginType>()("utility", {
|
|||
VcmoveCmd,
|
||||
HelpCmd,
|
||||
AboutCmd,
|
||||
ReloadGuildCmd,
|
||||
JumboCmd,
|
||||
AvatarCmd,
|
||||
],
|
||||
|
||||
onLoad({ state, guild }) {
|
||||
onLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
state.cases = GuildCases.getGuildInstance(guild.id);
|
||||
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
||||
|
@ -101,5 +111,10 @@ export const UtilityPlugin = zeppelinPlugin<UtilityPluginType>()("utility", {
|
|||
state.supporters = new Supporters();
|
||||
|
||||
state.lastReload = Date.now();
|
||||
|
||||
if (activeReloads.has(guild.id)) {
|
||||
sendSuccessMessage(pluginData, activeReloads.get(guild.id), "Reloaded!");
|
||||
activeReloads.delete(guild.id);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
31
backend/src/plugins/Utility/commands/AvatarCmd.ts
Normal file
31
backend/src/plugins/Utility/commands/AvatarCmd.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { downloadFile, messageLink, SECONDS, UnknownUser } from "../../../utils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { EmbedOptions, TextChannel } from "eris";
|
||||
import { activeReloads } from "../guildReloads";
|
||||
|
||||
export const AvatarCmd = utilityCmd({
|
||||
trigger: "avatar",
|
||||
description: "Retrieves a user's profile picture",
|
||||
permission: "can_avatar",
|
||||
|
||||
signature: {
|
||||
user: ct.resolvedUserLoose(),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const user = args.user || msg.author;
|
||||
if (!(user instanceof UnknownUser)) {
|
||||
const extention = user.avatarURL.slice(user.avatarURL.lastIndexOf("."), user.avatarURL.lastIndexOf("?"));
|
||||
const avatarUrl = user.avatarURL.slice(0, user.avatarURL.lastIndexOf("."));
|
||||
const embed: EmbedOptions = {
|
||||
image: { url: avatarUrl + `${extention}?size=2048` },
|
||||
};
|
||||
embed.title = `Avatar of ${user.username}#${user.discriminator}:`;
|
||||
msg.channel.createMessage({ embed });
|
||||
} else {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
|
||||
}
|
||||
},
|
||||
});
|
85
backend/src/plugins/Utility/commands/JumboCmd.ts
Normal file
85
backend/src/plugins/Utility/commands/JumboCmd.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { downloadFile, messageLink, SECONDS } from "../../../utils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { TextChannel } from "eris";
|
||||
import { activeReloads } from "../guildReloads";
|
||||
import fs from "fs";
|
||||
import sharp from "sharp";
|
||||
import twemoji from "twemoji";
|
||||
|
||||
const fsp = fs.promises;
|
||||
|
||||
async function getBufferFromUrl(url: string): Promise<Buffer> {
|
||||
const downloadedEmoji = await downloadFile(url);
|
||||
return fsp.readFile(downloadedEmoji.path);
|
||||
}
|
||||
|
||||
async function resizeBuffer(input: Buffer, width: number, height: number): Promise<Buffer> {
|
||||
return sharp(input, { density: 800 })
|
||||
.resize(width, height, {
|
||||
fit: "inside",
|
||||
})
|
||||
.toBuffer();
|
||||
}
|
||||
|
||||
const CDN_URL = "https://twemoji.maxcdn.com/2/svg";
|
||||
|
||||
export const JumboCmd = utilityCmd({
|
||||
trigger: "jumbo",
|
||||
description: "Makes an emoji jumbo",
|
||||
permission: "can_jumbo",
|
||||
cooldown: 5 * SECONDS,
|
||||
|
||||
signature: {
|
||||
emoji: ct.string(),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
// Get emoji url
|
||||
const config = pluginData.config.get();
|
||||
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;
|
||||
|
||||
if (results) {
|
||||
let url = "https://cdn.discordapp.com/emojis/";
|
||||
if (results[1] === "<a:") {
|
||||
extention = ".gif";
|
||||
}
|
||||
url += `${results[2]}${extention}`;
|
||||
if (extention === ".png") {
|
||||
const image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
file = {
|
||||
name: `emoji${extention}`,
|
||||
file: image,
|
||||
};
|
||||
} else {
|
||||
const image = await getBufferFromUrl(url);
|
||||
file = {
|
||||
name: `emoji${extention}`,
|
||||
file: image,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
let url = CDN_URL + `/${twemoji.convert.toCodePoint(args.emoji)}.svg`;
|
||||
let image;
|
||||
try {
|
||||
image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
} catch {
|
||||
if (url.toLocaleLowerCase().endsWith("fe0f.svg")) {
|
||||
url = url.slice(0, url.lastIndexOf("-fe0f")) + ".svg";
|
||||
image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
}
|
||||
}
|
||||
file = {
|
||||
name: `emoji.png`,
|
||||
file: image,
|
||||
};
|
||||
}
|
||||
|
||||
msg.channel.createMessage(null, file);
|
||||
},
|
||||
});
|
20
backend/src/plugins/Utility/commands/ReloadGuildCmd.ts
Normal file
20
backend/src/plugins/Utility/commands/ReloadGuildCmd.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { messageLink } from "../../../utils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { TextChannel } from "eris";
|
||||
import { activeReloads } from "../guildReloads";
|
||||
|
||||
export const ReloadGuildCmd = utilityCmd({
|
||||
trigger: "reload_guild",
|
||||
description: "Reload the Zeppelin configuration and all plugins for the server. This can sometimes fix issues.",
|
||||
permission: "can_reload_guild",
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (activeReloads.has(pluginData.guild.id)) return;
|
||||
activeReloads.set(pluginData.guild.id, msg.channel as TextChannel);
|
||||
|
||||
msg.channel.createMessage("Reloading...");
|
||||
pluginData.getKnubInstance().reloadGuild(pluginData.guild.id);
|
||||
},
|
||||
});
|
3
backend/src/plugins/Utility/guildReloads.ts
Normal file
3
backend/src/plugins/Utility/guildReloads.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { TextChannel } from "eris";
|
||||
|
||||
export const activeReloads: Map<string, TextChannel> = new Map();
|
Loading…
Add table
Reference in a new issue