(rewrite): /cite command rewritten. (Never even tried this yet.)
This commit is contained in:
+54
-39
@@ -1,48 +1,63 @@
|
|||||||
import { ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
// External Imports
|
||||||
|
import { AutocompleteInteraction, Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from 'athena-prime';
|
||||||
|
|
||||||
|
// Internal Imports
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { KnowledgebaseItem } from '../types';
|
import { CreateDefaultEmbed, SetSeverity } from '../utils';
|
||||||
|
|
||||||
export default {
|
// ---------------
|
||||||
name: 'cite',
|
|
||||||
data: new SlashCommandBuilder()
|
|
||||||
.setName('cite')
|
|
||||||
.setDescription('Cite content from the knowledgebase.')
|
|
||||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
|
||||||
.setContexts(InteractionContextType.Guild)
|
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
|
|
||||||
.addIntegerOption(option =>
|
|
||||||
option
|
|
||||||
.setName('name')
|
|
||||||
.setDescription('The name of the entry.')
|
|
||||||
.setRequired(true)
|
|
||||||
.setAutocomplete(true)
|
|
||||||
),
|
|
||||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
|
||||||
if (!interaction.guild) return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Must be ran in guild.' });
|
|
||||||
|
|
||||||
await interaction.deferReply();
|
@SlashCommand(
|
||||||
|
new CommandBuilder('cite', 'Cite a knowledgebase article.')
|
||||||
|
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
||||||
|
.setContexts(Constants.InteractionContextType.Guild)
|
||||||
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
||||||
|
.addIntegerOption({ name: 'article', description: 'The article to cite.', required: true, autocomplete: true })
|
||||||
|
)
|
||||||
|
class CiteCommand extends Command<CommandClient> {
|
||||||
|
cooldown = 5; // 5s.
|
||||||
|
|
||||||
const id = interaction.options.getInteger('name', true);
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await interaction.defer();
|
||||||
|
|
||||||
const item = await Database.getFromKnowledgebase(id);
|
const article = interaction.getRequiredInteger('article');
|
||||||
|
const item = await Database.getFromKnowledgebase(article);
|
||||||
|
|
||||||
if (!item) return interaction.editReply('Knowledgebase item not found.');
|
if (!item) {
|
||||||
|
await interaction.createMessage({
|
||||||
|
embeds: [{
|
||||||
|
...CreateDefaultEmbed(context),
|
||||||
|
...SetSeverity('error'),
|
||||||
|
|
||||||
return interaction.editReply(item.content);
|
description: 'There was an issue locating the requested knowledgebase article.'
|
||||||
},
|
}]
|
||||||
autoComplete: async function (client: Client, interaction: AutocompleteInteraction) {
|
});
|
||||||
if (!interaction.guild) return interaction.respond([]);
|
|
||||||
|
|
||||||
const items: KnowledgebaseItem[] = await Database.getAllKnowledgebaseItems(interaction.guild.id);
|
return;
|
||||||
|
|
||||||
const value = interaction.options.getFocused();
|
|
||||||
|
|
||||||
const toRespond = items.filter(i => !value ? true : i.content.includes(value));
|
|
||||||
if (toRespond.length > 25) toRespond.length = 25;
|
|
||||||
|
|
||||||
interaction.respond(toRespond.map(p => ({
|
|
||||||
name: p.name,
|
|
||||||
value: p.id
|
|
||||||
})));
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
await interaction.createMessage({
|
||||||
|
embeds: [{
|
||||||
|
...CreateDefaultEmbed(context),
|
||||||
|
|
||||||
|
description: item.content
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleAutocomplete(context: CommandClient<any, any>, interaction: AutocompleteInteraction, data: any) {
|
||||||
|
if (!interaction.guild) return await interaction.acknowledge([]);
|
||||||
|
const items = await Database.getAllKnowledgebaseItems(interaction.guild.id);
|
||||||
|
|
||||||
|
const value = interaction.focused();
|
||||||
|
if(!value) return await interaction.acknowledge([]);
|
||||||
|
|
||||||
|
const response = items.filter(item => item.content.includes(value.value as string));
|
||||||
|
if (response.length > 25) response.length = 25;
|
||||||
|
|
||||||
|
return await interaction.acknowledge(response.map(res => ({ name: res.name, value: res.id })));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new CiteCommand('cite');
|
||||||
@@ -13,7 +13,7 @@ import { CreateDefaultEmbed } from '../../utils';
|
|||||||
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
||||||
)
|
)
|
||||||
class AboutCommand extends Command<CommandClient> {
|
class AboutCommand extends Command<CommandClient> {
|
||||||
cooldown = 60;
|
cooldown = 5; // 5s.
|
||||||
|
|
||||||
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
||||||
if (!interaction.inGuild()) return;
|
if (!interaction.inGuild()) return;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ async function fetchUser(member: Member, id: number | null): Promise<E621User |
|
|||||||
.addNumberOption({ name: 'id', description: 'The ID of the user to sync your name to.', required: false, max_value: 16 })
|
.addNumberOption({ name: 'id', description: 'The ID of the user to sync your name to.', required: false, max_value: 16 })
|
||||||
)
|
)
|
||||||
class NameSyncCommand extends Command<CommandClient> {
|
class NameSyncCommand extends Command<CommandClient> {
|
||||||
cooldown = 60;
|
cooldown = 360; // 5m.
|
||||||
|
|
||||||
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
||||||
if (!interaction.inGuild()) return;
|
if (!interaction.inGuild()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user