Some work on channel-gating

This commit is contained in:
Charlie Laabs
2021-12-20 23:29:01 -06:00
parent 466c122dd2
commit a2ae99d75d
5 changed files with 85 additions and 28 deletions

View File

@@ -1,14 +1,53 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { SlashCommandBuilder, SlashCommandChannelOption } from '@discordjs/builders';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { ChannelType, Routes } from 'discord-api-types/v9';
import { config } from './config';
import { packageJson } from './util';
const CHANNEL_OPTIONS_MAX = 25;
const helpSlashCommand = new SlashCommandBuilder()
.setName('help')
.setDescription(`How to use ${packageJson().name}`);
const commands = [helpSlashCommand.toJSON()];
/**
* Helps generate a list of parameters for channel options
*/
const channelOptionsGenerator = (builder: SlashCommandChannelOption, index: number) =>
builder
.setName(`channel-${index + 1}`)
.setDescription('A text channel')
.setRequired(index === 0)
.addChannelType(ChannelType.GuildText as any);
const listenChannelCommand = new SlashCommandBuilder()
.setName('listen')
.addSubcommand((sub) => {
sub
.setName('add')
.setDescription(
`Add channels to learn from. Doesn't add the channel's past messages; re-train to do that.`
);
Array.from(Array(CHANNEL_OPTIONS_MAX).keys()).forEach((index) =>
sub.addChannelOption((opt) => channelOptionsGenerator(opt, index))
);
return sub;
})
.addSubcommand((sub) => {
sub
.setName('remove')
.setDescription(
`Remove channels from being learned from. Doesn't remove the channel's data; re-train to do that.`
);
Array.from(Array(CHANNEL_OPTIONS_MAX).keys()).forEach((index) =>
sub.addChannelOption((opt) => channelOptionsGenerator(opt, index))
);
return sub;
})
.setDescription(`How to use ${packageJson().name}`);
const commands = [helpSlashCommand.toJSON(), listenChannelCommand.toJSON()];
export async function deployCommands(clientId: string) {
const rest = new REST({ version: '9' }).setToken(config.token);