Skip to content

Commit

Permalink
feat: banner, server banner, server splash banner commands
Browse files Browse the repository at this point in the history
  • Loading branch information
espimarisa committed Aug 24, 2024
1 parent 21a9166 commit 53473cf
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 124 deletions.
16 changes: 15 additions & 1 deletion locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"COMMAND_AVATAR_SERVER_TITLE": "{{username}}'s server avatar",
"COMMAND_AVATAR_TITLE": "{{username}}'s avatar",

"COMMAND_BANNER_NAME": "Banner",
"COMMAND_BANNER_DESCRIPTION": "Sends an account's profile banner.",
"COMMAND_BANNER_OPTION_0_NAME": "account",
"COMMAND_BANNER_OPTION_0_DESCRIPTION": "The account to get the profile banner from. Defaults to yourself.",
"COMMAND_BANNER_TITLE": "{{username}}'s banner",

"COMMAND_CHANNEL_NAME": "Channel",
"COMMAND_CHANNEL_DESCRIPTION": "Gets information about a selected channel.",
"COMMAND_CHANNEL_OPTION_0_NAME": "channel",
Expand Down Expand Up @@ -109,7 +115,15 @@
"COMMAND_ROLEPLAY_KISS": "❤️ {{user}} gave {{target}} a kiss!",

"COMMAND_SERVER_NAME": "Server",
"COMMAND_SERVER_DESCRIPTION": "Gets information about the Discord server/guild.",
"COMMAND_SERVER_DESCRIPTION": "Gets information and statistics about the Discord server.",
"COMMAND_SERVER_OPTION_0_NAME": "info",
"COMMAND_SERVER_OPTION_0_DESCRIPTION": "Gets information and statistics about the Discord server.",
"COMMAND_SERVER_OPTION_1_NAME": "banner",
"COMMAND_SERVER_OPTION_1_DESCRIPTION": "Sends the server's banner.",
"COMMAND_SERVER_OPTION_2_NAME": "icon",
"COMMAND_SERVER_OPTION_2_DESCRIPTION": "Sends the server's icon.",
"COMMAND_SERVER_OPTION_3_NAME": "invite-banner",
"COMMAND_SERVER_OPTION_3_DESCRIPTION": "Sends the server's invite banner.",

"COMMAND_URBAN_NAME": "Urban",
"COMMAND_URBAN_DESCRIPTION": "Gets the definition of a word from the Urban Dictionary",
Expand Down
2 changes: 2 additions & 0 deletions locales/en-US/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"ERROR_DESCRIPTION": "\n```ts\n{{- error}}\n```",
"ERROR_FOUND_A_BUG": "Found a bug? - github.com/espimarisa/hibiki/issues",
"ERROR_IMAGE": "Failed to send the image. Try again later.",
"ERROR_NO_BANNER": "No banner is set.",
"ERROR_NO_ICON": "No icon is set.",
"ERROR_NO_OPTION_PROVIDED": "No option was provided.",
"ERROR_ROLE": "Failed to get information about the role. Try again later.",
"ERROR_SERVER": "Failed to get information about the server. Try again later."
Expand Down
75 changes: 75 additions & 0 deletions src/commands/banner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { type APIOption, HibikiCommand, type HibikiCommandOptions } from "$classes/Command.ts";
import { HibikiColors } from "$utils/constants.ts";
import { t } from "$utils/i18n.ts";
import { ApplicationCommandOptionType, type ChatInputCommandInteraction } from "discord.js";

export class AvatarCommand extends HibikiCommand {
options = [
{
// The account to get a banner from
type: ApplicationCommandOptionType.User,
required: false,
},
] satisfies HibikiCommandOptions[];

async runCommand(interaction: ChatInputCommandInteraction) {
// Gets the member data and/or the server member data for resolving the avatar URL
const memberToFetch = await interaction.options.getUser((this.options as APIOption[])[0]!.name)?.fetch();
const idToFetch = memberToFetch?.id ?? interaction.user.id;

// Fetches the member
const member =
interaction.guild!.members.cache.find((m) => m.id === idToFetch) ||
(await interaction.guild!.members.fetch(idToFetch));

// Error handler
const errorMessage = async (noBanner = false) => {
await interaction.followUp({
embeds: [
{
title: t("errors:ERROR", { lng: interaction.locale }),
description: noBanner
? t("errors:ERROR_NO_BANNER", { lng: interaction.locale })
: t("errors:ERROR_ACCOUNT", { lng: interaction.locale }),
color: HibikiColors.ERROR,
footer: {
text: t("errors:ERROR_FOUND_A_BUG", { lng: interaction.locale }),
icon_url: this.bot.user?.displayAvatarURL(),
},
},
],
});
};

// Error handler
if (!member) {
await errorMessage();
return;
}

// Error handler for no banner
if (!member.user.bannerURL()) {
await errorMessage(true);
return;
}

// Sends the avatar data
await interaction.followUp({
embeds: [
{
author: {
name: t("commands:COMMAND_BANNER_TITLE", {
username: member.user.tag,
lng: interaction.locale,
}),
icon_url: member.user.displayAvatarURL({ size: 2048 }).toString(),
},
color: member.user.accentColor ?? HibikiColors.GENERAL,
image: {
url: member.user.bannerURL({ size: 2048 })!.toString(),
},
},
],
});
}
}
Loading

0 comments on commit 53473cf

Please sign in to comment.