File tree Expand file tree Collapse file tree 5 files changed +54
-56
lines changed
Expand file tree Collapse file tree 5 files changed +54
-56
lines changed Original file line number Diff line number Diff line change 1- import { SparkCommand , CommandType , SlashCommandPlugin } from '@spark.ts/handler' ;
2-
3- function mapUsers ( ids : string [ ] ) {
4- const userMention = ( s : string ) => `<@!${ s } >` ;
5- return ids . map ( ( id ) => `\` - \` ${ userMention ( id ) } ` ) . join ( '\n' ) ;
6- }
7-
8- function testPlugin ( ownerIds : string [ ] ) : SlashCommandPlugin {
9- return {
10- description : 'Only allows the owner to run the command.' ,
11- async run ( { interaction, controller } ) {
12- if ( ownerIds . includes ( interaction . user . id ) ) {
13- return controller . next ( ) ;
14- }
15-
16- await interaction . reply ( {
17- content : `Only these people can run this!\n${ mapUsers ( ownerIds ) } ` ,
18- ephemeral : true ,
19- } ) ;
20-
21- return controller . stop ( ) ;
22- } ,
23- } ;
24- }
1+ import { SparkCommand , CommandType } from '@spark.ts/handler' ;
2+ import { ownerOnlySlash } from '../../plugins/ownerOnly' ;
253
264export default new SparkCommand ( {
275 type : CommandType . Slash ,
28- plugins : [ testPlugin ( [ '283312847478325251' ] ) ] ,
6+ plugins : [ ownerOnlySlash ( [ '283312847478325251' ] ) ] ,
297 run ( { interaction } ) {
308 interaction . reply ( 'You are allowed to use this command!' ) ;
319 } ,
Load Diff This file was deleted.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ import { SparkCommand , CommandType } from '@spark.ts/handler' ;
2+ import { ownerOnlyText } from '../../plugins/ownerOnly' ;
3+
4+ export default new SparkCommand ( {
5+ type : CommandType . Text ,
6+ plugins : [ ownerOnlyText ( [ '283312847478325251' ] ) ] ,
7+ run ( { message } ) {
8+ message . reply ( 'You are allowed to use this command!' ) ;
9+ } ,
10+ } ) ;
Original file line number Diff line number Diff line change 1+ import { SlashCommandPlugin , TextCommandPlugin } from '@spark.ts/handler' ;
2+
3+ function mapUsers ( ids : string [ ] ) {
4+ const userMention = ( s : string ) => `<@!${ s } >` ;
5+ return ids . map ( ( id ) => `\` - \` ${ userMention ( id ) } ` ) . join ( '\n' ) ;
6+ }
7+
8+ export function ownerOnlySlash ( ownerIds : string [ ] ) : SlashCommandPlugin {
9+ return {
10+ description : 'Only allows the owner to run the command.' ,
11+ async run ( { interaction, controller } ) {
12+ if ( ownerIds . includes ( interaction . user . id ) ) {
13+ return controller . next ( ) ;
14+ }
15+
16+ await interaction . reply ( {
17+ content : `Only these people can run this!\n${ mapUsers ( ownerIds ) } ` ,
18+ ephemeral : true ,
19+ } ) ;
20+
21+ return controller . stop ( ) ;
22+ } ,
23+ } ;
24+ }
25+
26+ export function ownerOnlyText ( ownerIds : string [ ] ) : TextCommandPlugin {
27+ return {
28+ description : 'Only allows the owner to run the command.' ,
29+ async run ( { message, controller } ) {
30+ if ( ownerIds . includes ( message . author . id ) ) {
31+ return controller . next ( ) ;
32+ }
33+
34+ await message . reply ( {
35+ content : `Only these people can run this!\n${ mapUsers ( ownerIds ) } ` ,
36+ } ) ;
37+
38+ return controller . stop ( ) ;
39+ } ,
40+ } ;
41+ }
You can’t perform that action at this time.
0 commit comments