Exemplo n.º 1
0
        public async Task GiveRole(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 (HasUserRole(ctx.Member, role.Value))
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Posiadasz już rolę `{message}`.");

                return;
            }

            if (_assignRolesService.IsRoleOnList(role.Value.Id))
            {
                if (!CanBotModifyThisRole(role.Value, ctx.Guild.CurrentMember.Roles.ToList()))
                {
                    await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Moje role są za nisko abym mógł nadać rolę `{message}`.");

                    return;
                }

                await ctx.Member.GrantRoleAsync(role.Value, "Rola nadana przez bota przy użyciu systemu nadawania ról. Działanie zostało zainicjowane przez użytkownika.");

                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Rola `{message}` nadana.");
            }
            else
            {
                await PostEmbedHelper.PostEmbed(ctx, "System ról", $"{ctx.User.Mention} Roli `{message}` nie ma na liście.");
            }
        }
Exemplo n.º 2
0
        public async Task GiveRole(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 (HasUserRole(ctx.Member, role.Value))
             * {
             *  await ctx.RespondAsync("You already have this role.");
             *  return;
             * }*/

            if (_assignRolesService.IsRoleOnList(role.Value.Id))
            {
                if (!CanBotModifyThisRole(role.Value, ctx.Guild.CurrentMember.Roles.ToList()))
                {
                    await ctx.RespondAsync("My roles are too low for me to give this role.");

                    return;
                }

                await ctx.Member.GrantRoleAsync(role.Value, "Role has been assigned by bot using assign role system. Action has been triggered by user.");

                await ctx.RespondAsync("Role has been assigned.");
            }
            else
            {
                await ctx.RespondAsync("Role is not on the list.");
            }
        }