Skip to content

Commit

Permalink
customise avatar command embed title
Browse files Browse the repository at this point in the history
  • Loading branch information
TiltedToast committed Sep 21, 2024
1 parent bd5274a commit 317308f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BOT_TOKEN=
BOT_ID="this is only used for registering slash commands"
BOT_ID=
EXCHANGE_API_KEY=
IMGUR_CLIENT_ID=
IMGUR_CLIENT_SECRET=
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@total-typescript/ts-reset": "^0.6.1",
"@types/qrcode": "^1.5.5",
"@types/strftime": "^0.9.8",
"bun-types": "^1.1.27",
"bun-types": "^1.1.29",
"concurrently": "9.0.0",
"drizzle-kit": "^0.24.2",
"husky": "^9.1.6",
Expand Down
18 changes: 17 additions & 1 deletion src/commands/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type User,
type UserContextMenuCommandInteraction,
codeBlock,
italic,
} from "discord.js";
import { type FactoryFunctionMap, all, create } from "mathjs";
import assert from "node:assert/strict";
Expand Down Expand Up @@ -373,16 +374,21 @@ export async function avatar(
) {
let user: User;

let invoker: User;

if (isChatInputCommandInteraction(input)) {
user = input.options.getUser("user", false) ?? input.user;
invoker = input.user;
} else if (isUserContextMenuCommandInteraction(input)) {
user = input.targetUser;
invoker = input.user;
} else {
const content = input.content.split(" ").filter(Boolean);
const tmp = content.length === 1 ? input.author : await getUserObjectPingId(input);

if (!tmp) return await sendOrReply(input, "Couldn't find the specified User");

invoker = input.author;
user = tmp;
}

Expand All @@ -392,9 +398,19 @@ export async function avatar(

if (!avatarURL) return await sendOrReply(input, "No avatar found!");

let title: string;

if (invoker.id === user.id) {
title = "Your avatar";
} else if (user.id === process.env.BOT_ID) {
title = "My avatar";
} else {
title = `${user.displayName}'s avatar`;
}

const avatarEmbed = new EmbedBuilder()
.setColor(EMBED_COLOUR)
.setTitle(`*${user.displayName}'s Avatar*`)
.setTitle(italic(title))
.setImage(avatarURL);

return await sendOrReply(input, { embeds: [avatarEmbed] });
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const USER_AGENT = `${BOT_NAME}:v1.0.0:tiltedtoast27@gmail.com`;
// biome-ignore format: this is nicer
const envVariables = z.object({
BOT_TOKEN: z.string().min(1, "You must provide a Discord Bot Token"),
BOT_ID: z.string().min(1, "You must provide a Discord Bot ID"),
EXCHANGE_API_KEY: z.string().min(1, "You must provide an API key for currency conversion"),
IMGUR_CLIENT_ID: z.string().min(1, "You must provide an Imgur Client Id"),
IMGUR_CLIENT_SECRET: z.string().min(1, "You must provide an Imgur Client Secret"),
Expand Down

0 comments on commit 317308f

Please sign in to comment.