@pikokr/command.ts 3.0.8-dev.00f7d77 → 3.0.8-dev.9957e57

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 파링
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Command.TS
2
2
 
3
- Command framework for discord.js
3
+ [![.github/workflows/publish.yml](https://github.com/pikokr/command.ts/actions/workflows/publish.yml/badge.svg)](https://github.com/pikokr/command.ts/actions/workflows/publish.yml)
4
+
5
+ ![cts](https://user-images.githubusercontent.com/68010770/145200458-b14c5e4e-6927-4516-8d48-c68a384d2a20.png)
4
6
 
5
- [Discord](https://discord.gg/EEhcPzsGHV) [가이드](https://pikokr.notion.site/a60262db37724fd38e4b7fc83be7e52d)
7
+ Command framework for discord.js
6
8
 
7
- [V2 문서](https://command-ts-docs-ezojnktwv-pikokr.vercel.app/)
9
+ [Discord](https://discord.gg/EEhcPzsGHV) / [문서](https://v3.cts.pikokr.dev) / [V2 문서](https://command-ts-docs-ezojnktwv-pikokr.vercel.app/)
@@ -37,18 +37,30 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
37
37
  }
38
38
  }
39
39
  user(msg, value) {
40
+ let user = this.client.users.cache.get(value);
41
+ if (user)
42
+ return user;
43
+ user = this.client.users.cache.find(x => x.tag === value);
44
+ if (user)
45
+ return user;
40
46
  const id = this.getUserIDByMention(value);
41
47
  if (!id)
42
48
  return null;
43
- const user = this.client.users.cache.get(id);
49
+ user = this.client.users.cache.get(id);
44
50
  return user || null;
45
51
  }
46
52
  member(msg, value) {
47
- var _a;
53
+ var _a, _b, _c;
54
+ let user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(value);
55
+ if (!user)
56
+ return user;
57
+ user = (_b = msg.guild) === null || _b === void 0 ? void 0 : _b.members.cache.find(x => x.user.tag === value);
58
+ if (user)
59
+ return user;
48
60
  const id = this.getUserIDByMention(value);
49
61
  if (!id)
50
62
  return;
51
- const user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(id);
63
+ user = (_c = msg.guild) === null || _c === void 0 ? void 0 : _c.members.cache.get(id);
52
64
  return user || undefined;
53
65
  }
54
66
  number(msg, value) {
@@ -32,6 +32,9 @@ class CommandHandler extends BuiltInModule_1.BuiltInModule {
32
32
  }
33
33
  message(msg) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
+ if (!(yield this.client.options.command.check(msg))) {
36
+ return;
37
+ }
35
38
  const error = (error) => this.client.client.emit('commandError', error, msg);
36
39
  try {
37
40
  const prefixList = typeof this.client.options.command.prefix === 'string'
@@ -1,9 +1,10 @@
1
1
  import { Registry } from './Registry';
2
- import { Client, Snowflake } from 'discord.js';
2
+ import { Client, Message, Snowflake } from 'discord.js';
3
3
  import { CoolDownAdapter } from '../command';
4
4
  import { REST } from '@discordjs/rest';
5
5
  export interface CommandOptions {
6
6
  prefix: string | ((msg: any) => string | Promise<string | string[]> | string[]) | string[];
7
+ check: (msg: Message) => boolean | Promise<boolean>;
7
8
  }
8
9
  export interface SlashCommandOptions {
9
10
  guild?: Snowflake | Snowflake[];
@@ -44,6 +44,7 @@ class CommandClient {
44
44
  this.options = lodash_1.default.merge({
45
45
  command: {
46
46
  prefix: '!',
47
+ check: () => true
47
48
  },
48
49
  owners: 'auto',
49
50
  slashCommands: {
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.8-dev.00f7d77",
4
+ "version": "3.0.8-dev.9957e57",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -34,17 +34,25 @@ export class BuiltinCommandConverters extends BuiltInModule {
34
34
 
35
35
  @argumentConverter(User)
36
36
  user(msg: Message, value: string): User | null {
37
+ let user = this.client.users.cache.get(value)
38
+ if (user) return user
39
+ user = this.client.users.cache.find(x=>x.tag === value)
40
+ if (user) return user
37
41
  const id = this.getUserIDByMention(value)
38
42
  if (!id) return null
39
- const user = this.client.users.cache.get(id)
43
+ user = this.client.users.cache.get(id)
40
44
  return user || null
41
45
  }
42
46
 
43
47
  @argumentConverter(GuildMember)
44
48
  member(msg: Message, value: string): GuildMember | undefined {
49
+ let user = msg.guild?.members.cache.get(value)
50
+ if (!user) return user
51
+ user = msg.guild?.members.cache.find(x=>x.user.tag===value)
52
+ if (user) return user
45
53
  const id = this.getUserIDByMention(value)
46
54
  if (!id) return
47
- const user = msg.guild?.members.cache.get(id)
55
+ user = msg.guild?.members.cache.get(id)
48
56
  return user || undefined
49
57
  }
50
58
 
@@ -17,6 +17,10 @@ export class CommandHandler extends BuiltInModule {
17
17
 
18
18
  @listener('messageCreate')
19
19
  async message(msg: Message) {
20
+ if (!await this.client.options.command.check(msg)) {
21
+ return
22
+ }
23
+
20
24
  const error = (error: Error) => this.client.client.emit('commandError', error, msg)
21
25
 
22
26
  try {
@@ -1,12 +1,13 @@
1
1
  import _ from 'lodash'
2
2
  import { Registry } from './Registry'
3
- import { Client, Snowflake, User } from 'discord.js'
3
+ import {Client, Message, Snowflake, User} from 'discord.js'
4
4
  import { BuiltinCommandConverters, BuiltinSlashCommandConverters, CommandHandler } from '../builtinModules'
5
5
  import { CoolDownAdapter, DefaultCoolDownAdapter } from '../command'
6
6
  import { REST } from '@discordjs/rest'
7
7
 
8
8
  export interface CommandOptions {
9
9
  prefix: string | ((msg: any) => string | Promise<string | string[]> | string[]) | string[]
10
+ check: (msg: Message) => boolean|Promise<boolean>
10
11
  }
11
12
 
12
13
  export interface SlashCommandOptions {
@@ -64,6 +65,7 @@ export class CommandClient {
64
65
  {
65
66
  command: {
66
67
  prefix: '!',
68
+ check: () => true
67
69
  },
68
70
  owners: 'auto',
69
71
  slashCommands: {