1- using System ;
1+ using Amino . Interactions . Attributes ;
2+ using Amino . Interactions . Objects ;
3+ using ReflectionsTest ;
4+ using System ;
25using System . Collections . Generic ;
36using System . Linq ;
47using System . Reflection ;
@@ -16,10 +19,10 @@ public partial class InteractionsClient
1619
1720 public enum LogLevels
1821 {
19- None ,
20- Debug ,
21- Warning ,
22- Error
22+ None = 0 ,
23+ Debug = 1 ,
24+ Warning = 2 ,
25+ Error = 3
2326 }
2427
2528 private Amino . Client AminoClient ;
@@ -36,24 +39,79 @@ public InteractionsClient(Amino.Client client)
3639 this . InteractionQueue = new Queue < Objects . Interaction > ( ) ;
3740 this . InteractionModules = new Dictionary < string , Objects . InteractionModule > ( ) ;
3841 _ = Task . Run ( async ( ) => { HandleInteractionQueue ( ) ; } ) ;
42+
3943 }
4044
4145
4246 public Task RegisterModule < T > ( ) where T : InteractionBase
4347 {
44-
48+ var moduleType = typeof ( T ) ;
49+ var methods = moduleType . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
50+ . Where ( m => m . GetCustomAttribute < Command > ( ) != null ) ;
51+
52+ foreach ( var method in methods )
53+ {
54+ var commandAttribute = method . GetCustomAttribute < Command > ( ) ;
55+ var enabledInDmsAttribute = method . GetCustomAttribute < EnabledInDms > ( ) ;
56+ var permissionGroup = method . GetCustomAttribute < PermissionGroup > ( ) ;
57+ var parameters = new FunctionAnalyzer ( ) . GetParameters ( method ) ;
58+
59+ InteractionModule module = new InteractionModule ( ) ;
60+ module . ModuleCommandName = commandAttribute . CommandName ;
61+ if ( commandAttribute . CommunityId != null ) { module . ModuleCommandCommunity = Convert . ToInt32 ( commandAttribute . CommunityId ) ; }
62+ if ( commandAttribute . CommandDescription != null ) { module . ModuleCommandDescription = commandAttribute . CommandDescription ; }
63+ if ( enabledInDmsAttribute != null ) { module . ModuleCommandEnabledInDms = enabledInDmsAttribute . IsEnabledInDms ; }
64+ if ( permissionGroup != null ) { module . ModulePermissionGroup = permissionGroup . RequiredPermission ; }
65+ foreach ( var parameter in parameters )
66+ {
67+ module . ModuleCommandParameters . Add ( ( parameter . Name , parameter . IsOptional ) ) ;
68+ }
69+
70+ this . InteractionModules . Add ( commandAttribute . CommandName , module ) ;
71+ }
72+ return Task . CompletedTask ;
4573 }
4674
75+
4776 public Task RegisterModules ( Assembly entrypoint )
4877 {
49-
78+ var moduleTypes = entrypoint . GetTypes ( ) . Where ( t => typeof ( InteractionBase ) . IsAssignableFrom ( t ) && ! t . IsAbstract ) ;
79+
80+ foreach ( var moduleType in moduleTypes )
81+ {
82+ var methods = moduleType . GetMethods ( BindingFlags . Public | BindingFlags . Instance )
83+ . Where ( m => m . GetCustomAttribute < Command > ( ) != null ) ;
84+
85+ foreach ( var method in methods )
86+ {
87+ var commandAttribute = method . GetCustomAttribute < Command > ( ) ;
88+ var enabledInDmsAttribute = method . GetCustomAttribute < EnabledInDms > ( ) ;
89+ var permissionGroup = method . GetCustomAttribute < PermissionGroup > ( ) ;
90+ var parameters = new FunctionAnalyzer ( ) . GetParameters ( method ) ;
91+
92+ InteractionModule module = new InteractionModule ( ) ;
93+ module . ModuleCommandName = commandAttribute . CommandName ;
94+ if ( commandAttribute . CommunityId != null ) { module . ModuleCommandCommunity = Convert . ToInt32 ( commandAttribute . CommunityId ) ; }
95+ if ( commandAttribute . CommandDescription != null ) { module . ModuleCommandDescription = commandAttribute . CommandDescription ; }
96+ if ( enabledInDmsAttribute != null ) { module . ModuleCommandEnabledInDms = enabledInDmsAttribute . IsEnabledInDms ; }
97+ if ( permissionGroup != null ) { module . ModulePermissionGroup = permissionGroup . RequiredPermission ; }
98+ foreach ( var parameter in parameters )
99+ {
100+ module . ModuleCommandParameters . Add ( ( parameter . Name , parameter . IsOptional ) ) ;
101+ }
102+
103+ this . InteractionModules . Add ( commandAttribute . CommandName , module ) ;
104+ }
105+ }
106+ return Task . CompletedTask ;
50107 }
51108
52109 public bool HandleInteraction ( Objects . Interaction interaction )
53110 {
54-
111+ return true ;
55112 }
56113
114+
57115 private async Task HandleInteractionQueue ( )
58116 {
59117 while ( true )
0 commit comments