feat: refactored handling of validators

This commit is contained in:
Marius Begby committed 2023-09-05 21:35:18 +02:00
1 parent e67d0004b0
commit 8c05499f08
31 files changed
+316 -338

No files matched your search

+4 -4
View File
@@ -1,7 +1,7 @@
import { EmbedBuilder, Guild, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
class GuildsCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -10,15 +10,15 @@ class GuildsCommand extends BaseSlashCommandInteraction {
.setDescription('Show the top 25 guilds by member count.');
const isSystemCommand: boolean = true;
super(data, isSystemCommand);
this.validators = [(args) => checkValidGuildId(args)];
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
if (await notValidGuildId({ interaction, executionId })) {
return;
}
await this.runValidators({ interaction, executionId });
let shardGuilds: Guild[] = [];
let totalGuildCount: number = 0;
+4 -4
View File
@@ -2,7 +2,7 @@ import { ApplicationCommandOption, ApplicationCommandOptionData, EmbedBuilder, S
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
class ReloadCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -11,15 +11,15 @@ class ReloadCommand extends BaseSlashCommandInteraction {
.setDescription('Reload slash command, autocomplete and component interactions across shards.');
const isSystemCommand: boolean = true;
super(data, isSystemCommand);
this.validators = [(args) => checkValidGuildId(args)];
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
if (await notValidGuildId({ interaction, executionId })) {
return;
}
await this.runValidators({ interaction, executionId });
try {
logger.debug('Reloading interaction module across all shards.');
+4 -4
View File
@@ -2,7 +2,7 @@ import { EmbedBuilder, EmbedField, SlashCommandBuilder } from 'discord.js';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, ShardInfo } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
class ShardsCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -29,15 +29,15 @@ class ShardsCommand extends BaseSlashCommandInteraction {
);
const isSystemCommand: boolean = true;
super(data, isSystemCommand);
this.validators = [(args) => checkValidGuildId(args)];
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
if (await notValidGuildId({ interaction, executionId })) {
return;
}
await this.runValidators({ interaction, executionId });
let shardInfoList: ShardInfo[] = [];
@@ -5,7 +5,7 @@ import { dependencies, version } from '../../../../package.json';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { getUptimeFormatted } from '../../../utils/system/getUptimeFormatted';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
class SystemStatusCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -14,15 +14,15 @@ class SystemStatusCommand extends BaseSlashCommandInteraction {
.setDescription('Show operational status of the bot with additional technical information.');
const isSystemCommand: boolean = true;
super(data, isSystemCommand);
this.validators = [(args) => checkValidGuildId(args)];
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
if (await notValidGuildId({ interaction, executionId })) {
return;
}
await this.runValidators({ interaction, executionId });
// from normal /status command
const uptimeString: string = await getUptimeFormatted({ executionId });