public static async Task <GuildUserProperties> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action <GuildUserProperties> func,
                                                                   RequestOptions options)
        {
            var args = new GuildUserProperties();

            func(args);
            var apiArgs = new API.Rest.ModifyGuildMemberParams
            {
                Deaf     = args.Deaf,
                Mute     = args.Mute,
                Nickname = args.Nickname
            };

            if (args.Channel.IsSpecified)
            {
                apiArgs.ChannelId = args.Channel.Value.Id;
            }
            else if (args.ChannelId.IsSpecified)
            {
                apiArgs.ChannelId = args.ChannelId.Value;
            }

            if (args.Roles.IsSpecified)
            {
                apiArgs.RoleIds = args.Roles.Value.Select(x => x.Id).ToArray();
            }
            else if (args.RoleIds.IsSpecified)
            {
                apiArgs.RoleIds = args.RoleIds.Value.ToArray();
            }

            await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);

            return(args);
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task ModifyAsync(Action <GuildUserProperties> func, RequestOptions options = null)
        {
            GuildUserProperties args = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);

            if (args.Deaf.IsSpecified)
            {
                IsDeafened = args.Deaf.Value;
            }
            if (args.Mute.IsSpecified)
            {
                IsMuted = args.Mute.Value;
            }
            if (args.Nickname.IsSpecified)
            {
                Nickname = args.Nickname.Value;
            }
            if (args.Roles.IsSpecified)
            {
                UpdateRoles(args.Roles.Value.Select(x => x.Id).ToArray());
            }
            else if (args.RoleIds.IsSpecified)
            {
                UpdateRoles(args.RoleIds.Value.ToArray());
            }
        }
Beispiel #3
0
        public static async Task <GuildUserProperties> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action <GuildUserProperties> func,
                                                                   RequestOptions options)
        {
            var args = new GuildUserProperties();

            func(args);

            if (args.TimedOutUntil.IsSpecified && args.TimedOutUntil.Value.Value.Offset > (new TimeSpan(28, 0, 0, 0)))
            {
                throw new ArgumentOutOfRangeException(nameof(args.TimedOutUntil), "Offset cannot be more than 28 days from the current date.");
            }

            var apiArgs = new API.Rest.ModifyGuildMemberParams
            {
                Deaf          = args.Deaf,
                Mute          = args.Mute,
                Nickname      = args.Nickname,
                TimedOutUntil = args.TimedOutUntil
            };

            if (args.Channel.IsSpecified)
            {
                apiArgs.ChannelId = args.Channel.Value?.Id;
            }
            else if (args.ChannelId.IsSpecified)
            {
                apiArgs.ChannelId = args.ChannelId.Value;
            }

            if (args.Roles.IsSpecified)
            {
                apiArgs.RoleIds = args.Roles.Value.Select(x => x.Id).ToArray();
            }
            else if (args.RoleIds.IsSpecified)
            {
                apiArgs.RoleIds = args.RoleIds.Value.ToArray();
            }

            /*
             * Ensure that the nick passed in the params of the request is not null.
             * string.Empty ("") is the only way to reset the user nick in the API,
             * a value of null does not. This is a workaround.
             */
            if (apiArgs.Nickname.IsSpecified && apiArgs.Nickname.Value == null)
            {
                apiArgs.Nickname = new Optional <string>(string.Empty);
            }

            await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);

            return(args);
        }
Beispiel #4
0
        public static async Task <GuildUserProperties> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action <GuildUserProperties> func,
                                                                   RequestOptions options)
        {
            GuildUserProperties args = new GuildUserProperties();

            func(args);
            ModifyGuildMemberParams apiArgs = new API.Rest.ModifyGuildMemberParams
            {
                Deaf     = args.Deaf,
                Mute     = args.Mute,
                Nickname = args.Nickname
            };

            if (args.Channel.IsSpecified)
            {
                apiArgs.ChannelId = args.Channel.Value?.Id;
            }
            else if (args.ChannelId.IsSpecified)
            {
                apiArgs.ChannelId = args.ChannelId.Value;
            }

            if (args.Roles.IsSpecified)
            {
                apiArgs.RoleIds = args.Roles.Value.Select(x => x.Id).ToArray();
            }
            else if (args.RoleIds.IsSpecified)
            {
                apiArgs.RoleIds = args.RoleIds.Value.ToArray();
            }

            /*
             * Ensure that the nick passed in the params of the request is not null.
             * string.Empty ("") is the only way to reset the user nick in the API,
             * a value of null does not. This is a workaround.
             */
            if (apiArgs.Nickname.IsSpecified && apiArgs.Nickname.Value == null)
            {
                apiArgs.Nickname = new Optional <string>(string.Empty);
            }

            await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);

            return(args);
        }