Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Created April 15, 2019 18:23
Show Gist options
  • Save nathan130200/a953f5ff2200f55e1f8f35f838199ad1 to your computer and use it in GitHub Desktop.
Save nathan130200/a953f5ff2200f55e1f8f35f838199ad1 to your computer and use it in GitHub Desktop.
Formatador de ajuda do bot Warface Radiation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Converters;
using DSharpPlus.CommandsNext.Entities;
using DSharpPlus.Entities;
using WarfaceRadiation.Attributes;
using WarfaceRadiation.Properties;
namespace WarfaceRadiation.Core
{
public class WarfaceRadiationHelpFormatter : BaseHelpFormatter
{
private Command Command;
private DiscordEmbedBuilder Embed;
private StringBuilder Description;
public WarfaceRadiationHelpFormatter(CommandContext ctx) : base(ctx)
{
this.Description = new StringBuilder();
this.Embed = new DiscordEmbedBuilder()
.WithTimestamp(DateTime.Now)
.WithColor(DiscordColor.Gold)
.WithThumbnailUrl("https://i.imgur.com/pGZrf9D.png")
.WithAuthor(Localization.commands_help_tip, iconUrl: ctx.Client.CurrentUser.AvatarUrl)
.WithFooter(string.Format(Localization.commands_core_requested_by, ctx.User.Username, ctx.User.Discriminator), ctx.User.GetAvatarUrl(ImageFormat.Jpeg));
}
public override BaseHelpFormatter WithCommand(Command command)
{
this.Command = command;
this.Description.AppendLine(Localization.commands_help_description)
.AppendLine(command.Description ?? Localization.commands_core_unavaiable)
.AppendLine();
if(this.Command.Aliases?.Any() == true)
{
this.Description.AppendLine(Localization.commands_help_aliases)
.AppendLine(string.Join(", ", this.Command.Aliases.Select(Formatter.InlineCode)))
.AppendLine();
}
if(this.Command.ExecutionChecks.Any(xa => xa is UnderConstructionAttribute))
{
this.Description.AppendLine(Localization.commands_help_under_construction)
.AppendLine("Esse comando __**talvez**__ não esteja pronto ainda!")
.AppendLine();
}
if(this.Command.ExecutionChecks.Any(xa => xa is DisabledAttribute))
{
var attr = (DisabledAttribute)this.Command.ExecutionChecks.FirstOrDefault(xa => xa is DisabledAttribute);
var term = attr
.Temporary ? "__temporariamente__" : "";
this.Description.AppendLine(":no_entry_sign: **Desativado**")
.AppendLine($"Esse comando foi desativado {term} pelo desenvolvedor.")
.AppendLine();
}
if(this.Command.CustomAttributes.Any(xa => xa is ExamplesAttribute))
{
var attr = (ExamplesAttribute) this.Command.CustomAttributes.First(xa => xa is ExamplesAttribute);
this.Description.AppendLine(Localization.commands_help_examples);
foreach (var exm in attr.Examples)
{
this.Description.AppendLine(exm.Replace("%PREFIX%", this.Context.Prefix)
.Replace("%QNAME%", this.Command.QualifiedName ?? this.Command.Name)
.Replace("%CNAME%", this.Command.Name)
);
}
this.Description.AppendLine();
}
if(this.Command.Overloads?.Any() == true)
{
this.Description.AppendLine(Localization.commands_help_overloads);
foreach (var overload in this.Command.Overloads)
{
var str = $"{this.Context.Prefix}{this.Command.QualifiedName ?? this.Command.Name} ";
foreach(var argv in overload.Arguments)
{
str += argv.IsOptional ? "[" : "<";
str += (argv.IsCatchAll ? "..." : "") + argv.Name;
str += argv.IsOptional ? "]" : ">";
str += "\n";
}
this.Description.AppendLine(Formatter.InlineCode(str));
}
this.Description.AppendLine();
}
return this;
}
public override BaseHelpFormatter WithSubcommands(IEnumerable<Command> subcommands)
{
var str = string.Join(", ", subcommands.Select(x => Formatter.InlineCode(x.Name)));
if (this.Command == null)
this.Description.AppendLine(Localization.commands_help_cmds);
else
this.Description.AppendLine(Localization.commands_help_subcmds);
this.Description.AppendLine(str);
return this;
}
public override CommandHelpMessage Build()
{
if (this.Command != null)
this.Embed.ThumbnailUrl = "https://i.imgur.com/Ncqe0tH.png";
return new CommandHelpMessage(this.Context.User.Mention, this.Embed
.WithDescription(this.Description.ToString()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment