Пример #1
0
        public static async Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken,
                                                   Action <AddGuildUserProperties> func, RequestOptions options)
        {
            var args = new AddGuildUserProperties();

            func?.Invoke(args);

            if (args.Roles.IsSpecified)
            {
                var ids = args.Roles.Value.Select(r => r.Id);

                if (args.RoleIds.IsSpecified)
                {
                    args.RoleIds.Value.Concat(ids);
                }
                else
                {
                    args.RoleIds = Optional.Create(ids);
                }
            }
            var apiArgs = new AddGuildMemberParams
            {
                AccessToken = accessToken,
                Nickname    = args.Nickname,
                IsDeafened  = args.Deaf,
                IsMuted     = args.Mute,
                RoleIds     = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create <ulong[]>()
            };

            await client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options);
        }
Пример #2
0
        //Users
        public static async Task <RestGuildUser> AddGuildUserAsync(IGuild guild, BaseDiscordClient client, ulong userId, string accessToken,
                                                                   Action <AddGuildUserProperties> func, RequestOptions options)
        {
            AddGuildUserProperties args = new AddGuildUserProperties();

            func?.Invoke(args);

            if (args.Roles.IsSpecified)
            {
                IEnumerable <ulong> ids = args.Roles.Value.Select(r => r.Id);

                if (args.RoleIds.IsSpecified)
                {
                    args.RoleIds.Value.Concat(ids);
                }
                else
                {
                    args.RoleIds = Optional.Create(ids);
                }
            }
            AddGuildMemberParams apiArgs = new AddGuildMemberParams
            {
                AccessToken = accessToken,
                Nickname    = args.Nickname,
                IsDeafened  = args.Deaf,
                IsMuted     = args.Mute,
                RoleIds     = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create <ulong[]>()
            };

            GuildMemberJson model = await client.ApiClient.AddGuildMemberAsync(guild.Id, userId, apiArgs, options);

            return(model is null ? null : RestGuildUser.Create(client, guild, model));
        }
Пример #3
0
        public async Task <IActionResult> AddGuildMemberAsync(Snowflake guildId, Snowflake userId, [FromBody] AddGuildMemberParams args)
        {
            args.Validate();

            return(Ok(new GuildMember
            {
                User = new User
                {
                    Id = userId
                },
                Deaf = args.Deaf,
                Mute = args.Mute,
                Nickname = args.Nickname,
                Roles = args.Roles
            }));
        }