Ejemplo n.º 1
0
        public async Task DeleteRole(CommandContext ctx, [RemainingText] string message)
        {
            await ctx.TriggerTypingAsync();

            var serverRoles = ctx.Guild.Roles;
            var role        = serverRoles.Select(p => p).Where(q => q.Value.Name == message).FirstOrDefault();

            if (role.Value == null)
            {
                await ctx.RespondAsync("The given role does not exist.");

                return;
            }

            if (!_assignRolesService.IsRoleOnList(role.Value.Id))
            {
                await ctx.RespondAsync("The role is not on the list.");

                return;
            }

            // User who triggered is owner, we can add role without problem or user who triggered isn't owner, we need to check if role is lower than the highest role he has
            var userTheHighestRolePosition = GetTheHighestRolePosition(ctx.Member.Roles.ToList());

            if (ctx.User == ctx.Guild.Owner || role.Value.Position < userTheHighestRolePosition)
            {
                // Add role to database
                _assignRolesService.RemoveRoleFromDatabase(ctx.Guild.Id, role.Value.Id);
                await ctx.RespondAsync("Role removed from the role list.");
            }
            else
            {
                await ctx.RespondAsync("You can not remove this role because it is equal or higher than your highest role.");
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteRole(CommandContext ctx, [RemainingText] string message)
        {
            await ctx.TriggerTypingAsync();

            var serverRoles = ctx.Guild.Roles;
            var role        = serverRoles.Select(p => p).Where(q => q.Value.Name == message).FirstOrDefault();

            if (role.Value == null)
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Rola `{message}` nie istnieje.");

                return;
            }

            if (!_assignRolesService.IsRoleOnList(role.Value.Id))
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Roli `{message}` nie ma na liście.");

                return;
            }

            // User who triggered is owner, we can add role without problem or user who triggered isn't owner, we need to check if role is lower than the highest role he has
            var userTheHighestRolePosition = GetTheHighestRolePosition(ctx.Member.Roles.ToList());

            if (ctx.User == ctx.Guild.Owner || role.Value.Position < userTheHighestRolePosition)
            {
                // Add role to database
                _assignRolesService.RemoveRoleFromDatabase(ctx.Guild.Id, role.Value.Id);
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Rola `{message}` usunięta z listy ról.");
            }
            else
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Nie możesz usunąć roli `{message}`, gdyż jest równa lub wyższa twojej najwyższej roli.");
            }
        }