Skip to content

Commit

Permalink
feat: girlcockx and currency conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
maamokun committed Jan 27, 2025
1 parent 44f2630 commit 7716506
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
96 changes: 96 additions & 0 deletions src/commands/currency.ts
Original file line number Diff line number Diff line change
@@ -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] });
},
};
4 changes: 3 additions & 1 deletion src/handlers/xfix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7716506

Please sign in to comment.