This repository has been archived by the owner on Dec 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermissionCommand.ts
69 lines (64 loc) · 2.27 KB
/
PermissionCommand.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { PermissionsError } from "../../errors.js";
import { CommandManager } from "../../structures/CommandManager.js";
import { CommandPermissions } from "../../structures/CommandPermissions.js";
import { FunctionCommand, FunctionCommandInit } from "./FunctionCommand.js";
import { CommandType } from "../commandsTypes.js";
import { InputManager } from "../../structures/InputManager.js";
import { CommandPermissionsInit } from "../../structures/CommandPermissions.js";
/**
* Initialization options of base command with attached permissions
* @interface
* @extends {FunctionCommandInit}
*/
export interface PermissionCommandInit extends FunctionCommandInit {
/**
* Object with permissions' options and resolvables
* @type {?CommandPermissionsInit}
*/
permissions?: CommandPermissionsInit;
}
/**
* Executable command with attached permission system
* @class
* @extends {FunctionCommand}
*/
export class PermissionCommand extends FunctionCommand {
/**
* Object containing check functions and permission bitfields
* @type {CommandPermissions}
* @public
* @readonly
*/
public readonly permissions: CommandPermissions;
/**
* Constructor of command with attached permissions
* @constructor
* @param {CommandManager} manager - command manager attached to this command
* @param {CommandType} type - command type
* @param {PermissionCommandInit} options - command initalization options
*/
constructor(manager: CommandManager, type: CommandType, options: PermissionCommandInit) {
super(manager, type, {
name: options.name,
announceSuccess: options.announceSuccess,
default_permission: options.default_permission,
ephemeral: options.ephemeral,
function: options.function,
});
this.permissions = new CommandPermissions(this, options.permissions);
}
/**
* Invoke the command
* @param {InputManager} input - input data
* @returns {Promise<void>}
* @public
* @async
*/
public async start(input: InputManager): Promise<void> {
if (this.permissions.check(input.interaction)) {
await super.start(input);
} else {
throw new PermissionsError(this);
}
}
}