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); }
public static async Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options) { var apiArgs = new API.Rest.ModifyGuildMemberParams() { TimedOutUntil = null }; await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); }
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); }
public static async Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options) { if (span.TotalDays > 28) // As its double, an exact value of 28 can be accepted. { throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot be more than 28 days from the current date."); } if (span.Ticks <= 0) { throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot hold no value or have a negative value."); } var apiArgs = new API.Rest.ModifyGuildMemberParams() { TimedOutUntil = DateTimeOffset.UtcNow.Add(span) }; await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false); }
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); }