@@ -5,150 +5,159 @@ import { Client, channelMention, ChannelType } from "discord.js";
5
5
* @type {Object<string, import("../src/ArgumentParser").UsageParser> }
6
6
*/
7
7
const DiscordUsages = {
8
- _mentionable : {
9
- type : "text" ,
10
- async parse ( ctx ) {
11
- return ctx . arg . replace ( / [ < @ # ! & > ] / g, "" ) ;
12
- } ,
13
- } ,
14
-
15
- user : {
16
- type : "_mentionable" ,
17
- async parse ( ctx ) {
18
- let user = ctx . context . client . users
19
- . fetch ( ctx . arg )
20
- . catch ( ( ) => null ) ;
21
-
22
- if ( ! user ) {
23
- return ctx . fail ( `${ ctx . opts . bot ? 'Bot' : 'User' } not found!` ) ;
24
- } ;
25
-
26
- if ( ctx . opts . bot && ! user . bot )
27
- return ctx . fail ( `${ ctx . style . bold (
28
- user . username
29
- ) } isn't a bot!`) ;
30
- else if ( ! opts . bot && user . bot )
31
- return ctx . fail ( `${ ctx . style . bold ( user . username ) } is a bot!` ) ;
32
-
33
- return { parsed : user } ;
34
- } ,
35
- } ,
36
-
37
- member : {
38
- type : "user" ,
39
- async parse ( ctx ) {
40
- const { guild } = ctx . context . message ;
41
- const member = await guild . members
42
- . fetch ( ctx . arg . id )
43
- . catch ( ( ) => null ) ;
44
-
45
- if ( ! member )
46
- return ctx . fail ( `${ ctx . style . bold (
47
- ctx . arg . username
48
- ) } isn't on ${ ctx . style . bold ( guild . name ) } !`) ;
49
-
50
- return { parsed : member } ;
51
- }
52
- } ,
53
-
54
- role : {
55
- type : "_mentionable" ,
56
- async parse ( ctx ) {
57
- const { guild } = ctx . context . message ;
58
- const role = await guild . roles . fetch ( ctx . arg ) . catch ( ( ) => null ) ;
59
-
60
- if ( ! role )
61
- return ctx . fail ( `Role not found!` ) ;
62
-
63
- return { parsed : role } ;
64
- } ,
65
- } ,
66
-
67
- channel : {
68
- type : "_mentionable" ,
69
- async parse ( ctx ) {
70
- const { guild } = ctx . context . message ;
71
- const channel = await guild . channels . fetch ( ctx . arg ) . catch ( ( ) => null ) ;
72
-
73
- if ( ! channel )
74
- return ctx . fail ( `Channel not found!` ) ;
75
-
76
- if ( ctx . opts . channelType !== undefined
77
- && ctx . opts . channelType != channel . type ) {
78
- return ctx . fail ( `${ channelMention ( channel . id ) } isn't ${ ctx . style . bold ( ChannelType [ ctx . opts . channelType ] ) } ` ) ;
79
- }
80
-
81
- return { parsed : channel } ;
82
- } ,
83
- } ,
84
-
85
- textChannel : {
86
- type : "channel" ,
87
- channelType : ChannelType . GuildText ,
88
- } ,
89
-
90
- voiceChannel : {
91
- type : "channel" ,
92
- channelType : ChannelType . GuildVoice ,
93
- } ,
8
+ _mentionable : {
9
+ type : "text" ,
10
+ async parse ( ctx ) {
11
+ return ctx . arg . replace ( / [ < @ # ! & > ] / g, "" ) ;
12
+ } ,
13
+ } ,
14
+
15
+ user : {
16
+ type : "_mentionable" ,
17
+ async parse ( ctx ) {
18
+ let user = ctx . context . client . users
19
+ . fetch ( ctx . arg )
20
+ . catch ( ( ) => null ) ;
21
+
22
+ if ( ! user ) {
23
+ return ctx . fail ( `${ ctx . opts . bot ? "Bot" : "User" } not found!` ) ;
24
+ }
25
+
26
+ if ( ctx . opts . bot && ! user . bot )
27
+ return ctx . fail (
28
+ `${ ctx . style . bold ( user . username ) } isn't a bot!` ,
29
+ ) ;
30
+ else if ( ! opts . bot && user . bot )
31
+ return ctx . fail ( `${ ctx . style . bold ( user . username ) } is a bot!` ) ;
32
+
33
+ return { parsed : user } ;
34
+ } ,
35
+ } ,
36
+
37
+ member : {
38
+ type : "user" ,
39
+ async parse ( ctx ) {
40
+ const { guild } = ctx . context . message ;
41
+ const member = await guild . members
42
+ . fetch ( ctx . arg . id )
43
+ . catch ( ( ) => null ) ;
44
+
45
+ if ( ! member )
46
+ return ctx . fail (
47
+ `${ ctx . style . bold (
48
+ ctx . arg . username ,
49
+ ) } isn't on ${ ctx . style . bold ( guild . name ) } !`,
50
+ ) ;
51
+
52
+ return { parsed : member } ;
53
+ } ,
54
+ } ,
55
+
56
+ role : {
57
+ type : "_mentionable" ,
58
+ async parse ( ctx ) {
59
+ const { guild } = ctx . context . message ;
60
+ const role = await guild . roles . fetch ( ctx . arg ) . catch ( ( ) => null ) ;
61
+
62
+ if ( ! role ) return ctx . fail ( `Role not found!` ) ;
63
+
64
+ return { parsed : role } ;
65
+ } ,
66
+ } ,
67
+
68
+ channel : {
69
+ type : "_mentionable" ,
70
+ async parse ( ctx ) {
71
+ const { guild } = ctx . context . message ;
72
+ const channel = await guild . channels
73
+ . fetch ( ctx . arg )
74
+ . catch ( ( ) => null ) ;
75
+
76
+ if ( ! channel ) return ctx . fail ( `Channel not found!` ) ;
77
+
78
+ if (
79
+ ctx . opts . channelType !== undefined &&
80
+ ctx . opts . channelType != channel . type
81
+ ) {
82
+ return ctx . fail (
83
+ `${ channelMention ( channel . id ) } isn't ${ ctx . style . bold (
84
+ ChannelType [ ctx . opts . channelType ] ,
85
+ ) } `,
86
+ ) ;
87
+ }
88
+
89
+ return { parsed : channel } ;
90
+ } ,
91
+ } ,
92
+
93
+ textChannel : {
94
+ type : "channel" ,
95
+ channelType : ChannelType . GuildText ,
96
+ } ,
97
+
98
+ voiceChannel : {
99
+ type : "channel" ,
100
+ channelType : ChannelType . GuildVoice ,
101
+ } ,
94
102
} ;
95
103
96
-
97
104
const DiscordChecks = {
98
- requirePermissions ( permissions ) { } ,
99
-
100
- async requireGuildOwner ( client , msg , args ) {
101
- return msg . guild . ownerId == msg . author . id ?
102
- {
103
- pass : true ,
104
- } :
105
- {
106
- pass : false ,
107
- message : "You must be the owner of this guild" ,
108
- } ;
109
- } ,
105
+ requirePermissions ( permissions ) { } ,
106
+
107
+ async requireGuildOwner ( client , msg , args ) {
108
+ return msg . guild . ownerId == msg . author . id
109
+ ? {
110
+ pass : true ,
111
+ }
112
+ : {
113
+ pass : false ,
114
+ message : "You must be the owner of this guild" ,
115
+ } ;
116
+ } ,
110
117
} ;
111
118
112
119
/**
113
120
* @typedef {import("../src/CommandHandler").CommandHandlerOptions } DiscordCommandHandlerOptions
114
121
*/
115
122
116
123
class DiscordCommandHandler extends CommandHandler {
117
- /**
118
- *
119
- * @param {Client } client The discord client
120
- * @param {DiscordCommandHandlerOptions } opts - Options for the command handler
121
- */
122
- constructor ( client , opts = { } ) {
123
- super ( Object . assign ( {
124
- argumentParser : {
125
- styling : {
126
- arg : ( x ) => `\`${ x } \`` ,
127
- bold : ( x ) => `**${ x } **` ,
128
- } ,
129
- } ,
130
- } , opts ) ) ;
131
- this . client = client ;
132
- this . client . handler = this ;
133
-
134
- for ( let [ id , usage ] of Object . entries ( DiscordUsages ) )
135
- this . registerUsage ( id , usage ) ;
136
- }
137
-
138
- buildArguments ( { args, ctx } ) {
139
- return [ ctx . client , ctx . message , args ] ;
140
- }
141
-
142
- // handles discord.js messages
143
- handleMessage ( msg ) {
144
- this . run ( msg . content , {
145
- message : msg ,
146
- client : this . client ,
147
- } ) ;
148
- }
124
+ /**
125
+ *
126
+ * @param {Client } client The discord client
127
+ * @param {DiscordCommandHandlerOptions } opts - Options for the command handler
128
+ */
129
+ constructor ( client , opts = { } ) {
130
+ super (
131
+ Object . assign (
132
+ {
133
+ argumentParser : {
134
+ styling : {
135
+ arg : ( x ) => `\`${ x } \`` ,
136
+ bold : ( x ) => `**${ x } **` ,
137
+ } ,
138
+ } ,
139
+ } ,
140
+ opts ,
141
+ ) ,
142
+ ) ;
143
+ this . client = client ;
144
+ this . client . handler = this ;
145
+
146
+ for ( let [ id , usage ] of Object . entries ( DiscordUsages ) )
147
+ this . registerUsage ( id , usage ) ;
148
+ }
149
+
150
+ buildArguments ( { args, ctx } ) {
151
+ return [ ctx . client , ctx . message , args ] ;
152
+ }
153
+
154
+ // handles discord.js messages
155
+ handleMessage ( msg ) {
156
+ this . run ( msg . content , {
157
+ message : msg ,
158
+ client : this . client ,
159
+ } ) ;
160
+ }
149
161
}
150
162
151
- export {
152
- DiscordCommandHandler ,
153
- DiscordUsages ,
154
- } ;
163
+ export { DiscordCommandHandler , DiscordUsages } ;
0 commit comments