Merge branch 'issue/379' into dev
This commit is contained in:
@@ -24,7 +24,12 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new ModifyGuildChannelParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyGuildChannelParams
|
||||
{
|
||||
Name = args.Name,
|
||||
Position = args.Position
|
||||
};
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client,
|
||||
Action<ModifyTextChannelParams> func,
|
||||
@@ -32,7 +37,13 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new ModifyTextChannelParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyTextChannelParams
|
||||
{
|
||||
Name = args.Name,
|
||||
Position = args.Position,
|
||||
Topic = args.Topic
|
||||
};
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
|
||||
Action<ModifyVoiceChannelParams> func,
|
||||
@@ -40,7 +51,14 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new ModifyVoiceChannelParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyVoiceChannelParams
|
||||
{
|
||||
Bitrate = args.Bitrate,
|
||||
Name = args.Name,
|
||||
Position = args.Position,
|
||||
UserLimit = args.UserLimit
|
||||
};
|
||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Invites
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using EmbedModel = Discord.API.GuildEmbed;
|
||||
using Model = Discord.API.Guild;
|
||||
using RoleModel = Discord.API.Role;
|
||||
using ImageModel = Discord.API.Image;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
@@ -21,12 +22,39 @@ namespace Discord.Rest
|
||||
var args = new ModifyGuildParams();
|
||||
func(args);
|
||||
|
||||
if (args.Splash.IsSpecified && guild.SplashId != null)
|
||||
args.Splash = new API.Image(guild.SplashId);
|
||||
if (args.Icon.IsSpecified && guild.IconId != null)
|
||||
args.Icon = new API.Image(guild.IconId);
|
||||
var apiArgs = new API.Rest.ModifyGuildParams
|
||||
{
|
||||
AfkChannelId = args.AfkChannelId,
|
||||
AfkTimeout = args.AfkTimeout,
|
||||
DefaultMessageNotifications = args.DefaultMessageNotifications,
|
||||
Icon = args.Icon.IsSpecified ? ImageModel.Create(args.Icon.Value) : Optional.Create<ImageModel?>(),
|
||||
Name = args.Name,
|
||||
Splash = args.Splash.IsSpecified ? ImageModel.Create(args.Splash.Value) : Optional.Create<ImageModel?>(),
|
||||
Username = args.Username,
|
||||
VerificationLevel = args.VerificationLevel
|
||||
};
|
||||
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
if (args.AfkChannel.IsSpecified)
|
||||
apiArgs.AfkChannelId = args.AfkChannel.Value.Id;
|
||||
else if (args.AfkChannelId.IsSpecified)
|
||||
apiArgs.AfkChannelId = args.AfkChannelId.Value;
|
||||
|
||||
if (args.Owner.IsSpecified)
|
||||
apiArgs.OwnerId = args.Owner.Value.Id;
|
||||
else if (args.OwnerId.IsSpecified)
|
||||
apiArgs.OwnerId = args.OwnerId.Value;
|
||||
|
||||
if (args.Region.IsSpecified)
|
||||
apiArgs.RegionId = args.Region.Value.Id;
|
||||
else if (args.RegionId.IsSpecified)
|
||||
apiArgs.RegionId = args.RegionId.Value;
|
||||
|
||||
if (!apiArgs.Splash.IsSpecified && guild.SplashId != null)
|
||||
apiArgs.Splash = new ImageModel(guild.SplashId);
|
||||
if (!apiArgs.Icon.IsSpecified && guild.IconId != null)
|
||||
apiArgs.Icon = new ImageModel(guild.IconId);
|
||||
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<EmbedModel> ModifyEmbedAsync(IGuild guild, BaseDiscordClient client,
|
||||
Action<ModifyGuildEmbedParams> func, RequestOptions options)
|
||||
@@ -35,44 +63,63 @@ namespace Discord.Rest
|
||||
|
||||
var args = new ModifyGuildEmbedParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyGuildEmbedParams
|
||||
{
|
||||
Enabled = args.Enabled
|
||||
};
|
||||
|
||||
if (args.Channel.IsSpecified)
|
||||
apiArgs.ChannelId = args.Channel.Value?.Id;
|
||||
else if (args.ChannelId.IsSpecified)
|
||||
apiArgs.ChannelId = args.ChannelId.Value;
|
||||
|
||||
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client,
|
||||
IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position));
|
||||
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RoleModel>> ModifyRolesAsync(IGuild guild, BaseDiscordClient client,
|
||||
IEnumerable<ModifyGuildRolesParams> args, RequestOptions options)
|
||||
{
|
||||
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id)
|
||||
{
|
||||
Color = x.Color.IsSpecified ? x.Color.Value.RawValue : Optional.Create<uint>(),
|
||||
Hoist = x.Hoist,
|
||||
Name = x.Name,
|
||||
Permissions = x.Permissions.IsSpecified ? x.Permissions.Value.RawValue : Optional.Create<ulong>(),
|
||||
Position = x.Position
|
||||
});
|
||||
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Bans
|
||||
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
|
||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong userId, int pruneDays, RequestOptions options)
|
||||
{
|
||||
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays };
|
||||
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
}
|
||||
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong userId, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
|
||||
@@ -87,7 +134,7 @@ namespace Discord.Rest
|
||||
return RestGuildChannel.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false);
|
||||
@@ -113,7 +160,7 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
//Integrations
|
||||
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id, options).ConfigureAwait(false);
|
||||
@@ -128,7 +175,7 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
//Invites
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);
|
||||
@@ -147,8 +194,8 @@ namespace Discord.Rest
|
||||
await role.ModifyAsync(x =>
|
||||
{
|
||||
x.Name = name;
|
||||
x.Permissions = (permissions ?? role.Permissions).RawValue;
|
||||
x.Color = (color ?? Color.Default).RawValue;
|
||||
x.Permissions = (permissions ?? role.Permissions);
|
||||
x.Color = (color ?? Color.Default);
|
||||
x.Hoist = isHoisted;
|
||||
}, options).ConfigureAwait(false);
|
||||
|
||||
@@ -164,7 +211,7 @@ namespace Discord.Rest
|
||||
return RestGuildUser.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
|
||||
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false);
|
||||
|
||||
@@ -61,7 +61,13 @@ namespace Discord.Rest
|
||||
|
||||
var args = new ModifyGuildIntegrationParams();
|
||||
func(args);
|
||||
var model = await Discord.ApiClient.ModifyGuildIntegrationAsync(GuildId, Id, args).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyGuildIntegrationParams
|
||||
{
|
||||
EnableEmoticons = args.EnableEmoticons,
|
||||
ExpireBehavior = args.ExpireBehavior,
|
||||
ExpireGracePeriod = args.ExpireGracePeriod
|
||||
};
|
||||
var model = await Discord.ApiClient.ModifyGuildIntegrationAsync(GuildId, Id, apiArgs).ConfigureAwait(false);
|
||||
|
||||
Update(model);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,15 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new ModifyGuildRoleParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyGuildRoleParams
|
||||
{
|
||||
Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create<uint>(),
|
||||
Hoist = args.Hoist,
|
||||
Name = args.Name,
|
||||
Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create<ulong>(),
|
||||
Position = args.Position
|
||||
};
|
||||
return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.GuildMember;
|
||||
|
||||
@@ -30,7 +31,7 @@ namespace Discord.Rest
|
||||
}
|
||||
}
|
||||
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
|
||||
|
||||
|
||||
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
|
||||
|
||||
internal RestGuildUser(BaseDiscordClient discord, IGuild guild, ulong id)
|
||||
@@ -61,21 +62,25 @@ namespace Discord.Rest
|
||||
roles.Add(roleIds[i]);
|
||||
_roleIds = roles.ToImmutable();
|
||||
}
|
||||
|
||||
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options).ConfigureAwait(false);
|
||||
Update(model);
|
||||
}
|
||||
public async Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null)
|
||||
{
|
||||
{
|
||||
var 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.RoleIds.IsSpecified)
|
||||
UpdateRoles(args.RoleIds.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());
|
||||
}
|
||||
public Task KickAsync(RequestOptions options = null)
|
||||
=> UserHelper.KickAsync(this, Discord, options);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.User;
|
||||
using ImageModel = Discord.API.Image;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
@@ -12,14 +14,36 @@ namespace Discord.Rest
|
||||
{
|
||||
var args = new ModifyCurrentUserParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifySelfAsync(args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyCurrentUserParams
|
||||
{
|
||||
Avatar = args.Avatar.IsSpecified ? ImageModel.Create(args.Avatar.Value) : Optional.Create<ImageModel?>(),
|
||||
Username = args.Username
|
||||
};
|
||||
|
||||
if (!apiArgs.Avatar.IsSpecified && user.AvatarId != null)
|
||||
apiArgs.Avatar = new ImageModel(user.AvatarId);
|
||||
|
||||
return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<ModifyGuildMemberParams> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyGuildMemberParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options).ConfigureAwait(false);
|
||||
var apiArgs = new API.Rest.ModifyGuildMemberParams
|
||||
{
|
||||
ChannelId = args.Channel.IsSpecified ? args.Channel.Value.Id : Optional.Create<ulong>(),
|
||||
Deaf = args.Deaf,
|
||||
Mute = args.Mute,
|
||||
Nickname = args.Nickname
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user