Create wrapper modify objects
this was a big one
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,24 @@ 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,
|
||||
Name = args.Name,
|
||||
OwnerId = args.OwnerId,
|
||||
RegionId = args.RegionId,
|
||||
Username = args.Username,
|
||||
VerificationLevel = args.VerificationLevel
|
||||
};
|
||||
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
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,17 +48,24 @@ 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
|
||||
{
|
||||
ChannelId = args.ChannelId,
|
||||
Enabled = args.Enabled
|
||||
};
|
||||
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, Hoist = x.Hoist, Name = x.Name, Permissions = x.Permissions, Position = x.Position });
|
||||
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
|
||||
@@ -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,
|
||||
Hoist = args.Hoist,
|
||||
Name = args.Name,
|
||||
Permissions = args.Permissions,
|
||||
Position = args.Position
|
||||
};
|
||||
return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.User;
|
||||
using ImageModel = Discord.API.Image;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
@@ -12,14 +13,27 @@ 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
|
||||
};
|
||||
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.ChannelId,
|
||||
Deaf = args.Deaf,
|
||||
Mute = args.Mute,
|
||||
Nickname = args.Nickname,
|
||||
RoleIds = args.RoleIds
|
||||
};
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user