Skip to content

Commit

Permalink
update link command
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonded committed Aug 27, 2024
1 parent 3e5cf2f commit 745f533
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "ISC",
"dependencies": {
"@prisma/client": "5.17.0",
"country-code-lookup": "^0.1.3",
"discord.js": "^14.15.3",
"tesseract.js": "^5.1.0",
"tsx": "^3.14.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/team/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import update from "./update";
import pass from "./pass";
import sync from "./sync";

export default category("Team", [who, link, create, update, pass, sync]);
export default category("Team", [who, link, create, pass, sync]);
53 changes: 49 additions & 4 deletions src/commands/team/link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { command } from "utils";
import lookup from "country-code-lookup";

const meta = new SlashCommandBuilder()
.setName("link")
Expand Down Expand Up @@ -46,27 +47,71 @@ const meta = new SlashCommandBuilder()
)
.setDescription("Choose your username style")
.setRequired(false)
)
.addStringOption((option) =>
option.setName("country").setDescription("Your country").setRequired(false)
);

export default command(meta, async ({ interaction }) => {
const country =
interaction.options.getString("country")!.charAt(0).toUpperCase() +
interaction.options.getString("country")!.slice(1);

const look =
lookup.byCountry(country) ??
lookup.byInternet(country) ??
lookup.byIso(country);

const info = {
User: interaction.user.globalName,
Id: interaction.user.id,
NexusMods: interaction.options.getString("nexusmods") ?? "None",
GitHub: interaction.options.getString("github") ?? "None",
Github: interaction.options.getString("github") ?? "None",
Theme: interaction.options.getString("theme") ?? "default",
Description: interaction.options.getString("description") ?? "None",
Style: interaction.options.getString("username") ?? "uppercase",
Timezone: "None",
Country: look?.internet ?? "None",
};

const data = fetch(process.env.API_ENDPOINT + "/bot/commands/user", {
method: "PUT",
const data = await fetch(process.env.API_ENDPOINT + "/bot/commands/user", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.BOT_TOKEN}`,
},
body: JSON.stringify(info),
});

return interaction.reply({ content: JSON.stringify(info, null, 2) });
if (!data.ok) {
return interaction.reply({
content: "Failed to link your account.",
ephemeral: true,
});
}

if (!look) {
return interaction.reply({
embeds: [
{
title: "Account Linked",
description:
"Your account has been successfully linked/Updated.\nBut we couldn't find your country.\nTry using an ISO Country Code.",
color: 0x00ff00,
},
],
ephemeral: true,
});
}

return interaction.reply({
embeds: [
{
title: "Account Linked",
description: "Your account has been successfully linked/Updated.",
color: 0x00ff00,
},
],
ephemeral: true,
});
});

0 comments on commit 745f533

Please sign in to comment.