This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandRegistry.cs
72 lines (56 loc) · 2.41 KB
/
CommandRegistry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Discord.Commands;
using Tomat.CommandFramework.HelpSystem;
using Tomat.Logging;
namespace Tomat.CommandFramework
{
public class CommandRegistry : ModuleBase<SocketCommandContext>
{
public static List<HelpCommandData> CommandData { get; set; } = new();
public static List<string> InfoCommands { get; set; } = new();
public static List<string> FunCommands { get; set; } = new();
public static List<string> ConfigCommands { get; set; } = new();
public static void LoadCommandEntries()
{
Logger.Debug("Loading commands from attribute data...");
foreach (Type type in Assembly.GetCallingAssembly().GetTypes().Where(x =>
x.IsSubclassOf(typeof(BaseCommand)) && !x.IsAbstract && x.GetConstructor(Array.Empty<Type>()) != null))
if (Activator.CreateInstance(type) is BaseCommand command)
{
Logger.Debug($"Found command to register: {command.Name}");
string helpEntry = $"`{command.Name}";
if (command.Parameters != null)
helpEntry += $" {command.Parameters}";
RegisterCommand(helpEntry + $"` - {command.CommandSummary}", command);
CommandData.Add(new HelpCommandData(command.HelpData.command,
command.HelpData.description,
command.Parameters,
command.Aliases));
}
Logger.Debug("Finished loading commands from attribute data!");
}
public static void RegisterCommand(string entry, BaseCommand command)
{
switch (command.CType)
{
case CommandType.Info:
InfoCommands.Add(entry);
break;
case CommandType.Fun:
FunCommands.Add(entry);
break;
case CommandType.Hidden:
Logger.Debug($"Skipping registration of hidden command: {command.Name}");
break;
case CommandType.Configuration:
ConfigCommands.Add(entry);
break;
default:
throw new ArgumentOutOfRangeException(nameof(command));
}
}
}
}