@@ -254,8 +254,7 @@ private static TopLevelMetadata GetCommandNodeMetadata(CommandNode commandNode)
254
254
255
255
IDiscordPermissionSet ? defaultMemberPermissions = null ;
256
256
var memberPermissionsAttribute =
257
- commandNode . GroupType . GetCustomAttribute < DiscordDefaultMemberPermissionsAttribute > ( ) ??
258
- commandNode . CommandMethod . GetCustomAttribute < DiscordDefaultMemberPermissionsAttribute > ( ) ;
257
+ commandNode . FindCustomAttributeOnLocalTree < DiscordDefaultMemberPermissionsAttribute > ( ) ;
259
258
260
259
if ( memberPermissionsAttribute is not null )
261
260
{
@@ -267,38 +266,31 @@ private static TopLevelMetadata GetCommandNodeMetadata(CommandNode commandNode)
267
266
268
267
var directMessagePermission = default ( Optional < bool > ) ;
269
268
var directMessagePermissionAttribute =
270
- commandNode . GroupType . GetCustomAttribute < DiscordDefaultDMPermissionAttribute > ( ) ??
271
- commandNode . CommandMethod . GetCustomAttribute < DiscordDefaultDMPermissionAttribute > ( ) ;
269
+ commandNode . FindCustomAttributeOnLocalTree < DiscordDefaultDMPermissionAttribute > ( ) ;
272
270
273
271
if ( directMessagePermissionAttribute is not null )
274
272
{
275
273
directMessagePermission = directMessagePermissionAttribute . IsExecutableInDMs ;
276
274
}
277
275
278
276
var isNsfw = default ( Optional < bool > ) ;
279
- var nsfwAttribute =
280
- commandNode . GroupType . GetCustomAttribute < DiscordNsfwAttribute > ( ) ??
281
- commandNode . CommandMethod . GetCustomAttribute < DiscordNsfwAttribute > ( ) ;
277
+ var nsfwAttribute = commandNode . FindCustomAttributeOnLocalTree < DiscordNsfwAttribute > ( ) ;
282
278
283
279
if ( nsfwAttribute is not null )
284
280
{
285
281
isNsfw = nsfwAttribute . IsNsfw ;
286
282
}
287
283
288
284
var allowedContextTypes = default ( Optional < IReadOnlyList < InteractionContextType > > ) ;
289
- var contextsAttribute =
290
- commandNode . GroupType . GetCustomAttribute < AllowedContextsAttribute > ( ) ??
291
- commandNode . CommandMethod . GetCustomAttribute < AllowedContextsAttribute > ( ) ;
285
+ var contextsAttribute = commandNode . FindCustomAttributeOnLocalTree < AllowedContextsAttribute > ( ) ;
292
286
293
287
if ( contextsAttribute is not null )
294
288
{
295
289
allowedContextTypes = contextsAttribute . Contexts . AsOptional ( ) ;
296
290
}
297
291
298
292
var allowedIntegrationTypes = default ( Optional < IReadOnlyList < ApplicationIntegrationType > > ) ;
299
- var integrationAttribute =
300
- commandNode . GroupType . GetCustomAttribute < DiscordInstallContextAttribute > ( ) ??
301
- commandNode . CommandMethod . GetCustomAttribute < DiscordInstallContextAttribute > ( ) ;
293
+ var integrationAttribute = commandNode . FindCustomAttributeOnLocalTree < DiscordInstallContextAttribute > ( ) ;
302
294
303
295
if ( integrationAttribute is not null )
304
296
{
@@ -598,7 +590,7 @@ ILocalizationProvider localizationProvider
598
590
599
591
if ( treeDepth > 1 )
600
592
{
601
- if ( command . CommandMethod . GetCustomAttribute < DiscordDefaultDMPermissionAttribute > ( ) is not null )
593
+ if ( command . Attributes . OfType < DiscordDefaultDMPermissionAttribute > ( ) . FirstOrDefault ( ) is not null )
602
594
{
603
595
throw new InvalidNodeException
604
596
(
@@ -607,7 +599,7 @@ ILocalizationProvider localizationProvider
607
599
) ;
608
600
}
609
601
610
- if ( command . CommandMethod . GetCustomAttribute < DiscordDefaultMemberPermissionsAttribute > ( ) is not null )
602
+ if ( command . Attributes . OfType < DiscordDefaultMemberPermissionsAttribute > ( ) . FirstOrDefault ( ) is not null )
611
603
{
612
604
throw new InvalidNodeException
613
605
(
@@ -616,7 +608,7 @@ ILocalizationProvider localizationProvider
616
608
) ;
617
609
}
618
610
619
- if ( command . CommandMethod . GetCustomAttribute < DiscordNsfwAttribute > ( ) is not null )
611
+ if ( command . Attributes . OfType < DiscordNsfwAttribute > ( ) . FirstOrDefault ( ) is not null )
620
612
{
621
613
throw new InvalidNodeException
622
614
(
@@ -638,9 +630,9 @@ ILocalizationProvider localizationProvider
638
630
) ;
639
631
}
640
632
641
- var parameters = command . CommandMethod . GetParameters ( ) ;
633
+ var parameters = command . Shape . Parameters ;
642
634
var expectedParameter = commandType . AsParameterName ( ) ;
643
- if ( parameters . Length != 1 || parameters [ 0 ] . Name != expectedParameter )
635
+ if ( parameters . Count != 1 || parameters [ 0 ] . HintName != expectedParameter )
644
636
{
645
637
throw new InvalidNodeException
646
638
(
@@ -718,7 +710,7 @@ ILocalizationProvider localizationProvider
718
710
var actualParameterType = parameter . GetActualParameterType ( ) ;
719
711
var ( enableAutocomplete , choices ) = GetParameterChoices
720
712
(
721
- parameter . Parameter ,
713
+ parameter ,
722
714
actualParameterType ,
723
715
localizationProvider
724
716
) ;
@@ -757,7 +749,7 @@ ILocalizationProvider localizationProvider
757
749
}
758
750
759
751
// Collection parameters
760
- var rangeAttribute = parameter . Parameter . GetCustomAttribute < RangeAttribute > ( ) ;
752
+ var rangeAttribute = parameter . Attributes . OfType < RangeAttribute > ( ) . SingleOrDefault ( ) ;
761
753
var ( minElements , maxElements ) = ( rangeAttribute ? . GetMin ( ) ?? 1 , rangeAttribute ? . GetMax ( ) ) ;
762
754
763
755
for ( ulong i = 0 ; i < ( maxElements ?? minElements ) ; i ++ )
@@ -801,7 +793,7 @@ ILocalizationProvider localizationProvider
801
793
private static ( Optional < bool > EnableAutocomplete , Optional < IReadOnlyList < IApplicationCommandOptionChoice > > Choices )
802
794
GetParameterChoices
803
795
(
804
- ParameterInfo parameter ,
796
+ IParameterShape parameter ,
805
797
Type actualParameterType ,
806
798
ILocalizationProvider localizationProvider
807
799
)
@@ -824,7 +816,7 @@ ILocalizationProvider localizationProvider
824
816
}
825
817
else
826
818
{
827
- if ( parameter . GetCustomAttribute < AutocompleteAttribute > ( ) is not null )
819
+ if ( parameter . Attributes . OfType < AutocompleteAttribute > ( ) . SingleOrDefault ( ) is not null )
828
820
{
829
821
enableAutocomplete = true ;
830
822
}
@@ -840,7 +832,7 @@ private static Optional<IReadOnlyList<ChannelType>> CreateChannelTypesOption
840
832
ApplicationCommandOptionType parameterType
841
833
)
842
834
{
843
- var channelTypesAttribute = parameter . Parameter . GetCustomAttribute < ChannelTypesAttribute > ( ) ;
835
+ var channelTypesAttribute = parameter . Attributes . OfType < ChannelTypesAttribute > ( ) . SingleOrDefault ( ) ;
844
836
if ( channelTypesAttribute is not null && parameterType is not ApplicationCommandOptionType . Channel )
845
837
{
846
838
throw new InvalidCommandParameterException
@@ -1063,8 +1055,8 @@ private static (MinValueAttribute? MinValue, MaxValueAttribute? MaxValue) GetNum
1063
1055
ApplicationCommandOptionType discordType
1064
1056
)
1065
1057
{
1066
- var minValue = parameter . Parameter . GetCustomAttribute < MinValueAttribute > ( ) ;
1067
- var maxValue = parameter . Parameter . GetCustomAttribute < MaxValueAttribute > ( ) ;
1058
+ var minValue = parameter . Attributes . OfType < MinValueAttribute > ( ) . SingleOrDefault ( ) ;
1059
+ var maxValue = parameter . Attributes . OfType < MaxValueAttribute > ( ) . SingleOrDefault ( ) ;
1068
1060
1069
1061
if ( discordType is not ( Number or Integer ) && ( minValue is not null || maxValue is not null ) )
1070
1062
{
@@ -1096,8 +1088,8 @@ private static (MinLengthAttribute? MinLength, MaxLengthAttribute? MaxLength) Ge
1096
1088
ApplicationCommandOptionType discordType
1097
1089
)
1098
1090
{
1099
- var minLength = parameter . Parameter . GetCustomAttribute < MinLengthAttribute > ( ) ;
1100
- var maxLength = parameter . Parameter . GetCustomAttribute < MaxLengthAttribute > ( ) ;
1091
+ var minLength = parameter . Attributes . OfType < MinLengthAttribute > ( ) . SingleOrDefault ( ) ;
1092
+ var maxLength = parameter . Attributes . OfType < MaxLengthAttribute > ( ) . SingleOrDefault ( ) ;
1101
1093
1102
1094
var isNonStringWithLengthConstraint = discordType is not ApplicationCommandOptionType . String
1103
1095
&& ( minLength is not null || maxLength is not null ) ;
0 commit comments