Initial support for channel-based data storage

This commit is contained in:
Charlie Laabs
2021-12-21 23:19:14 -06:00
parent a2ae99d75d
commit 3b946b72ec
6 changed files with 177 additions and 79 deletions

View File

@@ -6,10 +6,27 @@ import { packageJson } from './util';
const CHANNEL_OPTIONS_MAX = 25;
const helpSlashCommand = new SlashCommandBuilder()
export const helpCommand = new SlashCommandBuilder()
.setName('help')
.setDescription(`How to use ${packageJson().name}`);
export const inviteCommand = new SlashCommandBuilder()
.setName('invite')
.setDescription('Get the invite link for this bot.');
export const messageCommand = new SlashCommandBuilder()
.setName(config.slashCommandName)
.setDescription('Generate a message from learned past messages')
.addBooleanOption((tts) =>
tts.setName('tts').setDescription('Read the message via text-to-speech.').setRequired(false)
)
.addBooleanOption((debug) =>
debug
.setName('debug')
.setDescription('Follow up the generated message with the detailed sources that inspired it.')
.setRequired(false)
);
/**
* Helps generate a list of parameters for channel options
*/
@@ -20,15 +37,15 @@ const channelOptionsGenerator = (builder: SlashCommandChannelOption, index: numb
.setRequired(index === 0)
.addChannelType(ChannelType.GuildText as any);
const listenChannelCommand = new SlashCommandBuilder()
export const listenChannelCommand = new SlashCommandBuilder()
.setName('listen')
.setDescription('Change what channels the bot actively listens to and learns from.')
.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))
);
@@ -45,9 +62,25 @@ const listenChannelCommand = new SlashCommandBuilder()
);
return sub;
})
.setDescription(`How to use ${packageJson().name}`);
.addSubcommand((sub) =>
sub
.setName('list')
.setDescription(`List the channels the bot is currently actively listening to.`)
);
const commands = [helpSlashCommand.toJSON(), listenChannelCommand.toJSON()];
export const trainCommand = new SlashCommandBuilder()
.setName('train')
.setDescription(
'Train from past messages from the configured listened channels. This takes a while.'
);
const commands = [
helpCommand.toJSON(),
inviteCommand.toJSON(),
messageCommand.toJSON(),
listenChannelCommand.toJSON(),
trainCommand.toJSON(),
];
export async function deployCommands(clientId: string) {
const rest = new REST({ version: '9' }).setToken(config.token);