-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpModule.cs
More file actions
94 lines (81 loc) · 2.26 KB
/
HelpModule.cs
File metadata and controls
94 lines (81 loc) · 2.26 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//Thanks LunarLite ;)
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Discord.Rest;
using System.Linq;
using System.Threading.Tasks;
namespace Unimate.Modules.Public
{
public class HelpModule : ModuleBase
{
private CommandService _service;
public HelpModule(CommandService service) // Create a constructor for the commandservice dependency
{
_service = service;
}
[Command("help")]
[Remarks("General help command, returns this list.")]
public async Task HelpAsync()
{
string prefix = "<>";
var user = Context.User as SocketGuildUser;
var DM = await user.CreateDMChannelAsync();
var builder = new EmbedBuilder()
{
Color = new Color(114, 137, 218),
Description = "These are the commands you can use:"
};
foreach (var module in _service.Modules)
{
string description = null;
foreach (var cmd in module.Commands)
{
var result = await cmd.CheckPreconditionsAsync(Context);
if (result.IsSuccess)
description += $"{prefix}{cmd.Aliases.First()}: " + cmd.Remarks + "\n";
}
if (!string.IsNullOrWhiteSpace(description))
{
builder.AddField(x =>
{
x.Name = module.Name;
x.Value = description;
x.IsInline = false;
});
}
}
await DM.SendMessageAsync("", false, builder.Build());
}
[Command("help")]
[Remarks("Type -help and a command to see more about it, example: -help hi")]
public async Task HelpAsync(string command)
{
var result = _service.Search(Context, command);
var user = Context.User as SocketGuildUser;
var DM = await user.CreateDMChannelAsync();
if (!result.IsSuccess)
{
await DM.SendMessageAsync($"Sorry, I couldn't find a command like **{command}**.");
return;
}
var builder = new EmbedBuilder()
{
Color = new Color(114, 137, 218),
Description = $"Here are some commands like **{command}**"
};
foreach (var match in result.Commands)
{
var cmd = match.Command;
builder.AddField(x =>
{
x.Name = string.Join(", ", cmd.Aliases);
x.Value = $"Parameters: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\n" +
$"Remarks: {cmd.Remarks}";
x.IsInline = false;
});
}
await DM.SendMessageAsync("", false, builder.Build());
}
}
}