@pikokr/command.ts 3.0.7 → 3.0.8

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.
@@ -1,5 +1,5 @@
1
1
  import { BuiltInModule } from './BuiltInModule';
2
- import { Client, GuildMember, Message, User } from 'discord.js';
2
+ import { Client, GuildMember, Message, User, Role } from 'discord.js';
3
3
  import { CommandClient } from '../structures';
4
4
  export declare class BuiltinCommandConverters extends BuiltInModule {
5
5
  private cts;
@@ -11,4 +11,6 @@ export declare class BuiltinCommandConverters extends BuiltInModule {
11
11
  user(msg: Message, value: string): User | null;
12
12
  member(msg: Message, value: string): GuildMember | undefined;
13
13
  number(msg: Message, value: string): number | undefined;
14
+ getRoleIDByMention(mention: string): `${bigint}` | undefined;
15
+ role(msg: Message, value: string): Role | undefined;
14
16
  }
@@ -55,6 +55,25 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
55
55
  const n = Number(value);
56
56
  return isNaN(n) ? undefined : n;
57
57
  }
58
+ getRoleIDByMention(mention) {
59
+ if (!mention)
60
+ return;
61
+ if (mention.startsWith('<@') && mention.endsWith('>')) {
62
+ mention = mention.slice(2, -1);
63
+ if (mention.startsWith('&')) {
64
+ mention = mention.slice(1);
65
+ }
66
+ return mention;
67
+ }
68
+ }
69
+ role(msg, value) {
70
+ var _a;
71
+ const id = this.getRoleIDByMention(value);
72
+ if (!id)
73
+ return;
74
+ const role = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.roles.cache.get(id);
75
+ return role || undefined;
76
+ }
58
77
  }
59
78
  __decorate([
60
79
  command_1.argumentConverter(discord_js_1.Message, false),
@@ -86,4 +105,10 @@ __decorate([
86
105
  __metadata("design:paramtypes", [discord_js_1.Message, String]),
87
106
  __metadata("design:returntype", void 0)
88
107
  ], BuiltinCommandConverters.prototype, "number", null);
108
+ __decorate([
109
+ command_1.argumentConverter(discord_js_1.Role),
110
+ __metadata("design:type", Function),
111
+ __metadata("design:paramtypes", [discord_js_1.Message, String]),
112
+ __metadata("design:returntype", Object)
113
+ ], BuiltinCommandConverters.prototype, "role", null);
89
114
  exports.BuiltinCommandConverters = BuiltinCommandConverters;
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.7",
4
+ "version": "3.0.8",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import { BuiltInModule } from './BuiltInModule'
2
2
  import { argumentConverter } from '../command'
3
- import { Client, GuildMember, Message, User } from 'discord.js'
3
+ import { Client, GuildMember, Message, User, Role } from 'discord.js'
4
4
  import { CommandClient } from '../structures'
5
5
 
6
6
  export class BuiltinCommandConverters extends BuiltInModule {
@@ -53,4 +53,24 @@ export class BuiltinCommandConverters extends BuiltInModule {
53
53
  const n = Number(value)
54
54
  return isNaN(n) ? undefined : n
55
55
  }
56
+
57
+ getRoleIDByMention(mention: string): `${bigint}` | undefined {
58
+ if (!mention) return
59
+ if (mention.startsWith('<@') && mention.endsWith('>')) {
60
+ mention = mention.slice(2, -1)
61
+ if (mention.startsWith('&')) {
62
+ mention = mention.slice(1)
63
+ }
64
+ return mention as `${bigint}`
65
+ }
66
+ }
67
+
68
+ @argumentConverter(Role)
69
+ role(msg: Message, value: string): Role | undefined{
70
+ const id = this.getRoleIDByMention(value)
71
+ if (!id) return
72
+ const role = msg.guild?.roles.cache.get(id)
73
+ return role || undefined
74
+ }
75
+
56
76
  }