Implemented emoji endpoints (#835)
* Implemented emoji endpoints. * Fixed: now using API entities for REST client. * Removed emoji listing endpoint, as per @foxbot's request.
This commit is contained in:
committed by
Christopher F
parent
cf8de42b62
commit
b4bf046ad4
@@ -253,5 +253,46 @@ namespace Discord.Rest
|
||||
model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return model.Pruned;
|
||||
}
|
||||
|
||||
//Emotes
|
||||
public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
|
||||
{
|
||||
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options);
|
||||
return emote.ToEntity();
|
||||
}
|
||||
public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles,
|
||||
RequestOptions options)
|
||||
{
|
||||
var apiargs = new CreateGuildEmoteParams
|
||||
{
|
||||
Name = name,
|
||||
Image = image.ToModel()
|
||||
};
|
||||
if (roles.IsSpecified)
|
||||
apiargs.RoleIds = roles.Value?.Select(xr => xr.Id)?.ToArray();
|
||||
|
||||
var emote = await client.ApiClient.CreateGuildEmoteAsync(guild.Id, apiargs, options);
|
||||
return emote.ToEntity();
|
||||
}
|
||||
public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
if (func == null) throw new ArgumentNullException(nameof(func));
|
||||
|
||||
var props = new EmoteProperties();
|
||||
func(props);
|
||||
|
||||
var apiargs = new ModifyGuildEmoteParams
|
||||
{
|
||||
Name = props.Name
|
||||
};
|
||||
if (props.Roles.IsSpecified)
|
||||
apiargs.RoleIds = props.Roles.Value?.Select(xr => xr.Id)?.ToArray();
|
||||
|
||||
var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options);
|
||||
return emote.ToEntity();
|
||||
}
|
||||
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
|
||||
=> client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,16 @@ namespace Discord.Rest
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
|
||||
//Emotes
|
||||
public Task<GuildEmote> GetEmoteAsync(ulong id, RequestOptions options = null)
|
||||
=> GuildHelper.GetEmoteAsync(this, Discord, id, options);
|
||||
public Task<GuildEmote> CreateEmoteAsync(string name, Image image, Optional<IEnumerable<IRole>> roles = default(Optional<IEnumerable<IRole>>), RequestOptions options = null)
|
||||
=> GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options);
|
||||
public Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options);
|
||||
public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null)
|
||||
=> GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options);
|
||||
|
||||
//IGuild
|
||||
bool IGuild.Available => Available;
|
||||
IAudioClient IGuild.AudioClient => null;
|
||||
|
||||
Reference in New Issue
Block a user