diff --git a/deploy-commands.cjs b/deploy-commands.cjs index 0f8b9b7..8b48fea 100644 --- a/deploy-commands.cjs +++ b/deploy-commands.cjs @@ -4,6 +4,7 @@ const { token } = require('./config.json'); const { exec } = require('child_process'); const rest = new REST({ version: "9" }).setToken(token); +const appID = '898850107892596776'; console.log('building...'); exec('pnpm tsc', (err, stdout, stderr) => { @@ -16,11 +17,25 @@ exec('pnpm tsc', (err, stdout, stderr) => { for (const file of commandFiles) { const command = require(`./built/commands/${file}`); - commands.push(command.data.toJSON()); + commands.push(command); } + const knownServers = require('./built/lib/knownServers').knownServers; + const servers = [...new Set(Object.values(knownServers).reduce((a, b) => a.concat(b), []))]; + + for (const id of servers) { + const serverCommands = commands.filter(command => command.serverWhitelist && command.serverWhitelist.includes(id)); + + rest + .put(Routes.applicationGuildCommands(appID, id), { body: serverCommands.map(cmd => cmd.data.toJSON()) }) + .then(() => console.log(`${serverCommands.length} commands added to ${id}`)) + .catch(console.error); + } + + const globalCommands = commands.filter(command => !command.serverWhitelist); + rest - .put(Routes.applicationGuildCommands('898850107892596776', '587108210121506816'), { body: commands }) - .then(() => console.log(`${commands.length} commands added`)) + .put(Routes.applicationCommands(appID), { body: globalCommands.map(cmd => cmd.data.toJSON()) }) + .then(() => console.log(`${globalCommands.length} commands added globally, might take a bit to refresh`)) .catch(console.error); }); \ No newline at end of file diff --git a/src/commands/change.ts b/src/commands/change.ts index c1575c0..221f265 100644 --- a/src/commands/change.ts +++ b/src/commands/change.ts @@ -1,4 +1,5 @@ import { CategoryChannel, GuildMember, EmbedBuilder, TextChannel, Interaction, ChannelType, SlashCommandBuilder } from 'discord.js'; +import { knownServers } from '../lib/knownServers'; const rand = [ 'This change has no significance.', @@ -48,6 +49,8 @@ module.exports = { .setRequired(true) ), + serverWhitelist: [...knownServers.firepit, ...knownServers.fbi], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/color.ts b/src/commands/color.ts index 808a299..983981f 100644 --- a/src/commands/color.ts +++ b/src/commands/color.ts @@ -1,6 +1,7 @@ import { RoleCreateOptions, GuildMember, Interaction, EmbedBuilder, TextChannel, ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder } from 'discord.js'; import { default as parseColor, Color } from 'parse-color'; import { isColorRole, COLOR_ROLE_SEPERATOR } from '../lib/assignableRoles'; +import { knownServers } from '../lib/knownServers'; const PREVIEW_DURATION = 1000 * 60; @@ -45,6 +46,8 @@ module.exports = { option.setName('preview').setDescription('Preview the color instead of applying it') ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/decrease.ts b/src/commands/decrease.ts index 69a145d..2fdd2cb 100644 --- a/src/commands/decrease.ts +++ b/src/commands/decrease.ts @@ -1,5 +1,6 @@ import { Interaction, GuildMember, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction } from '../lib/counter'; +import { knownServers } from '../lib/knownServers'; module.exports = { data: new SlashCommandBuilder() @@ -13,6 +14,8 @@ module.exports = { .setMinValue(1) ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/decrease2.ts b/src/commands/decrease2.ts index 82fc36d..cebe55f 100644 --- a/src/commands/decrease2.ts +++ b/src/commands/decrease2.ts @@ -1,5 +1,6 @@ import { Interaction, GuildMember, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction, getCounter } from '../lib/counter'; +import { knownServers } from '../lib/knownServers'; module.exports = { data: new SlashCommandBuilder() @@ -13,6 +14,8 @@ module.exports = { .setMinValue(1) ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/garbagecollectroles.ts b/src/commands/garbagecollectroles.ts index feeb8cc..07ccf09 100644 --- a/src/commands/garbagecollectroles.ts +++ b/src/commands/garbagecollectroles.ts @@ -1,5 +1,6 @@ import { Guild, GuildMember, Interaction, Role, SlashCommandBuilder } from 'discord.js'; import { isColorRole, isPronounRole } from '../lib/assignableRoles'; +import { knownServers } from '../lib/knownServers'; async function fetchRoleMembers(role: Role) { const members = await role.guild.members.fetch(); @@ -27,6 +28,8 @@ module.exports = { .addBooleanOption((option) => option.setName('dry-run').setDescription('Only show roles that would be deleted.')) .setDefaultMemberPermissions('0'), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/increase.ts b/src/commands/increase.ts index 29f4449..b178b66 100644 --- a/src/commands/increase.ts +++ b/src/commands/increase.ts @@ -1,5 +1,6 @@ import { GuildMember, Interaction, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction } from '../lib/counter'; +import { knownServers } from '../lib/knownServers'; module.exports = { data: new SlashCommandBuilder() @@ -13,6 +14,8 @@ module.exports = { .setMinValue(1) ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/increase2.ts b/src/commands/increase2.ts index c606e9e..b6e9353 100644 --- a/src/commands/increase2.ts +++ b/src/commands/increase2.ts @@ -1,5 +1,6 @@ import { GuildMember, Interaction, SlashCommandBuilder } from 'discord.js'; import { changeCounterInteraction } from '../lib/counter'; +import { knownServers } from '../lib/knownServers'; module.exports = { data: new SlashCommandBuilder() @@ -13,6 +14,8 @@ module.exports = { .setMinValue(1) ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/monitor.ts b/src/commands/monitor.ts index 225de96..559c248 100644 --- a/src/commands/monitor.ts +++ b/src/commands/monitor.ts @@ -1,5 +1,6 @@ import { EmbedBuilder, Interaction, SlashCommandBuilder } from 'discord.js'; import got from 'got'; +import { knownServers } from '../lib/knownServers'; const rand = require('random-seed').create(); const imagesEndpoint = 'https://commons.wikimedia.org/w/api.php?action=query&cmlimit=500&cmtitle=Category%3ALiminal_spaces&cmtype=file&list=categorymembers&format=json'; @@ -16,6 +17,8 @@ module.exports = { .setRequired(true) ), + serverWhitelist: [...knownServers.firepit_extended, ...knownServers.fbi], + execute: async (interaction: Interaction) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/pronouns.ts b/src/commands/pronouns.ts index 2c285f5..78b2c65 100644 --- a/src/commands/pronouns.ts +++ b/src/commands/pronouns.ts @@ -1,5 +1,6 @@ import { RoleCreateOptions, GuildMember, Interaction, SlashCommandBuilder } from 'discord.js'; import { pronouns, PRONOUN_ROLE_SEPERATOR } from '../lib/assignableRoles'; +import { knownServers } from '../lib/knownServers'; function extendOption(t: string) { return {name: t, value: t}; @@ -17,6 +18,8 @@ module.exports = { .setChoices(...Array.from(pronouns.values()).map(extendOption)) ), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: Interaction, member: GuildMember) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/survey.ts b/src/commands/survey.ts index bbe8df8..31189e2 100644 --- a/src/commands/survey.ts +++ b/src/commands/survey.ts @@ -1,5 +1,6 @@ import { CommandInteraction, GuildMember, ActionRowBuilder, ButtonBuilder, Client, Collection, MessageComponentInteraction, StringSelectMenuBuilder, ModalBuilder, TextChannel, TextInputStyle, Message, ButtonStyle, ComponentType, APIButtonComponentWithCustomId, Events, TextInputBuilder, SlashCommandBuilder } from 'discord.js'; import * as fs from 'fs/promises'; +import { knownServers } from '../lib/knownServers'; const SURVEY_CHANNEL = '983479509376434216'; const RESPONSES_CHANNEL = '983762973858361364'; @@ -604,6 +605,8 @@ module.exports = { .setName('createsurvey') .setDescription('Re-create the survey button'), + serverWhitelist: [...knownServers.firepit], + execute: async (interaction: CommandInteraction) => { const row = new ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId('survey-take').setLabel('Take Survey').setStyle(ButtonStyle.Secondary) diff --git a/src/lib/knownServers.ts b/src/lib/knownServers.ts new file mode 100644 index 0000000..e975dc9 --- /dev/null +++ b/src/lib/knownServers.ts @@ -0,0 +1,5 @@ +export const knownServers = { + firepit: ['587108210121506816'], + firepit_extended: ['587108210121506816', '848904454573260881'], + fbi: ['1155873339525562398'] +}; \ No newline at end of file