Adds eslint and linted & improved routing for interactions

This commit is contained in:
Michel Fedde 2025-06-17 20:37:53 +02:00
parent 83209f642c
commit 441715675c
35 changed files with 2091 additions and 463 deletions

View file

@ -2,41 +2,26 @@ import {GroupConfigurationTransformers, TransformerType} from "./GroupConfigurat
import {GroupConfigurationHandler} from "./GroupConfigurationHandler";
import {
ActionRowBuilder,
AnyComponentBuilder, AnySelectMenuInteraction,
APISelectMenuComponent,
AnySelectMenuInteraction,
ButtonBuilder,
ButtonStyle, channelMention,
ChannelSelectMenuBuilder, ChannelSelectMenuInteraction,
ChannelType,
ChatInputCommandInteraction, codeBlock,
EmbedBuilder, inlineCode,
InteractionCallbackResponse,
InteractionEditReplyOptions,
ChannelSelectMenuBuilder, ChannelType,
ChatInputCommandInteraction, EmbedBuilder, inlineCode, Interaction,
InteractionReplyOptions,
InteractionUpdateOptions, italic, MessageFlags,
SelectMenuBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder, TextBasedChannel,
UserSelectMenuBuilder
StringSelectMenuOptionBuilder, UserSelectMenuBuilder
} from "discord.js";
import {Logger} from "log4js";
import {Container} from "../Container/Container";
import {Nullable} from "../types/Nullable";
import GroupConfiguration from "../Database/tables/GroupConfiguration";
import {
BaseSelectMenuBuilder,
MentionableSelectMenuBuilder,
MessageActionRowComponentBuilder,
RoleSelectMenuBuilder
} from "@discordjs/builders";
import {unwatchFile} from "node:fs";
import {UserError} from "../Discord/UserError";
import {RuntimeGroupConfiguration} from "./RuntimeGroupConfiguration";
import {ChannelId} from "../types/DiscordTypes";
import {IconCache} from "../Icons/IconCache";
import {ifError} from "node:assert";
import {DiscordClient} from "../Discord/DiscordClient";
import {channel} from "node:diagnostics_channel";
type UIElementCollection = Record<string, UIElement>;
type UIElement = {
@ -104,7 +89,7 @@ export class GroupConfigurationRenderer {
let response = await interaction.reply(this.getReplyOptions());
let exit = false;
let eventResponse;
const filter = i => i.user.id === interaction.user.id;
const filter = (i: Interaction) => i.user.id === interaction.user.id;
do {
if (eventResponse) {
@ -117,7 +102,7 @@ export class GroupConfigurationRenderer {
filter: filter,
time: 60_000
});
} catch (e) {
} catch (_: unknown) {
break;
}
@ -139,7 +124,7 @@ export class GroupConfigurationRenderer {
}
if (eventResponse.customId.startsWith(GroupConfigurationRenderer.SETVALUE_COMMAND)) {
this.handleSelection(eventResponse);
this.handleSelection(<AnySelectMenuInteraction>eventResponse);
continue;
}
@ -150,7 +135,7 @@ export class GroupConfigurationRenderer {
await eventResponse.update(
this.getReplyOptions()
);
} catch (e) {
} catch (_) {
}
await eventResponse.deleteReply();
@ -170,6 +155,7 @@ export class GroupConfigurationRenderer {
private getReplyOptions(): InteractionUpdateOptions & InteractionReplyOptions & { withResponse: true } {
const embed = this.createEmbed();
const icons = Container.get<IconCache>(IconCache.name);
embed.setAuthor({
name: "/ " + this.breadcrumbs.join(" / ")
});
@ -177,7 +163,8 @@ export class GroupConfigurationRenderer {
const exitButton = new ButtonBuilder()
.setLabel("Exit")
.setStyle(ButtonStyle.Danger)
.setCustomId("exit");
.setCustomId("exit")
.setEmoji(icons.get("door_open_solid_white") ?? '');
const actionrow = new ActionRowBuilder<ButtonBuilder>()
@ -185,7 +172,8 @@ export class GroupConfigurationRenderer {
const backButton = new ButtonBuilder()
.setLabel("Back")
.setStyle(ButtonStyle.Secondary)
.setCustomId(GroupConfigurationRenderer.MOVEBACK_COMMAND);
.setCustomId(GroupConfigurationRenderer.MOVEBACK_COMMAND)
.setEmoji(icons.get("angle_left_solid") ?? '');
actionrow.addComponents(backButton)
}
@ -201,7 +189,7 @@ export class GroupConfigurationRenderer {
}
private createEmbed(): EmbedBuilder {
const {currentCollection, currentElement} = this.findCurrentUI();
const {currentElement} = this.findCurrentUI();
if (currentElement === null) {
return new EmbedBuilder()
@ -224,7 +212,7 @@ export class GroupConfigurationRenderer {
private getCurrentValueAsUI(): string {
const path = this.breadcrumbs.join(".");
let value = this.configurationHandler.getConfigurationByPath(path);
const value = this.configurationHandler.getConfigurationByPath(path);
if (value === undefined) return italic("None");
@ -263,7 +251,7 @@ export class GroupConfigurationRenderer {
if (currentElement?.isConfiguration ?? false) {
return [
new ActionRowBuilder<ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder>()
.addComponents(this.getSelectForBreadcrumbs(<UIElement>currentElement))
.addComponents(this.getSelectForBreadcrumbs())
]
}
@ -274,13 +262,13 @@ export class GroupConfigurationRenderer {
.setLabel(` ${elem.label}`)
.setStyle(ButtonStyle.Primary)
.setCustomId(GroupConfigurationRenderer.MOVETO_COMMAND + elem.key)
.setEmoji(icons.get("folder_tree_solid") ?? '')
.setEmoji(icons.get(elem.isConfiguration ? 'pen_solid' : "folder_solid") ?? '')
)
)
]
}
private getSelectForBreadcrumbs(currentElement: UIElement): ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder {
private getSelectForBreadcrumbs(): ChannelSelectMenuBuilder | MentionableSelectMenuBuilder | RoleSelectMenuBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder {
const breadcrumbPath = this.breadcrumbs.join('.')
const transformerType = this.transformers.getTransformerType(breadcrumbPath);
if (transformerType === undefined) {
@ -300,7 +288,7 @@ export class GroupConfigurationRenderer {
.setCustomId(GroupConfigurationRenderer.SETVALUE_COMMAND + breadcrumbPath)
.setOptions(
options.map(intl => new StringSelectMenuOptionBuilder()
.setLabel(displaynames.of(intl))
.setLabel(displaynames.of(intl) ?? '')
.setValue(intl)
)
)