@pikokr/command.ts 3.0.6-dev.292ef89 → 3.0.6-dev.33d39ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command/decorator.js +27 -3
- package/dist/error/checks/DMOnlyCommand.d.ts +3 -0
- package/dist/error/checks/DMOnlyCommand.js +9 -0
- package/dist/error/checks/GuildOnlyCommand.d.ts +3 -0
- package/dist/error/checks/GuildOnlyCommand.js +9 -0
- package/dist/error/checks/OwnerOnlyCommand.d.ts +3 -0
- package/dist/error/checks/OwnerOnlyCommand.js +9 -0
- package/dist/error/checks/index.d.ts +3 -0
- package/dist/error/checks/index.js +15 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +1 -0
- package/package.json +1 -1
- package/src/command/decorator.ts +25 -7
- package/src/error/checks/DMOnlyCommand.ts +5 -0
- package/src/error/checks/GuildOnlyCommand.ts +5 -0
- package/src/error/checks/OwnerOnlyCommand.ts +5 -0
- package/src/error/checks/index.ts +3 -0
- package/src/error/index.ts +1 -0
|
@@ -75,9 +75,33 @@ const rest = (target, propertyKey, parameterIndex) => {
|
|
|
75
75
|
Reflect.defineMetadata(constants_1.KRest, parameterIndex, target, propertyKey);
|
|
76
76
|
};
|
|
77
77
|
exports.rest = rest;
|
|
78
|
-
exports.ownerOnly = utils_2.createCheckDecorator((msg) =>
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
exports.ownerOnly = utils_2.createCheckDecorator((msg) => {
|
|
79
|
+
if (msg.data.cts.owners.includes(msg.author.id))
|
|
80
|
+
return true;
|
|
81
|
+
throw new error_1.OwnerOnlyCommandError();
|
|
82
|
+
}, (i) => {
|
|
83
|
+
if (i.data.cts.owners.includes(i.user.id))
|
|
84
|
+
return true;
|
|
85
|
+
throw new error_1.OwnerOnlyCommandError();
|
|
86
|
+
});
|
|
87
|
+
exports.guildOnly = utils_2.createCheckDecorator((msg) => {
|
|
88
|
+
if (!!msg.guild)
|
|
89
|
+
return true;
|
|
90
|
+
throw new error_1.GuildOnlyCommandError();
|
|
91
|
+
}, (i) => {
|
|
92
|
+
if (!!i.guildId)
|
|
93
|
+
return true;
|
|
94
|
+
throw new error_1.GuildOnlyCommandError();
|
|
95
|
+
});
|
|
96
|
+
exports.dmOnly = utils_2.createCheckDecorator((msg) => {
|
|
97
|
+
if (!msg.guild)
|
|
98
|
+
return true;
|
|
99
|
+
throw new error_1.DMOnlyCommandError();
|
|
100
|
+
}, (i) => {
|
|
101
|
+
if (!i.guildId)
|
|
102
|
+
return true;
|
|
103
|
+
throw new error_1.DMOnlyCommandError();
|
|
104
|
+
});
|
|
81
105
|
const requireUserPermissions = (permission) => utils_2.createCheckDecorator((msg) => {
|
|
82
106
|
if (!msg.guild || !msg.member)
|
|
83
107
|
throw new Error('This command must be used in guild.');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./OwnerOnlyCommand"), exports);
|
|
14
|
+
__exportStar(require("./GuildOnlyCommand"), exports);
|
|
15
|
+
__exportStar(require("./DMOnlyCommand"), exports);
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -16,3 +16,4 @@ __exportStar(require("./ArgumentNotProvided"), exports);
|
|
|
16
16
|
__exportStar(require("./ArgumentConverterNotFound"), exports);
|
|
17
17
|
__exportStar(require("./CommandCheckFailed"), exports);
|
|
18
18
|
__exportStar(require("./PermissionRequired"), exports);
|
|
19
|
+
__exportStar(require("./checks"), exports);
|
package/package.json
CHANGED
package/src/command/decorator.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ArgumentConverter, SlashArgumentConverter } from './ArgumentConverter'
|
|
|
5
5
|
import { Module } from '../structures'
|
|
6
6
|
import { createCheckDecorator } from './utils'
|
|
7
7
|
import { GuildMember, Message, PermissionResolvable, Permissions, TextChannel } from 'discord.js'
|
|
8
|
-
import { ClientPermissionRequired, UserPermissionRequired } from '../error'
|
|
8
|
+
import { ClientPermissionRequired, DMOnlyCommandError, GuildOnlyCommandError, OwnerOnlyCommandError, UserPermissionRequired } from '../error'
|
|
9
9
|
|
|
10
10
|
type CommandOptions = {
|
|
11
11
|
name: string
|
|
@@ -111,18 +111,36 @@ export const rest: ParameterDecorator = (target, propertyKey, parameterIndex) =>
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export const ownerOnly = createCheckDecorator(
|
|
114
|
-
(msg) =>
|
|
115
|
-
|
|
114
|
+
(msg) => {
|
|
115
|
+
if (msg.data.cts.owners.includes(msg.author.id)) return true
|
|
116
|
+
throw new OwnerOnlyCommandError()
|
|
117
|
+
},
|
|
118
|
+
(i) => {
|
|
119
|
+
if (i.data.cts.owners.includes(i.user.id)) return true
|
|
120
|
+
throw new OwnerOnlyCommandError()
|
|
121
|
+
},
|
|
116
122
|
)
|
|
117
123
|
|
|
118
124
|
export const guildOnly = createCheckDecorator(
|
|
119
|
-
(msg) =>
|
|
120
|
-
|
|
125
|
+
(msg) => {
|
|
126
|
+
if (!!msg.guild) return true
|
|
127
|
+
throw new GuildOnlyCommandError()
|
|
128
|
+
},
|
|
129
|
+
(i) => {
|
|
130
|
+
if (!!i.guildId) return true
|
|
131
|
+
throw new GuildOnlyCommandError()
|
|
132
|
+
},
|
|
121
133
|
)
|
|
122
134
|
|
|
123
135
|
export const dmOnly = createCheckDecorator(
|
|
124
|
-
(msg) =>
|
|
125
|
-
|
|
136
|
+
(msg) => {
|
|
137
|
+
if (!msg.guild) return true
|
|
138
|
+
throw new DMOnlyCommandError()
|
|
139
|
+
},
|
|
140
|
+
(i) => {
|
|
141
|
+
if (!i.guildId) return true
|
|
142
|
+
throw new DMOnlyCommandError()
|
|
143
|
+
},
|
|
126
144
|
)
|
|
127
145
|
|
|
128
146
|
export const requireUserPermissions = (permission: PermissionResolvable) =>
|
package/src/error/index.ts
CHANGED