Ejemplo n.º 1
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider map)
        {
            var service = map.GetService <RemindMeService>();

            if (service != null)
            {
                //if (CheckAllowCommands(service, context))
                //{
                try
                {
                    if (SqliteDbHandler.GetAdminRoles(context.Guild).Any(x => ((SocketGuildUser)context.User).Roles.Select(y => y.Id).Contains(x)))
                    {
                        return(Task.FromResult(PreconditionResult.FromSuccess()));
                    }
                    else if (new RequireOwnerAttribute().CheckPermissionsAsync(context, command, map).GetAwaiter().GetResult().IsSuccess || new RequireUserPermissionAttribute(GuildPermission.Administrator).CheckPermissionsAsync(context, command, map).GetAwaiter().GetResult().IsSuccess)
                    {
                        return(Task.FromResult(PreconditionResult.FromSuccess()));
                    }
                    return(Task.FromResult(PreconditionResult.FromError("This command can only be used by user with admin role, server administrator or bot owner.")));
                }
                catch (SqliteException e)
                {
                    context.Message.AddReactionAsync(new Emoji("❌"));
                    return(Task.FromResult(PreconditionResult.FromError(e.Message)));
                }
                //}
                //return Task.FromResult(PreconditionResult.FromError("Managing music via commands is disabled in this guild."));
            }

            return(Task.FromResult(PreconditionResult.FromError("No RemindMeService found.")));
        }
Ejemplo n.º 2
0
        internal List <SocketRole> GetAdminRoles(IGuild guild)
        {
            List <SocketRole> roles = new List <SocketRole>();

            foreach (ulong roleId in SqliteDbHandler.GetAdminRoles(guild))
            {
                roles.Add(guild.Roles.Where(x => x.Id == roleId).FirstOrDefault() as SocketRole);
            }
            return(roles);
        }