@@ -22,6 +22,7 @@ import {
22
22
import type { Client , WorkerClient } from '../client' ;
23
23
import { type MessageStructure , type OptionResolverStructure , Transformers } from '../client/transformers' ;
24
24
import type { MakeRequired } from '../common' ;
25
+ import { INTEGER_OPTION_VALUE_LIMIT } from '../common/it/constants' ;
25
26
import { ComponentContext , ModalContext } from '../components' ;
26
27
import {
27
28
AutocompleteInteraction ,
@@ -635,7 +636,7 @@ export class HandleCommand {
635
636
async argsOptionsParser (
636
637
command : Command | SubCommand ,
637
638
message : GatewayMessageCreateDispatchData ,
638
- args : Partial < Record < string , string > > ,
639
+ args : Record < string , string > ,
639
640
resolved : MakeRequired < ContextOptionsResolved > ,
640
641
) {
641
642
const options : APIApplicationCommandInteractionDataOption [ ] = [ ] ;
@@ -649,6 +650,7 @@ export class HandleCommand {
649
650
type : ApplicationCommandOptionType ;
650
651
} ) [ ] ) {
651
652
try {
653
+ if ( ! args [ i . name ] && i . type !== ApplicationCommandOptionType . Attachment ) continue ;
652
654
let value : string | boolean | number | undefined ;
653
655
switch ( i . type ) {
654
656
case ApplicationCommandOptionType . Attachment :
@@ -658,9 +660,7 @@ export class HandleCommand {
658
660
}
659
661
break ;
660
662
case ApplicationCommandOptionType . Boolean :
661
- if ( args [ i . name ] ) {
662
- value = [ 'yes' , 'y' , 'true' , 'treu' ] . includes ( args [ i . name ] ! . toLowerCase ( ) ) ;
663
- }
663
+ value = [ 'yes' , 'y' , 'true' , 'treu' ] . includes ( args [ i . name ] . toLowerCase ( ) ) ;
664
664
break ;
665
665
case ApplicationCommandOptionType . Channel :
666
666
{
@@ -670,24 +670,22 @@ export class HandleCommand {
670
670
if ( ! rawQuery ) continue ;
671
671
const channel =
672
672
( await this . client . cache . channels ?. raw ( rawQuery ) ) ?? ( await this . fetchChannel ( i , rawQuery ) ) ;
673
- if ( channel ) {
674
- if ( 'channel_types' in i ) {
675
- if ( ! ( i as SeyfertChannelOption ) . channel_types ! . includes ( channel . type ) ) {
676
- if ( i . required )
677
- errors . push ( {
678
- name : i . name ,
679
- error : `The entered channel type is not one of ${ ( i as SeyfertChannelOption )
680
- . channel_types ! . map ( t => ChannelType [ t ] )
681
- . join ( ', ' ) } `,
682
- fullError : [ 'CHANNEL_TYPES' , ( i as SeyfertChannelOption ) . channel_types ! ] ,
683
- } ) ;
684
- break ;
685
- }
673
+ if ( ! channel ) break ;
674
+ if ( 'channel_types' in i ) {
675
+ if ( ! ( i as SeyfertChannelOption ) . channel_types ! . includes ( channel . type ) ) {
676
+ errors . push ( {
677
+ name : i . name ,
678
+ error : `The entered channel type is not one of ${ ( i as SeyfertChannelOption )
679
+ . channel_types ! . map ( t => ChannelType [ t ] )
680
+ . join ( ', ' ) } `,
681
+ fullError : [ 'CHANNEL_TYPES' , ( i as SeyfertChannelOption ) . channel_types ! ] ,
682
+ } ) ;
683
+ break ;
686
684
}
687
- value = channel . id ;
688
- //discord funny memoentnt!!!!!!!!
689
- resolved . channels [ channel . id ] = channel as APIInteractionDataResolvedChannel ;
690
685
}
686
+ value = channel . id ;
687
+ //discord funny memoentnt!!!!!!!!
688
+ resolved . channels [ channel . id ] = channel as APIInteractionDataResolvedChannel ;
691
689
}
692
690
break ;
693
691
case ApplicationCommandOptionType . Mentionable :
@@ -754,115 +752,111 @@ export class HandleCommand {
754
752
break ;
755
753
case ApplicationCommandOptionType . String :
756
754
{
757
- value = args [ i . name ] ;
758
755
const option = i as SeyfertStringOption ;
759
- if ( ! value ) break ;
760
- if ( option . min_length ) {
761
- if ( value . length < option . min_length ) {
762
- value = undefined ;
763
- if ( i . required )
764
- errors . push ( {
765
- name : i . name ,
766
- error : `The entered string has less than ${ option . min_length } characters. The minimum required is ${ option . min_length } characters. `,
767
- fullError : [ 'STRING_MIN_LENGTH ' , option . min_length ] ,
768
- } ) ;
756
+ if ( option . choices ?. length ) {
757
+ const choice = option . choices . find ( x => x . name === args [ i . name ] ) ;
758
+ if ( ! choice ) {
759
+ errors . push ( {
760
+ name : i . name ,
761
+ error : `The entered choice is invalid. Please choose one of the following options: ${ option . choices
762
+ . map ( x => x . name )
763
+ . join ( ', ' ) } `,
764
+ fullError : [ 'STRING_INVALID_CHOICE ' , option . choices ] ,
765
+ } ) ;
769
766
break ;
770
767
}
768
+ value = choice . value ;
769
+ break ;
771
770
}
772
- if ( option . max_length ) {
773
- if ( value . length > option . max_length ) {
774
- value = undefined ;
775
- if ( i . required )
776
- errors . push ( {
777
- name : i . name ,
778
- error : `The entered string has more than ${ option . max_length } characters. The maximum required is ${ option . max_length } characters.` ,
779
- fullError : [ 'STRING_MAX_LENGTH' , option . max_length ] ,
780
- } ) ;
771
+ if ( option . min_length !== undefined ) {
772
+ if ( args [ i . name ] . length < option . min_length ) {
773
+ errors . push ( {
774
+ name : i . name ,
775
+ error : `The entered string has less than ${ option . min_length } characters. The minimum required is ${ option . min_length } characters` ,
776
+ fullError : [ 'STRING_MIN_LENGTH' , option . min_length ] ,
777
+ } ) ;
781
778
break ;
782
779
}
783
780
}
784
- if ( option . choices ?. length ) {
785
- const choice = option . choices . find ( x => x . name === value ) ;
786
- if ( ! choice ) {
787
- value = undefined ;
788
- if ( i . required )
789
- errors . push ( {
790
- name : i . name ,
791
- error : `The entered choice is invalid. Please choose one of the following options: ${ option . choices
792
- . map ( x => x . name )
793
- . join ( ', ' ) } .`,
794
- fullError : [ 'STRING_INVALID_CHOICE' , option . choices ] ,
795
- } ) ;
781
+ if ( option . max_length !== undefined ) {
782
+ if ( args [ i . name ] . length > option . max_length ) {
783
+ errors . push ( {
784
+ name : i . name ,
785
+ error : `The entered string has more than ${ option . max_length } characters. The maximum required is ${ option . max_length } characters` ,
786
+ fullError : [ 'STRING_MAX_LENGTH' , option . max_length ] ,
787
+ } ) ;
796
788
break ;
797
789
}
798
- value = choice . value ;
799
790
}
791
+ value = args [ i . name ] ;
800
792
}
801
793
break ;
802
794
case ApplicationCommandOptionType . Number :
803
795
case ApplicationCommandOptionType . Integer :
804
796
{
805
797
const option = i as SeyfertNumberOption | SeyfertIntegerOption ;
806
- if ( ! option . choices ?. length ) {
807
- value = Number ( args [ i . name ] ) ;
808
- if ( args [ i . name ] === undefined ) {
809
- value = undefined ;
798
+ if ( option . choices ?. length ) {
799
+ const choice = option . choices . find ( x => x . name === args [ i . name ] ) ;
800
+ if ( ! choice ) {
801
+ errors . push ( {
802
+ name : i . name ,
803
+ error : `The entered choice is invalid. Please choose one of the following options: ${ option . choices
804
+ . map ( x => x . name )
805
+ . join ( ', ' ) } `,
806
+ fullError : [ 'NUMBER_INVALID_CHOICE' , option . choices ] ,
807
+ } ) ;
810
808
break ;
811
809
}
812
- if ( Number . isNaN ( value ) ) {
810
+ value = choice . value ;
811
+ break ;
812
+ }
813
+ value =
814
+ i . type === ApplicationCommandOptionType . Integer
815
+ ? Math . trunc ( Number ( args [ i . name ] ) )
816
+ : Number ( args [ i . name ] ) ;
817
+ if ( Number . isNaN ( value ) ) {
818
+ value = undefined ;
819
+ errors . push ( {
820
+ name : i . name ,
821
+ error : 'The entered choice is an invalid number' ,
822
+ fullError : [ 'NUMBER_NAN' , args [ i . name ] ] ,
823
+ } ) ;
824
+ break ;
825
+ }
826
+ if ( value <= - INTEGER_OPTION_VALUE_LIMIT || value >= INTEGER_OPTION_VALUE_LIMIT ) {
827
+ value = undefined ;
828
+ errors . push ( {
829
+ name : i . name ,
830
+ error : 'The entered number must be between -2^53 and 2^53' ,
831
+ fullError : [ 'NUMBER_OUT_OF_BOUNDS' , INTEGER_OPTION_VALUE_LIMIT ] ,
832
+ } ) ;
833
+ break ;
834
+ }
835
+ if ( option . min_value !== undefined ) {
836
+ if ( value < option . min_value ) {
813
837
value = undefined ;
814
- if ( i . required )
815
- errors . push ( {
816
- name : i . name ,
817
- error : 'The entered choice is an invalid number.' ,
818
- fullError : [ 'NUMBER_NAN' , args [ i . name ] ] ,
819
- } ) ;
838
+ errors . push ( {
839
+ name : i . name ,
840
+ error : `The entered number is less than ${ option . min_value } . The minimum allowed is ${ option . min_value } ` ,
841
+ fullError : [ 'NUMBER_MIN_VALUE' , option . min_value ] ,
842
+ } ) ;
820
843
break ;
821
844
}
822
- if ( option . min_value ) {
823
- if ( value < option . min_value ) {
824
- value = undefined ;
825
- if ( i . required )
826
- errors . push ( {
827
- name : i . name ,
828
- error : `The entered number is less than ${ option . min_value } . The minimum allowed is ${ option . min_value } ` ,
829
- fullError : [ 'NUMBER_MIN_VALUE' , option . min_value ] ,
830
- } ) ;
831
- break ;
832
- }
833
- }
834
- if ( option . max_value ) {
835
- if ( value > option . max_value ) {
836
- value = undefined ;
837
- if ( i . required )
838
- errors . push ( {
839
- name : i . name ,
840
- error : `The entered number is greater than ${ option . max_value } . The maximum allowed is ${ option . max_value } ` ,
841
- fullError : [ 'NUMBER_MAX_VALUE' , option . max_value ] ,
842
- } ) ;
843
- break ;
844
- }
845
- }
846
- break ;
847
845
}
848
- const choice = option . choices . find ( x => x . name === args [ i . name ] ) ;
849
- if ( ! choice ) {
850
- value = undefined ;
851
- if ( i . required )
846
+ if ( option . max_value !== undefined ) {
847
+ if ( value > option . max_value ) {
848
+ value = undefined ;
852
849
errors . push ( {
853
850
name : i . name ,
854
- error : `The entered choice is invalid. Please choose one of the following options: ${ option . choices
855
- . map ( x => x . name )
856
- . join ( ', ' ) } .`,
857
- fullError : [ 'NUMBER_INVALID_CHOICE' , option . choices ] ,
851
+ error : `The entered number is greater than ${ option . max_value } . The maximum allowed is ${ option . max_value } ` ,
852
+ fullError : [ 'NUMBER_MAX_VALUE' , option . max_value ] ,
858
853
} ) ;
854
+ break ;
855
+ }
859
856
break ;
860
857
}
861
- value = choice . value ;
862
858
}
863
859
break ;
864
- default :
865
- break ;
866
860
}
867
861
if ( value !== undefined ) {
868
862
options . push ( {
0 commit comments