13
13
using DisCatSharp . ApplicationCommands . EventArgs ;
14
14
using DisCatSharp . ApplicationCommands . Exceptions ;
15
15
using DisCatSharp . ApplicationCommands . Workers ;
16
- using DisCatSharp . Attributes ;
17
16
using DisCatSharp . Common ;
18
17
using DisCatSharp . Common . Utilities ;
19
18
using DisCatSharp . Entities ;
20
19
using DisCatSharp . Enums ;
20
+ using DisCatSharp . Enums . Core ;
21
21
using DisCatSharp . EventArgs ;
22
22
using DisCatSharp . Exceptions ;
23
23
@@ -661,39 +661,37 @@ private async Task RegisterCommands(List<ApplicationCommandsModuleConfiguration>
661
661
if ( Configuration . GenerateTranslationFilesOnly )
662
662
{
663
663
var cgwsgs = new List < CommandGroupWithSubGroups > ( ) ;
664
- var cgs2 = new List < CommandGroup > ( ) ;
665
664
foreach ( var cmd in slashGroupsTuple . applicationCommands )
666
665
if ( cmd . Type is ApplicationCommandType . ChatInput )
667
666
{
668
667
var cgs = new List < CommandGroup > ( ) ;
668
+ var cs2 = new List < Command > ( ) ;
669
669
if ( cmd . Options is not null )
670
+ {
670
671
foreach ( var scg in cmd . Options . Where ( x => x . Type is ApplicationCommandOptionType . SubCommandGroup ) )
671
672
{
672
673
var cs = new List < Command > ( ) ;
673
674
if ( scg . Options is not null )
674
675
foreach ( var sc in scg . Options )
675
676
if ( sc . Options is null || sc . Options . Count is 0 )
676
- cs . Add ( new ( sc . Name , sc . Description , null , null ) ) ;
677
+ cs . Add ( new ( sc . Name , sc . Description , null , null , sc . RawNameLocalizations , sc . RawDescriptionLocalizations ) ) ;
677
678
else
678
- cs . Add ( new ( sc . Name , sc . Description , [ .. sc . Options ] , null ) ) ;
679
- cgs . Add ( new ( scg . Name , scg . Description , cs , null ) ) ;
679
+ cs . Add ( new ( sc . Name , sc . Description , [ .. sc . Options ] , null , sc . RawNameLocalizations , sc . RawDescriptionLocalizations ) ) ;
680
+ cgs . Add ( new ( scg . Name , scg . Description , cs , null , scg . RawNameLocalizations , scg . RawDescriptionLocalizations ) ) ;
680
681
}
681
682
682
- cgwsgs . Add ( new ( cmd . Name , cmd . Description , cgs , cmd . Type ) ) ;
683
+ foreach ( var sc2 in cmd . Options . Where ( x => x . Type is ApplicationCommandOptionType . SubCommand ) )
684
+ if ( sc2 . Options == null || sc2 . Options . Count == 0 )
685
+ cs2 . Add ( new ( sc2 . Name , sc2 . Description , null , null , sc2 . RawNameLocalizations , sc2 . RawDescriptionLocalizations ) ) ;
686
+ else
687
+ cs2 . Add ( new ( sc2 . Name , sc2 . Description , [ .. sc2 . Options ] , null , sc2 . RawNameLocalizations , sc2 . RawDescriptionLocalizations ) ) ;
688
+ }
683
689
684
- var cs2 = new List < Command > ( ) ;
685
- foreach ( var sc2 in cmd . Options . Where ( x => x . Type is ApplicationCommandOptionType . SubCommand ) )
686
- if ( sc2 . Options == null || sc2 . Options . Count == 0 )
687
- cs2 . Add ( new ( sc2 . Name , sc2 . Description , null , null ) ) ;
688
- else
689
- cs2 . Add ( new ( sc2 . Name , sc2 . Description , [ .. sc2 . Options ] , null ) ) ;
690
- cgs2 . Add ( new ( cmd . Name , cmd . Description , cs2 , cmd . Type ) ) ;
690
+ cgwsgs . Add ( new ( cmd . Name , cmd . Description , cgs , cs2 , cmd . Type , cmd . RawNameLocalizations , cmd . RawDescriptionLocalizations ) ) ;
691
691
}
692
692
693
693
if ( cgwsgs . Count is not 0 )
694
694
groupTranslation . AddRange ( cgwsgs . Select ( cgwsg => JsonConvert . DeserializeObject < GroupTranslator > ( JsonConvert . SerializeObject ( cgwsg ) ) ! ) ) ;
695
- if ( cgs2 . Count is not 0 )
696
- groupTranslation . AddRange ( cgs2 . Select ( cg2 => JsonConvert . DeserializeObject < GroupTranslator > ( JsonConvert . SerializeObject ( cg2 ) ) ! ) ) ;
697
695
}
698
696
}
699
697
@@ -733,12 +731,20 @@ private async Task RegisterCommands(List<ApplicationCommandsModuleConfiguration>
733
731
var cs = new List < Command > ( ) ;
734
732
foreach ( var cmd in slashCommands . applicationCommands . Where ( cmd => cmd . Type is ApplicationCommandType . ChatInput && ( cmd . Options is null || ! cmd . Options . Any ( x => x . Type is ApplicationCommandOptionType . SubCommand or ApplicationCommandOptionType . SubCommandGroup ) ) ) )
735
733
if ( cmd . Options == null || cmd . Options . Count == 0 )
736
- cs . Add ( new ( cmd . Name , cmd . Description , null , ApplicationCommandType . ChatInput ) ) ;
734
+ cs . Add ( new ( cmd . Name , cmd . Description , null , ApplicationCommandType . ChatInput , cmd . RawNameLocalizations , cmd . RawDescriptionLocalizations ) ) ;
737
735
else
738
- cs . Add ( new ( cmd . Name , cmd . Description , [ .. cmd . Options ] , ApplicationCommandType . ChatInput ) ) ;
736
+ cs . Add ( new ( cmd . Name , cmd . Description , [ .. cmd . Options ] , ApplicationCommandType . ChatInput , cmd . RawNameLocalizations , cmd . RawDescriptionLocalizations ) ) ;
739
737
740
738
if ( cs . Count is not 0 )
741
- translation . AddRange ( cs . Select ( c => JsonConvert . DeserializeObject < CommandTranslator > ( JsonConvert . SerializeObject ( c ) ) ! ) ) ;
739
+ //translation.AddRange(cs.Select(c => JsonConvert.DeserializeObject<CommandTranslator>(JsonConvert.SerializeObject(c))!));
740
+ {
741
+ foreach ( var c in cs )
742
+ {
743
+ var json = JsonConvert . SerializeObject ( c ) ;
744
+ var obj = JsonConvert . DeserializeObject < CommandTranslator > ( json ) ;
745
+ translation . Add ( obj ! ) ;
746
+ }
747
+ }
742
748
}
743
749
}
744
750
@@ -804,7 +810,7 @@ private async Task RegisterCommands(List<ApplicationCommandsModuleConfiguration>
804
810
{
805
811
updateList = updateList . DistinctBy ( x => x . Name ) . ToList ( ) ;
806
812
if ( Configuration . GenerateTranslationFilesOnly )
807
- await this . CheckRegistrationStartup ( translation , groupTranslation ) ;
813
+ await this . CheckRegistrationStartup ( translation , groupTranslation , guildId ) ;
808
814
else
809
815
try
810
816
{
@@ -911,7 +917,7 @@ private async Task RegisterCommands(List<ApplicationCommandsModuleConfiguration>
911
917
RegisteredCommands = GlobalCommandsInternal
912
918
} ) . ConfigureAwait ( false ) ;
913
919
914
- await this . CheckRegistrationStartup ( translation , groupTranslation ) ;
920
+ await this . CheckRegistrationStartup ( translation , groupTranslation , guildId ) ;
915
921
}
916
922
catch ( NullReferenceException ex )
917
923
{
@@ -965,15 +971,16 @@ private async Task RegisterCommands(List<ApplicationCommandsModuleConfiguration>
965
971
/// </summary>
966
972
/// <param name="translation">The optional translations.</param>
967
973
/// <param name="groupTranslation">The optional group translations.</param>
968
- private async Task CheckRegistrationStartup ( List < CommandTranslator > ? translation = null , List < GroupTranslator > ? groupTranslation = null )
974
+ /// <param name="guildId">The optional guild id.</param>
975
+ private async Task CheckRegistrationStartup ( List < CommandTranslator > ? translation = null , List < GroupTranslator > ? groupTranslation = null , ulong ? guildId = null )
969
976
{
970
977
if ( Configuration . GenerateTranslationFilesOnly )
971
978
{
972
979
try
973
980
{
974
981
if ( translation is not null && translation . Count is not 0 )
975
982
{
976
- var fileName = $ "translation_generator_export-shard{ this . Client . ShardId } -SINGLE.json";
983
+ var fileName = $ "translation_generator_export-shard{ this . Client . ShardId } -SINGLE- { ( guildId . HasValue ? guildId . Value : "global" ) } .json";
977
984
var fs = File . Create ( fileName ) ;
978
985
var ms = new MemoryStream ( ) ;
979
986
var writer = new StreamWriter ( ms ) ;
@@ -991,7 +998,7 @@ private async Task CheckRegistrationStartup(List<CommandTranslator>? translation
991
998
992
999
if ( groupTranslation is not null && groupTranslation . Count is not 0 )
993
1000
{
994
- var fileName = $ "translation_generator_export-shard{ this . Client . ShardId } -GROUP.json";
1001
+ var fileName = $ "translation_generator_export-shard{ this . Client . ShardId } -GROUP- { ( guildId . HasValue ? guildId . Value : "global" ) } .json";
995
1002
var fs = File . Create ( fileName ) ;
996
1003
var ms = new MemoryStream ( ) ;
997
1004
var writer = new StreamWriter ( ms ) ;
@@ -1030,6 +1037,8 @@ private async Task CheckStartupFinishAsync(ApplicationCommandsExtension sender,
1030
1037
GuildsWithoutScope = s_missingScopeGuildIdsGlobal
1031
1038
} ) . ConfigureAwait ( false ) ;
1032
1039
FinishFired = true ;
1040
+ if ( Configuration . GenerateTranslationFilesOnly )
1041
+ Environment . Exit ( 0 ) ;
1033
1042
}
1034
1043
1035
1044
args . Handled = false ;
@@ -1081,7 +1090,11 @@ private Task InteractionHandler(DiscordClient client, InteractionCreateEventArgs
1081
1090
GuildLocale = e . Interaction . GuildLocale ,
1082
1091
AppPermissions = e . Interaction . AppPermissions ,
1083
1092
Entitlements = e . Interaction . Entitlements ,
1084
- EntitlementSkuIds = e . Interaction . EntitlementSkuIds
1093
+ EntitlementSkuIds = e . Interaction . EntitlementSkuIds ,
1094
+ UserId = e . Interaction . User . Id ,
1095
+ GuildId = e . Interaction . GuildId ,
1096
+ MemberId = e . Interaction . GuildId is not null ? e . Interaction . User . Id : null ,
1097
+ ChannelId = e . Interaction . ChannelId
1085
1098
} ;
1086
1099
1087
1100
try
@@ -1340,7 +1353,12 @@ private Task ContextMenuHandler(DiscordClient client, ContextMenuInteractionCrea
1340
1353
_ = Task . Run ( async ( ) =>
1341
1354
{
1342
1355
//Creates the context
1343
- var context = new ContextMenuContext
1356
+ var context = new ContextMenuContext ( e . Type switch
1357
+ {
1358
+ ApplicationCommandType . User => DisCatSharpCommandType . UserCommand ,
1359
+ ApplicationCommandType . Message => DisCatSharpCommandType . MessageCommand ,
1360
+ _ => throw new ArgumentOutOfRangeException ( nameof ( e . Type ) , "Unknown context menu type" )
1361
+ } )
1344
1362
{
1345
1363
Interaction = e . Interaction ,
1346
1364
Channel = e . Interaction . Channel ,
@@ -1359,7 +1377,11 @@ private Task ContextMenuHandler(DiscordClient client, ContextMenuInteractionCrea
1359
1377
GuildLocale = e . Interaction . GuildLocale ,
1360
1378
AppPermissions = e . Interaction . AppPermissions ,
1361
1379
Entitlements = e . Interaction . Entitlements ,
1362
- EntitlementSkuIds = e . Interaction . EntitlementSkuIds
1380
+ EntitlementSkuIds = e . Interaction . EntitlementSkuIds ,
1381
+ UserId = e . Interaction . User . Id ,
1382
+ GuildId = e . Interaction . GuildId ,
1383
+ MemberId = e . Interaction . GuildId is not null ? e . Interaction . User . Id : null ,
1384
+ ChannelId = e . Interaction . ChannelId
1363
1385
} ;
1364
1386
1365
1387
try
0 commit comments