Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { CanActivate, ExecutionContext, Inject, Injectable } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { ChatInputCommandInteraction } from "discord.js";
import { NecordExecutionContext } from "necord";
import { CommandConfig } from "../decorators";
@Injectable()
export class CommandConfigGuard implements CanActivate {
public constructor(
@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
private readonly reflector: Reflector,
) {}
public async canActivate(executionContext: ExecutionContext): Promise<boolean> {
const commandConfig = this.reflector.get(CommandConfig.KEY, executionContext.getHandler());
const context = NecordExecutionContext.create(executionContext);
const args = context.getArgByIndex(0);
const interaction = args[0] as ChatInputCommandInteraction;
if (commandConfig.disable) {
interaction.reply(this.translate.getTranslation("Tools.Command.Checker.Disable", interaction.guildLocale));
return false;
}
return true;
}
}
|