Exemplo n.º 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));
                }
            }
Exemplo n.º 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);
 }
Exemplo n.º 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
                });
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 6
0
        internal static Task Client_MessageReceived(SocketMessage arg)
        {
            SocketUserMessage userMessage = arg as SocketUserMessage;

            if (userMessage != null)
            {
                SocketTextChannel guildChannel = userMessage.Channel as SocketTextChannel;
                bool isGuildContext            = guildChannel != null;

                bool ispotentialCommand;
                if (isGuildContext)
                {
                    ispotentialCommand = CommandParser.IsPotentialCommand(userMessage.Content, guildChannel.Guild.Id);
                }
                else
                {
                    ispotentialCommand = CommandParser.IsPotentialCommand(userMessage.Content);
                }

                if (ispotentialCommand)
                {
                    IMessageContext      messageContext;
                    IGuildMessageContext guildMessageContext;
                    IDMCommandContext    commandContext;
                    IGuildCommandContext guildCommandContext;
                    if (isGuildContext)
                    {
                        guildMessageContext = new GuildMessageContext(userMessage, guildChannel.Guild);
                        messageContext      = guildMessageContext;
                    }
                    else
                    {
                        messageContext      = new MessageContext(userMessage);
                        guildMessageContext = null;
                    }

                    if (messageContext.IsDefined)
                    {
                        if (isGuildContext)
                        {
                            guildCommandContext = new GuildCommandContext(guildMessageContext, CommandParser.ParseCommand(guildMessageContext));
                            commandContext      = guildCommandContext;
                        }
                        else
                        {
                            commandContext      = new DMCommandContext(messageContext, CommandParser.ParseCommand(messageContext));
                            guildCommandContext = null;
                        }

                        if (isGuildContext)
                        {
                            if (!guildCommandContext.ChannelMeta.CheckChannelMeta(guildCommandContext.UserInfo, guildCommandContext.InterpretedCommand, out string error))
                            {
                                return(messageContext.Channel.SendEmbedAsync(error, true));
                            }
                        }

                        switch (commandContext.CommandSearch)
                        {
                        case CommandSearchResult.NoMatch:
                            return(messageContext.Message.AddReactionAsync(UnicodeEmoteService.Question));

                        case CommandSearchResult.PerfectMatch:
                            return(commandContext.InterpretedCommand.HandleCommandAsync(commandContext, guildCommandContext));

                        case CommandSearchResult.TooFewArguments:
                            return(messageContext.Channel.SendEmbedAsync($"The command `{commandContext.InterpretedCommand}` requires a minimum of {commandContext.InterpretedCommand.MinimumArgumentCount} arguments!", true));

                        case CommandSearchResult.TooManyArguments:
                            return(commandContext.InterpretedCommand.HandleCommandAsync(commandContext, guildCommandContext));
                        }
                    }
                }
            }
            return(Task.CompletedTask);
        }