feat(discord-bot): add fdp command
All checks were successful
Build and Push Docker Image / typecheck (push) Successful in 23s
Build and Push Docker Image / build (push) Successful in 33s

This commit is contained in:
2026-05-12 16:28:08 +02:00
parent 69e461b54b
commit f5a7dbf1e8
5 changed files with 337 additions and 1 deletions

View 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" })],
});
},
};

View File

@@ -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,