refactor command loading, now some are specific to servers and some are global
This commit is contained in:
parent
3dc74d722e
commit
561c039135
|
@ -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);
|
||||
});
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder().setCustomId('survey-take').setLabel('Take Survey').setStyle(ButtonStyle.Secondary)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
export const knownServers = {
|
||||
firepit: ['587108210121506816'],
|
||||
firepit_extended: ['587108210121506816', '848904454573260881'],
|
||||
fbi: ['1155873339525562398']
|
||||
};
|
Loading…
Reference in New Issue