Beispiel #1
0
        public static EmbedBuilder GetHelpListEmbed(IDMCommandContext context)
        {
            string contextType = "";

            if (GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
            {
                contextType = "Guild";
            }
            else
            {
                contextType = "PM";
            }

            string embedTitle = "List of all Commands";
            string embedDesc  = "This list only shows commands where all preconditions have been met!";

            List <EmbedFieldBuilder> helpFields = new List <EmbedFieldBuilder>();

            foreach (CommandCollection collection in CommandCollection.AllCollections)
            {
                bool collectionAllowed = true;
                if (context.IsGuildContext)
                {
                    collectionAllowed = guildContext.ChannelMeta.allowedCommandCollections.Count == 0 || guildContext.ChannelMeta.allowedCommandCollections.Contains(collection.Name);
                }
                int availableCommands = collection.ViewableCommands(context, guildContext);
                if (availableCommands > 0 && collectionAllowed)
                {
                    helpFields.Add(Macros.EmbedField($"Collection \"{collection.Name}\"", $"{availableCommands} commands.{(string.IsNullOrEmpty(collection.Description) ? string.Empty : $" {collection.Description}.")} Use `{MessageHandler.CommandParser.CommandSyntax("man")}` to see a summary of commands in this command family!", true));
                }
            }
Beispiel #2
0
 public static bool TryParseGuild(IDMCommandContext context, string argument, out SocketGuild guild, bool allowthis = true, bool allowId = true)
 {
     if (allowthis && argument.ToLower() == "this" && GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
     {
         guild = guildContext.Guild;
         return(guild != null);
     }
     else if (allowId && ulong.TryParse(argument, out ulong guildId))
     {
         guild = BotCore.Client.GetGuild(guildId);
         return(guild != null);
     }
     guild = null;
     return(false);
 }
Beispiel #3
0
        public static EmbedBuilder GetCommandCollectionEmbed(IDMCommandContext context, CommandCollection collection)
        {
            string contextType = "";

            if (GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
            {
                contextType = "Guild";
            }
            else
            {
                contextType = "PM";
            }

            string embedTitle = $"Command Collection \"{collection.Name}\"";
            string embedDesc  = "This list only shows commands where all preconditions have been met!";

            List <EmbedFieldBuilder> helpFields = new List <EmbedFieldBuilder>();

            foreach (Command command in collection.Commands)
            {
                if (command.CanView(context, guildContext, context.UserInfo.IsBotAdmin, out _))
                {
                    helpFields.Add(Macros.EmbedField(command.Syntax, command.Summary, true));
                }
            }

            if (helpFields.Count == 0)
            {
                embedDesc = "No command's precondition has been met!";
                return(new EmbedBuilder()
                {
                    Title = embedTitle, Description = embedDesc, Color = BotCore.ErrorColor, Footer = new EmbedFooterBuilder()
                    {
                        Text = "Context: " + contextType
                    }
                });
            }
            else
            {
                return(new EmbedBuilder()
                {
                    Title = embedTitle, Description = embedDesc, Color = BotCore.EmbedColor, Footer = new EmbedFooterBuilder()
                    {
                        Text = "Context: " + contextType
                    }, Fields = helpFields
                });
            }
        }
        public static EmbedBuilder GetHelpListEmbed(IDMCommandContext context)
        {
            string contextType = "";

            if (GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
            {
                contextType = "Guild";
            }
            else
            {
                contextType = "PM";
            }

            string embedTitle = "List of all Commands";
            string embedDesc  = "This list only shows commands where all preconditions have been met!";

            List <EmbedFieldBuilder> helpFields = getCommandAndCollectionEmbedFields(context, guildContext);

            if (helpFields.Count == 0)
            {
                embedDesc = "No command's precondition has been met!";
                return(new EmbedBuilder()
                {
                    Title = embedTitle, Description = embedDesc, Color = BotCore.ErrorColor, Footer = new EmbedFooterBuilder()
                    {
                        Text = "Context: " + contextType
                    }
                });
            }
            else
            {
                return(new EmbedBuilder()
                {
                    Title = embedTitle, Description = embedDesc, Color = BotCore.EmbedColor, Footer = new EmbedFooterBuilder()
                    {
                        Text = "Context: " + contextType
                    }, Fields = helpFields
                });
            }
        }
Beispiel #5
0
 /// <summary>
 /// Attempts to parse a guild text channel without guild command context
 /// </summary>
 /// <param name="context">The commandcontext to parse the channel with</param>
 /// <param name="argument">The argument string to parse the channel from</param>
 /// <param name="result">The sockettextchannel result</param>
 /// <param name="allowMention">Wether mentioning is enabled for parsing role</param>
 /// <param name="allowThis">Wether pointing to current channel is enabled</param>
 /// <param name="allowId">Wether the ulong id is enabled for parsing role</param>
 /// <returns>True, if parsing was successful</returns>
 public static bool TryParseGuildTextChannel(IDMCommandContext context, string argument, out SocketTextChannel result, bool allowMention = true, bool allowThis = true, bool allowId = true)
 {
     result = null;
     if (allowId && ulong.TryParse(argument, out ulong Id))
     {
         result = BotCore.Client.GetChannel(Id) as SocketTextChannel;
         return(result != null);
     }
     if (allowMention && argument.StartsWith("<#") && argument.EndsWith('>') && argument.Length > 3)
     {
         if (ulong.TryParse(argument.Substring(2, argument.Length - 3), out ulong Id2))
         {
             result = BotCore.Client.GetChannel(Id2) as SocketTextChannel;
             return(result != null);
         }
     }
     if (allowThis && argument.Equals("this") && GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
     {
         result = guildContext.GuildChannel;
         return(result != null);
     }
     return(false);
 }