Skip to content

Commit 632fe03

Browse files
committed
Finish basics
Finished the basics of the Framework
1 parent 034cb9e commit 632fe03

4 files changed

Lines changed: 86 additions & 17 deletions

File tree

Amino.NET.Interactions/Attributes/PermissionGroup.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
namespace Amino.Interactions.Attributes
88
{
9-
public class PermissionGroup
9+
public class PermissionGroup : Attribute
1010
{
1111
public enum PermissionGroups
1212
{
13-
All,
14-
Chat_Staff,
15-
Staff,
16-
Curator,
17-
Leader,
18-
Agent
13+
All = 0,
14+
Chat_Staff = 1,
15+
Staff = 2,
16+
Curator = 3,
17+
Leader = 4,
18+
Agent = 5
1919
}
2020

2121
public PermissionGroups RequiredPermission { get; set; } = PermissionGroups.All;

Amino.NET.Interactions/InteractionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class InteractionBase
1010
{
1111
public Objects.Interaction Context;
1212

13-
13+
1414
}
1515
}

Amino.NET.Interactions/InteractionsClient.cs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
using Amino.Interactions.Attributes;
2+
using Amino.Interactions.Objects;
3+
using ReflectionsTest;
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
47
using 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)

Amino.NET.Interactions/Objects/InteractionModule.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Amino.Interactions.Attributes;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -8,5 +9,15 @@ namespace Amino.Interactions.Objects
89
{
910
public class InteractionModule
1011
{
12+
13+
public string ModuleCommandName { get; set; }
14+
public string ModuleCommandDescription { get; set; }
15+
public int? ModuleCommandCommunity { get; set; }
16+
17+
public bool ModuleCommandEnabledInDms { get; set; } = true;
18+
public PermissionGroup.PermissionGroups ModulePermissionGroup { get; set; } = PermissionGroup.PermissionGroups.All;
19+
20+
public List<(string, bool)> ModuleCommandParameters { get; set; } = new List<(string, bool)>();
21+
1122
}
1223
}

0 commit comments

Comments
 (0)