-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLibrary.cs
More file actions
40 lines (32 loc) · 1.22 KB
/
CommandLibrary.cs
File metadata and controls
40 lines (32 loc) · 1.22 KB
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
using Microsoft.Extensions.Logging;
namespace Botifex
{
/// <summary>
/// Holds all the commands that have been registered for Botifex to set up with its messengers
/// </summary>
public class CommandLibrary : ICommandLibrary
{
private ILogger<CommandLibrary> log;
private Dictionary<string, SlashCommand> commands = new Dictionary<string, SlashCommand>();
public List<SlashCommand> Commands { get => commands.Values.ToList(); } // return all the command objects
public CommandLibrary(ILogger<CommandLibrary> log)
{
this.log = log;
}
public void RegisterCommand(SlashCommand command)
{
command.Name = command.Name.ToLower();
if (commands.ContainsKey(command.Name))
log.LogWarning($"Attempted to add {command.Name} more than once, ignored");
else // good to go
{
#if DEBUG
log.LogDebug("Command registered: " + command.Name);
#endif
commands.Add(command.Name, command);
}
}
public SlashCommand GetCommand(string name) => commands[name];
public bool HasCommand(string name) => commands.ContainsKey(name);
}
}