From 771650602e0ad392a211090bf430740333b1c3ff Mon Sep 17 00:00:00 2001 From: maamokun/MikanDev Date: Mon, 27 Jan 2025 21:13:27 +0900 Subject: [PATCH] feat: girlcockx and currency conversion --- src/commands/currency.ts | 96 ++++++++++++++++++++++++++++++++++++++++ src/handlers/xfix.ts | 4 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/commands/currency.ts diff --git a/src/commands/currency.ts b/src/commands/currency.ts new file mode 100644 index 0000000..38eee44 --- /dev/null +++ b/src/commands/currency.ts @@ -0,0 +1,96 @@ +import { + type CommandInteraction, + EmbedBuilder, + ButtonBuilder, + ActionRowBuilder, + ButtonStyle, + Colors, + ApplicationCommandOptionType, +} from "discord.js"; + +const currencyToName = async (code: string) => { + const data = await fetch( + "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json", + ); + const currencies = await data.json(); + return currencies[code]; +}; + +export default { + name: "currency", + description: "Convert between various currencies", + cooldown: 3, + isPremium: false, + botPermissions: [], + userPermissions: [], + validations: [], + slashCommand: { + enabled: true, + options: [ + { + name: "amount", + description: "The amount you are converting", + type: ApplicationCommandOptionType.Number, + required: true, + }, + { + name: "from", + description: "The currency you are converting from", + type: ApplicationCommandOptionType.String, + required: true, + }, + { + name: "to", + description: "The currency you are converting to", + type: ApplicationCommandOptionType.String, + required: true, + }, + ], + }, + interactionRun: async (interaction: CommandInteraction) => { + const amount = interaction.options.get("amount")?.value as number; + const from = interaction.options.get("from")?.value as string; + const to = interaction.options.get("to")?.value as string; + + const fromName = await currencyToName(from.toLowerCase()); + const toName = await currencyToName(to.toLowerCase()); + + if (!fromName || !toName) { + return interaction.reply({ + content: + "Invalid currency codes. A list of valid codes can be found [here](https://www.iban.com/currency-codes)", + ephemeral: true, + }); + } + + const data = await fetch( + `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/${from.toLowerCase()}.json`, + ); + const result = await data.json(); + + const rates = result[from.toLowerCase()]; + + const rate = rates[to.toLowerCase()]; + + if (!rate) { + return interaction.reply({ + content: `Conversion rate from ${fromName} to ${toName} not found.`, + ephemeral: true, + }); + } + + const final = amount * rate; + + const embed = new EmbedBuilder() + .setTitle("Currency Conversion") + .setDescription( + `**${amount} ${fromName}** is equal to **${final} ${toName}**`, + ) + .setFooter({ + text: `This data is not realtime, and is updated every 24 hours`, + }) + .setColor(Colors.Green); + + await interaction.reply({ embeds: [embed] }); + }, +}; diff --git a/src/handlers/xfix.ts b/src/handlers/xfix.ts index a345998..2cd9396 100644 --- a/src/handlers/xfix.ts +++ b/src/handlers/xfix.ts @@ -24,8 +24,10 @@ export const xfix = async (message: Message) => { let url = messageURL[0]; + if (url.split("/").length === 4) return; + url = url - .replace("https://x.com", "https://fixupx.com") + .replace("https://x.com", "https://girlcockx.com") .replace("https://twitter.com", "https://twittpr.com"); await message.suppressEmbeds(true);