Skip to content

Instantly share code, notes, and snippets.

@RealSGII2
Created August 1, 2020 21:58
Show Gist options
  • Select an option

  • Save RealSGII2/35a504fb02d5653b63360fd0c2935429 to your computer and use it in GitHub Desktop.

Select an option

Save RealSGII2/35a504fb02d5653b63360fd0c2935429 to your computer and use it in GitHub Desktop.
[Command("dmhelp"), Alias("dmbotinfo", "dmcommands")]
public async Task DMHelp()
{
EmbedBuilder extraHelpEmbed = new EmbedBuilder();
extraHelpEmbed.AddField("Wiki", "[Click Here](https://github.com/Blackcatmaxy/Botcatmaxy/wiki)", true);
extraHelpEmbed.AddField("Submit bugs, enhancements, and contribute", "[Click Here](http://bot.blackcatmaxy.com)", true);
EmbedBuilder embed = new EmbedBuilder
{
Title = "Commands",
Description = "You are viewing all commands you have permission to use."
};
foreach (ModuleInfo module in _service.Modules)
{
string description = "";
foreach (CommandInfo command in module.Commands)
{
PreconditionResult isAllowed = await command.CheckPreconditionsAsync(Context);
if (isAllowed.IsSuccess)
{
description += $"!{command.Aliases[0]}\n";
}
}
if (!string.IsNullOrWhiteSpace(description))
{
embed.AddField(new EmbedFieldBuilder
{
Name = module.Name,
Value = description
}); ;
}
}
await Context.User.SendMessageAsync(embed: extraHelpEmbed.Build());
await Context.User.SendMessageAsync(embed: embed.Build());
}
[Command("dmhelp"), Alias("dmbotinfo", "dmcommands")]
public async Task DMHelp(string commandName)
{
SearchResult res = _service.Search(Context, commandName);
if (!res.IsSuccess)
{
await ReplyAsync($"`!{commandName}` isn't a command.");
return;
}
EmbedBuilder embed = new EmbedBuilder
{
Title = "Commands",
Description = $"Viewing search results you can use for `!{commandName}`."
};
foreach (CommandMatch match in res.Commands)
{
CommandInfo command = match.Command;
PreconditionResult isAllowed = await command.CheckPreconditionsAsync(Context);
if (isAllowed.IsSuccess)
{
string args = "";
foreach (ParameterInfo param in command.Parameters)
{
args += $"[{param.Name}] ";
}
embed.AddField(new EmbedFieldBuilder
{
Name = $"!{command.Aliases[0]} {args}",
Value = command.Summary ?? "*No description.*"
});
}
}
await Context.User.SendMessageAsync(embed: embed.Build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment