feat(discord-bot): add fdp command
This commit is contained in:
48
apps/discord-bot/src/commands/fdp.ts
Normal file
48
apps/discord-bot/src/commands/fdp.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { AttachmentBuilder } from "discord.js";
|
||||
import sharp from "sharp";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { noMention } from "~/discord";
|
||||
import type { Command } from "./index";
|
||||
|
||||
const POOP_PATH = join(dirname(fileURLToPath(import.meta.url)), "../../assets/poop.png");
|
||||
|
||||
export const fdpCommand: Command = {
|
||||
help: "Essaie et tu verras",
|
||||
handler: async (message) => {
|
||||
const avatarUrl = message.author.displayAvatarURL({ size: 512, extension: "png" });
|
||||
|
||||
const avatarBuffer = Buffer.from(await (await fetch(avatarUrl)).arrayBuffer());
|
||||
|
||||
const { width: avatarWidth, height: avatarHeight } = await sharp(avatarBuffer).metadata();
|
||||
if (!avatarWidth || !avatarHeight) return;
|
||||
|
||||
const poopWidth = Math.floor(avatarWidth / 2);
|
||||
const poopBuffer = await sharp(POOP_PATH).resize({ width: poopWidth }).toBuffer();
|
||||
const { height: poopHeight } = await sharp(poopBuffer).metadata();
|
||||
if (!poopHeight) return;
|
||||
|
||||
const overlap = Math.floor(poopHeight / 4);
|
||||
const poopLeft = Math.floor((avatarWidth - poopWidth) / 2);
|
||||
|
||||
const result = await sharp({
|
||||
create: {
|
||||
width: avatarWidth,
|
||||
height: avatarHeight + poopHeight - overlap,
|
||||
channels: 4,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
},
|
||||
})
|
||||
.composite([
|
||||
{ input: avatarBuffer, top: poopHeight - overlap, left: 0 },
|
||||
{ input: poopBuffer, top: 0, left: poopLeft },
|
||||
])
|
||||
.webp()
|
||||
.toBuffer();
|
||||
|
||||
await message.reply({
|
||||
...noMention,
|
||||
files: [new AttachmentBuilder(result, { name: "fdp.webp" })],
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Message, OmitPartialGroupDMChannel } from "discord.js";
|
||||
import { fdpCommand } from "./fdp";
|
||||
import { pingCommand } from "./ping";
|
||||
import { trackCommand } from "./tracking";
|
||||
import { iconeCommand } from "./icone";
|
||||
@@ -18,6 +19,7 @@ export type Command = {
|
||||
};
|
||||
|
||||
export const commands: Record<string, Command> = {
|
||||
fdp: fdpCommand,
|
||||
ping: pingCommand,
|
||||
track: trackCommand,
|
||||
icone: iconeCommand,
|
||||
|
||||
Reference in New Issue
Block a user