@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.
@@ -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) => msg.data.cts.owners.includes(msg.author.id), (i) => i.data.cts.owners.includes(i.user.id));
79
- exports.guildOnly = utils_2.createCheckDecorator((msg) => !!msg.guild, (i) => !!i.guildId);
80
- exports.dmOnly = utils_2.createCheckDecorator((msg) => !msg.guild, (i) => !i.guildId);
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,3 @@
1
+ export declare class DMOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DMOnlyCommandError = void 0;
4
+ class DMOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.DMOnlyCommandError = DMOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export declare class GuildOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildOnlyCommandError = void 0;
4
+ class GuildOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.GuildOnlyCommandError = GuildOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export declare class OwnerOnlyCommandError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OwnerOnlyCommandError = void 0;
4
+ class OwnerOnlyCommandError extends Error {
5
+ constructor() {
6
+ super();
7
+ }
8
+ }
9
+ exports.OwnerOnlyCommandError = OwnerOnlyCommandError;
@@ -0,0 +1,3 @@
1
+ export * from './OwnerOnlyCommand';
2
+ export * from './GuildOnlyCommand';
3
+ export * from './DMOnlyCommand';
@@ -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);
@@ -4,3 +4,4 @@ export * from './ArgumentNotProvided';
4
4
  export * from './ArgumentConverterNotFound';
5
5
  export * from './CommandCheckFailed';
6
6
  export * from './PermissionRequired';
7
+ export * from './checks';
@@ -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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikokr/command.ts",
3
3
  "description": "Discord.js command framework for typescript.",
4
- "version": "3.0.6-dev.292ef89",
4
+ "version": "3.0.6-dev.33d39ce",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -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) => msg.data.cts.owners.includes(msg.author.id),
115
- (i) => i.data.cts.owners.includes(i.user.id),
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) => !!msg.guild,
120
- (i) => !!i.guildId,
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) => !msg.guild,
125
- (i) => !i.guildId,
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) =>
@@ -0,0 +1,5 @@
1
+ export class DMOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export class GuildOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export class OwnerOnlyCommandError extends Error {
2
+ constructor() {
3
+ super()
4
+ }
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from './OwnerOnlyCommand'
2
+ export * from './GuildOnlyCommand'
3
+ export * from './DMOnlyCommand'
@@ -4,3 +4,4 @@ export * from './ArgumentNotProvided'
4
4
  export * from './ArgumentConverterNotFound'
5
5
  export * from './CommandCheckFailed'
6
6
  export * from './PermissionRequired'
7
+ export * from './checks'