Exemple #1
0
        public async Task AddRole(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("Given role doesn't exist.");

                return;
            }

            if (_assignRolesService.IsRoleOnList(role.Value.Id))
            {
                await ctx.RespondAsync("The role is already 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.AddRoleToDatabase(ctx.Guild.Id, role.Value.Id);
                await ctx.RespondAsync("Role added to the role list.");
            }
            else
            {
                await ctx.RespondAsync("You can not add this role because it is equal or higher than your highest role.");
            }
        }
Exemple #2
0
        public async Task AddRole(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} Rola `{message}` jest już 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.AddRoleToDatabase(ctx.Guild.Id, role.Value.Id);
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Rola `{message}` dodana do listy ról.");
            }
            else
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Nie możesz dodać roli `{message}`, gdyż jest równa lub wyższa twojej najwyższej roli.");
            }
        }