Skip to content

Commit

Permalink
Merge pull request #105 from chiscookeke11/fix-#89
Browse files Browse the repository at this point in the history
Fix #89
  • Loading branch information
Marchand-Nicolas authored Feb 17, 2025
2 parents 7c8fbb4 + a6f1a8c commit bffc645
Show file tree
Hide file tree
Showing 3 changed files with 6,729 additions and 62 deletions.
14 changes: 12 additions & 2 deletions discord/interactions/helpCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { REST } from "@discordjs/rest";
import { ChatInputCommandInteraction, Client } from "discord.js";

import { slashCommandsArray } from "../slashCommands";

export const handleHelpCommand = async (
interaction: ChatInputCommandInteraction,
client: Client,
Expand All @@ -9,10 +11,18 @@ export const handleHelpCommand = async (
try {
const userId = interaction.member?.user?.id;
const guildId = interaction.guildId;
console.log({ interaction });

if (!userId || !guildId) return;

const commands =
slashCommandsArray
.map((cmd) => `• \`/${cmd.name}\` - ${cmd.description}`)
.join("\n") || "No commands available.";

const responseMessage = `**Available Commands:**\n${commands}\n\nFor support, join our [Telegram Group](https://t.me/+Mi34Im1Uafc1Y2Q8).\nFor more information, visit [Starky](https://starky.wtf/).`;

await interaction.reply({
content: "For more information, visit [Starky](https://starky.wtf/).",
content: responseMessage,
ephemeral: true,
});
} catch (error) {
Expand Down
171 changes: 111 additions & 60 deletions discord/slashCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,124 @@ import { Routes, SlashCommandBuilder } from "discord.js";
import config from "../config";
import WatchTowerLogger from "../watchTower";

export const registerSlashCommands = async () => {
type SlashCommandOption = {
type: "role" | "user";
name: string;
description: string;
required: boolean;
};

type SlashCommandData = {
name: string;
description: string;
options?: SlashCommandOption[];
};

export const slashCommandsArray: SlashCommandData[] = [
{
name: "starky-connect",
description: "Connect your Starknet wallet to this Discord server",
},
{
name: "starky-disconnect",
description: "Disconnect your Starknet wallet from this Discord server",
},
{
name: "starky-add-config",
description: "Add a starky configuration to this server",
options: [
{
type: "role",
name: "role",
description:
"What role do you want to assign to people matching your criteria?",
required: true,
},
],
},
{
name: "starky-delete-config",
description: "Delete a Starky configuration from this server",
},
{
name: "starky-refresh",
description: "Refresh your Starky roles on this server",
},
{
name: "starky-view-config",
description: "View your Starky configurations on this server",
options: [
{
type: "role",
name: "role",
description: "The role of the configuration you want to check.",
required: true,
},
],
},
{
name: "starky-debug-user",
description: "Debug a user on this server",
options: [
{
type: "user",
name: "user",
description: "The user you want to debug.",
required: true,
},
],
},
{
name: "starky-set-config-custom-api",
description:
"Set a custom API URI for a configuration (Instead of Starkscan)",
},
{ name: "help", description: "Get help with Starky" },
{
name: "list-configs",
description: "View your Starky configurations on this server",
},
];

const buildSlashCommand = (
commandData: SlashCommandData
): SlashCommandBuilder => {
const command = new SlashCommandBuilder()
.setName(commandData.name)
.setDescription(commandData.description);
commandData.options?.forEach((option) => {
if (option.type === "role") {
command.addRoleOption((opt) =>
opt
.setName(option.name)
.setDescription(option.description)
.setRequired(option.required)
);
} else if (option.type === "user") {
command.addUserOption((opt) =>
opt
.setName(option.name)
.setDescription(option.description)
.setRequired(option.required)
);
}
});
return command;
};

export const registerSlashCommands = async (): Promise<void> => {
const restDiscordClient = new REST({ version: "10" }).setToken(
config.DISCORD_BOT_TOKEN
);

const slashCommands = [
new SlashCommandBuilder()
.setName("starky-connect")
.setDescription("Connect your Starknet wallet to this Discord server"),
new SlashCommandBuilder()
.setName("starky-disconnect")
.setDescription(
"Disconnect your Starknet wallet from this Discord server"
),
new SlashCommandBuilder()
.setName("starky-add-config")
.setDescription("Add a starky configuration to this server")
.addRoleOption((option) =>
option
.setName("role")
.setDescription(
"What role do you want to assign to people matching your criteria?"
)
.setRequired(true)
),
new SlashCommandBuilder()
.setName("starky-delete-config")
.setDescription("Delete a Starky configuration from this server"),
new SlashCommandBuilder()
.setName("starky-refresh")
.setDescription("Refresh your Starky roles on this server"),
new SlashCommandBuilder()
.setName("starky-view-config")
.setDescription("View your Starky configurations on this server")
.addRoleOption((option) =>
option
.setName("role")
.setDescription("The role of the configuration you want to check.")
.setRequired(true)
),
new SlashCommandBuilder()
.setName("list-configs")
.setDescription("View your Starky configurations on this server"),
new SlashCommandBuilder()
.setName("starky-debug-user")
.setDescription("Debug a user on this server")
.addUserOption((option) =>
option
.setName("user")
.setDescription("The user you want to debug.")
.setRequired(true)
),
new SlashCommandBuilder()
.setName("starky-set-config-custom-api")
.setDescription(
"Set a custom API URI for a configuration (Instead of Starkscan)"
),
new SlashCommandBuilder()
.setName("help")
.setDescription("Display a link to help"),
].map((command) => command.toJSON());
const slashCommands = slashCommandsArray
.map(buildSlashCommand)
.map((cmd) => cmd.toJSON());

WatchTowerLogger.info("> Registering Discord slash commands...");
await restDiscordClient.put(
Routes.applicationCommands(config.NEXT_PUBLIC_DISCORD_CLIENT_ID),
{
body: slashCommands,
}
{ body: slashCommands }
);
WatchTowerLogger.info("> Registered Discord slash commands!");
};
Loading

0 comments on commit bffc645

Please sign in to comment.