Beispiel #1
0
 private static string ParseFailedCheck(CheckBaseAttribute attr)
 {
     return(attr switch
     {
         RequireOwnerAttribute _ => ", only the server owner can use that command.",
         RequirePermissionsAttribute _ => ", you don't have permission to do that.",
         RequireRolesAttribute _ => ", you do not have a required role.",
         RequireUserPermissionsAttribute _ => ", you don't have permission to do that.",
         RequireNsfwAttribute _ => ", this command can only be used in an NSFW channel.",
         RequirePollStartChannelAttribute => ", you cannot start a poll in this channel.",
         _ => ", an unknown Discord API error has occurred, contact the developer and please try again later."
     });
Beispiel #2
0
 private string ParseFailedCheck(CheckBaseAttribute attr)
 {
     return(attr switch
     {
         CooldownAttribute _ => "You cannot do that so often!",
         RequireOwnerAttribute _ => "Only the server owner can use that command!",
         RequirePermissionsAttribute _ => "You don't have permission to do that!",
         RequireRolesAttribute _ => "You do not have a required role!",
         RequireUserPermissionsAttribute _ => "You don't have permission to do that!",
         RequireNsfwAttribute _ => "This command can only be used in an NSFW channel!",
         _ => "Unknown Discord API error occured, please try again later."
     });
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var guildAdminAttr   = new RequireUserPermissionAttribute(GuildPermission.Administrator);
            var guildAdminResult = await guildAdminAttr.CheckPermissionsAsync(context, command, services);

            if (guildAdminResult.IsSuccess)
            {
                return(PreconditionResult.FromSuccess());
            }

            var botOwnerAttr   = new RequireOwnerAttribute();
            var botOwnerResult = await botOwnerAttr.CheckPermissionsAsync(context, command, services);

            if (botOwnerResult.IsSuccess)
            {
                return(PreconditionResult.FromSuccess());
            }

            return(PreconditionResult.FromError(ErrorMessage ?? $"User requires administrator permission or has to be the bot owner."));
        }
Beispiel #4
0
        public async Task Test()
        {
            List <CommandInfo> cmds      = CommandHandler.GetCommands();
            string             msg       = "User Commands:\n";
            string             adminCmds = "Admin Commands:\n";
            string             ownerCmds = "Owner Commands:\n";
            int x = 0;
            int y = 0;

            foreach (CommandInfo cmd in cmds)
            {
                if (cmd.Preconditions.Count > 0)
                {
                    foreach (PreconditionAttribute precondition in cmd.Preconditions)
                    {
                        if (precondition is RequireBotPermissionAttribute)
                        {
                            RequireBotPermissionAttribute attribute = precondition as RequireBotPermissionAttribute;
                            //msg += "*Requires Bot Permission: " + attribute.GuildPermission + "*\n";
                        }
                        else if (precondition is RequireUserPermissionAttribute)
                        {
                            RequireUserPermissionAttribute attribute = precondition as RequireUserPermissionAttribute;
                            //msg += "*Requires User Permission: " + attribute.GuildPermission + "*\n";
                            if (AdminAttribute(attribute))
                            {
                                adminCmds += "**__" + cmd.Name + "__**\n";
                                if (!string.IsNullOrEmpty(cmd.Summary))
                                {
                                    adminCmds += "*" + cmd.Summary + "*\n";
                                }
                                y++;
                            }
                            else
                            {
                                msg += "**__" + cmd.Name + "__**\n";
                                if (!string.IsNullOrEmpty(cmd.Summary))
                                {
                                    msg += "*" + cmd.Summary + "*\n";
                                }
                                x++;
                            }
                        }
                        else if (precondition is RequireOwnerAttribute)
                        {
                            RequireOwnerAttribute attribute = precondition as RequireOwnerAttribute;
                            ownerCmds += "**__" + cmd.Name + "__**\n";
                            if (!string.IsNullOrEmpty(cmd.Summary))
                            {
                                ownerCmds += "*" + cmd.Summary + "*\n";
                            }
                        }
                    }
                }
                else
                {
                    msg += "**__" + cmd.Name + "__**\n";
                    if (!string.IsNullOrEmpty(cmd.Summary))
                    {
                        msg += "*" + cmd.Summary + "*\n";
                    }
                    x++;
                }

                if (y > 10)
                {
                    adminCmds += "|";
                    y          = 0;
                }
                if (x > 10)
                {
                    msg += "|";
                    x    = 0;
                }
            }

            string       prefix = "/";
            ServerConfig config = null;

            if (!Context.IsPrivate)
            {
                config = ServerConfigs.GetConfig(Context.Guild);
            }
            if (config != null)
            {
                prefix = config.Prefix;
            }
            foreach (string s in SplitMessage(msg, '|'))
            {
                if (!string.IsNullOrEmpty(s))
                {
                    await Context.Channel.SendMessageAsync(string.Format(s, prefix));
                }
            }
            foreach (string s in SplitMessage(adminCmds, '|'))
            {
                if (!string.IsNullOrEmpty(s))
                {
                    await Context.Channel.SendMessageAsync(string.Format(s, prefix));
                }
            }
            await Context.Channel.SendMessageAsync(ownerCmds);
        }
Beispiel #5
0
        public async Task Commandlist(params string[] parameters)
        {
            string dm = "​\nList of Commands\n"
                        + "━━━━━━━━━━━━━━━━━━━━━━"
                        + "\n\n";


            Type type = typeof(Tools);


            foreach (var method in type.GetMethods())
            {
                var attrs = System.Attribute.GetCustomAttributes(method);

                foreach (var attrib in attrs)
                {
                    if (attrib is CommandAttribute)
                    {
                        CommandAttribute a = (CommandAttribute)attrib;
                        dm += "!!" + a.Text + "\n";
                    }

                    if (attrib is AliasAttribute)
                    {
                        AliasAttribute a = (AliasAttribute)attrib;
                        dm += "aliases: ";
                        foreach (var alias in a.Aliases)
                        {
                            dm += "!!" + alias + ", ";
                        }
                        dm = dm.Remove(dm.Count() - 2);

                        dm += "\n";
                    }

                    if (attrib is SummaryAttribute)
                    {
                        SummaryAttribute a = (SummaryAttribute)attrib;
                        dm += a.Text + "\n";
                    }

                    if (attrib is RequireOwnerAttribute)
                    {
                        RequireOwnerAttribute a = (RequireOwnerAttribute)attrib;
                        dm += "Permitted users - Bot owner" + "\n";
                    }

                    if (attrib is RequireUserPermissionAttribute)
                    {
                        RequireUserPermissionAttribute a = (RequireUserPermissionAttribute)attrib;
                        dm += "Permitted users - ";
                        if (a.GuildPermission.Value == GuildPermission.Administrator)
                        {
                            dm += "Server Admins";
                        }

                        dm += "\n";
                    }

                    if (attrib is RequireRoleAttribute)
                    {
                        RequireRoleAttribute a = (RequireRoleAttribute)attrib;
                        dm += "Permitted users - " + a.name + "\n";
                    }
                }

                dm += "\n​";
            }
            dm += "\n\n​";
            await DmSplit(dm);
            await CommandStatus("DM Sent.", "Command List");
        }