diff --git a/package-lock.json b/package-lock.json index a70f430..611907c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,8 +6,8 @@ "": { "name": "ikea-canada-support", "dependencies": { + "@discordjs/builders": "^0.5.0", "@discordjs/rest": "^0.1.0-canary.0", - "discord-api-types": "^0.22.0", "discord.js": "^13.1.0" }, "devDependencies": { diff --git a/package.json b/package.json index 73173a8..1cfc35e 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "ts-node": "^10.1.0" }, "dependencies": { + "@discordjs/builders": "^0.5.0", "@discordjs/rest": "^0.1.0-canary.0", - "discord-api-types": "^0.22.0", "discord.js": "^13.1.0" } } diff --git a/rolemanager/data.ts b/rolemanager/data.ts index 6b180c9..f01fabd 100644 --- a/rolemanager/data.ts +++ b/rolemanager/data.ts @@ -2,12 +2,12 @@ import * as Opt from "../types/Opt"; //array of Opt.Row|Opt.Menu, each one is a message that will be sent/understood // - types/Opt.d.ts -const InteractionRoles: (Opt.Row|Opt.Menu)[] = [ +export const InteractionRoles: (Opt.Row|Opt.Menu)[] = [ { type: 'menu', message: 'Pronouns', palceholder: '', - id: 'rolemenu', + id: 'pronounsmenu', max: 'all', options: [ { @@ -106,7 +106,7 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [ type: 'menu', message: 'Other Roles', palceholder: '', - id: 'otherrolesmenu', + id: 'rolesmenu', max: 'all', options: [ { @@ -123,4 +123,4 @@ const InteractionRoles: (Opt.Row|Opt.Menu)[] = [ } ]; -export default InteractionRoles; \ No newline at end of file +export const GuildId = '861404201645244416'; \ No newline at end of file diff --git a/rolemanager/package.json b/rolemanager/package.json index efcfd2b..aa57d69 100644 --- a/rolemanager/package.json +++ b/rolemanager/package.json @@ -3,7 +3,7 @@ "main": "index.ts", "scripts": { "start": "ts-node .", - "debug": "ts-node .", + "ts-node": "ts-node", "watchdog": "./run.sh", "tmux": "tmux new-session -d -s $npm_package_name \"./run.sh\"", "resume": "tmux a -t $npm_package_name", diff --git a/rolemanager/slash.ts b/rolemanager/slash.ts new file mode 100644 index 0000000..7255996 --- /dev/null +++ b/rolemanager/slash.ts @@ -0,0 +1,67 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { REST } from '@discordjs/rest'; +import { Routes } from 'discord-api-types/v9'; +import { GuildId, InteractionRoles } from './data'; + +const commands = [ + + //roles ====== + new SlashCommandBuilder() + .setName('roles') + .setDescription('displays the role selections') + .addIntegerOption((option) => { + option + .setName('category') + .setDescription('the category of roles that will be displayed') + .setRequired(true) + + InteractionRoles.forEach((opt, i) => option.addChoice(opt.message, i)); + + return option; + }) + .toJSON(), + + //rolesall ====== + new SlashCommandBuilder() + .setName('rolesall') + .setDescription('displays the role selections for everyone') + .addIntegerOption((option) => { + + option + .setName('category') + .setDescription('the category of roles that will be displayed') + + InteractionRoles.forEach((opt, i) => option.addChoice(opt.message, i)); + + return option; + }) + .addChannelOption(option => + option + .setName('channel') + .setDescription('the channel the message(s) will be sent in')) + .toJSON(), + + //updateroles ====== + new SlashCommandBuilder() + .setName('updateroles') + .setDescription('updates the cached role options') + .toJSON() + +]; + +const rest = new REST({ version: '9' }).setToken(require('fs').readFileSync('../token').toString()); + +export default async function refreshCommands(ClientId: string) { + + try { + + await rest.put( + Routes.applicationGuildCommands(ClientId, GuildId), + { body: commands }, + ); + + } catch (error) { + console.error(error); + } + +} \ No newline at end of file diff --git a/types/Opt.d.ts b/types/Opt.d.ts index 13fbd3a..00dd318 100644 --- a/types/Opt.d.ts +++ b/types/Opt.d.ts @@ -31,5 +31,6 @@ export interface RowButton { export interface Row { type: 'row'; message: string; + id: string; //not needed for api, just needed for slash commands buttons: [RowButton?, RowButton?, RowButton?, RowButton?, RowButton?]; }