WIP: [#1]: Athena Rewrite #1

Draft
nxbat wants to merge 14 commits from athena-rewrite into dev
3 changed files with 55 additions and 40 deletions
Showing only changes of commit 97ac053c69 - Show all commits
+52 -37
View File
@@ -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 { 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);
},
autoComplete: async function (client: Client, interaction: AutocompleteInteraction) {
if (!interaction.guild) return interaction.respond([]);
description: 'There was an issue locating the requested knowledgebase article.'
}]
});
const items: KnowledgebaseItem[] = await Database.getAllKnowledgebaseItems(interaction.guild.id);
return;
}
const value = interaction.options.getFocused();
await interaction.createMessage({
embeds: [{
...CreateDefaultEmbed(context),
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
})));
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');
+1 -1
View File
@@ -13,7 +13,7 @@ import { CreateDefaultEmbed } from '../../utils';
.setCommandType(Constants.ApplicationCommandType.ChatInput)
)
class AboutCommand extends Command<CommandClient> {
cooldown = 60;
cooldown = 5; // 5s.
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
if (!interaction.inGuild()) return;
+1 -1
View File
@@ -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 })
)
class NameSyncCommand extends Command<CommandClient> {
cooldown = 60;
cooldown = 360; // 5m.
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
if (!interaction.inGuild()) return;