internal static RestWebhook Create(BaseDiscordClient discord, ITextChannel channel, Model model) { var entity = new RestWebhook(discord, channel, model.Id, model.Token, model.ChannelId); entity.Update(model); return(entity); }
public static async Task <IReadOnlyCollection <RestWebhook> > GetWebhooksAsync(ITextChannel channel, BaseDiscordClient client, RequestOptions options) { var models = await client.ApiClient.GetChannelWebhooksAsync(channel.Id, options).ConfigureAwait(false); return(models.Select(x => RestWebhook.Create(client, channel, x)) .ToImmutableArray()); }
internal static RestWebhook Create(BaseDiscordClient discord, IGuild guild, Model model) { RestWebhook entity = new RestWebhook(discord, guild, model.Id, model.Token, model.ChannelId); entity.Update(model); return(entity); }
//Webhooks public static async Task<RestWebhook> CreateWebhookAsync(ITextChannel channel, BaseDiscordClient client, string name, Stream avatar, RequestOptions options) { var args = new CreateWebhookParams { Name = name }; if (avatar != null) args.Avatar = new API.Image(avatar); var model = await client.ApiClient.CreateWebhookAsync(channel.Id, args, options).ConfigureAwait(false); return RestWebhook.Create(client, channel, model); }
public static async Task <RestWebhook> GetWebhookAsync(ITextChannel channel, BaseDiscordClient client, ulong id, RequestOptions options) { API.WebhookJson model = await client.ApiClient.GetWebhookAsync(id, options : options).ConfigureAwait(false); if (model == null) { return(null); } return(RestWebhook.Create(client, channel, model)); }
public static async Task <RestWebhook> GetWebhookAsync(BaseDiscordClient client, ulong id, RequestOptions options) { var model = await client.ApiClient.GetWebhookAsync(id); if (model != null) { return(RestWebhook.Create(client, (IGuild)null, model)); } return(null); }
//Webhooks public static async Task <RestWebhook> GetWebhookAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { var model = await client.ApiClient.GetWebhookAsync(id, options : options).ConfigureAwait(false); if (model == null) { return(null); } return(RestWebhook.Create(client, guild, model)); }
internal static WebhookCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { API.AuditLogChangeJson[] changes = entry.Changes; API.AuditLogChangeJson channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); API.AuditLogChangeJson typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); API.AuditLogChangeJson nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); ulong channelId = channelIdModel.NewValue.ToObject <ulong>(discord.ApiClient.Serializer); WebhookType type = typeModel.NewValue.ToObject <WebhookType>(discord.ApiClient.Serializer); string name = nameModel.NewValue.ToObject <string>(discord.ApiClient.Serializer); API.WebhookJson webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); RestWebhook webhook = webhookInfo == null ? null : RestWebhook.Create(discord, (IGuild)null, webhookInfo); return(new WebhookCreateAuditLogData(webhook, entry.TargetId.Value, type, name, channelId)); }
internal static WebhookCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { var changes = entry.Changes; var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); var channelId = channelIdModel.NewValue.ToObject <ulong>(discord.ApiClient.Serializer); var type = typeModel.NewValue.ToObject <WebhookType>(discord.ApiClient.Serializer); var name = nameModel.NewValue.ToObject <string>(discord.ApiClient.Serializer); var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); return(new WebhookCreateAuditLogData(webhook, type, name, channelId)); }
internal static WebhookUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { var changes = entry.Changes; var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); var avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash"); var oldName = nameModel?.OldValue?.ToObject <string>(); var oldChannelId = channelIdModel?.OldValue?.ToObject <ulong>(); var oldAvatar = avatarHashModel?.OldValue?.ToObject <string>(); var before = new WebhookInfo(oldName, oldChannelId, oldAvatar); var newName = nameModel?.NewValue?.ToObject <string>(); var newChannelId = channelIdModel?.NewValue?.ToObject <ulong>(); var newAvatar = avatarHashModel?.NewValue?.ToObject <string>(); var after = new WebhookInfo(newName, newChannelId, newAvatar); var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); return(new WebhookUpdateAuditLogData(webhook, before, after)); }
internal static WebhookUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) { API.AuditLogChangeJson[] changes = entry.Changes; API.AuditLogChangeJson nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); API.AuditLogChangeJson channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); API.AuditLogChangeJson avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash"); string oldName = nameModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer); ulong? oldChannelId = channelIdModel?.OldValue?.ToObject <ulong>(discord.ApiClient.Serializer); string oldAvatar = avatarHashModel?.OldValue?.ToObject <string>(discord.ApiClient.Serializer); WebhookInfo before = new WebhookInfo(oldName, oldChannelId, oldAvatar); string newName = nameModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer); ulong? newChannelId = channelIdModel?.NewValue?.ToObject <ulong>(discord.ApiClient.Serializer); string newAvatar = avatarHashModel?.NewValue?.ToObject <string>(discord.ApiClient.Serializer); WebhookInfo after = new WebhookInfo(newName, newChannelId, newAvatar); API.WebhookJson webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); RestWebhook webhook = webhookInfo != null?RestWebhook.Create(discord, (IGuild)null, webhookInfo) : null; return(new WebhookUpdateAuditLogData(webhook, before, after)); }
/// <inheritdoc /> public Task UpdateAsync(RequestOptions options = null) => RestWebhook.UpdateAsync(options);
//News public static async Task <RestWebhook> CreateNewsWebhookAsync(BaseDiscordClient client, SocketNewsChannel source, ITextChannel target, RequestOptions options) { API.WebhookJson model = await client.ApiClient.CreateFollowWebhookAsync(source.Id, new CreateWebhookNews(target.Id), options).ConfigureAwait(false); return(RestWebhook.Create(client, target, model)); }
/// <summary> /// Converts an existing <see cref="RestWebhook"/> to an abstracted <see cref="IRestWebhook"/> value. /// </summary> /// <param name="restWebhook">The existing <see cref="RestWebhook"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restWebhook"/>.</exception> /// <returns>An <see cref="IRestWebhook"/> that abstracts <paramref name="restWebhook"/>.</returns> public static IRestWebhook Abstract(this RestWebhook restWebhook) => new RestWebhookAbstraction(restWebhook);
public static async Task <IReadOnlyCollection <RestWebhook> > GetWebhooksAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { IReadOnlyCollection <API.WebhookJson> models = await client.ApiClient.GetGuildWebhooksAsync(guild.Id, options).ConfigureAwait(false); return(models.Select(x => RestWebhook.Create(client, guild, x)).ToImmutableArray()); }
/// <summary> /// Constructs a new <see cref="RestWebhookAbstraction"/> around an existing <see cref="Rest.RestWebhook"/>. /// </summary> /// <param name="restWebhook">The value to use for <see cref="Rest.RestWebhook"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restWebhook"/>.</exception> public RestWebhookAbstraction(RestWebhook restWebhook) { RestWebhook = restWebhook ?? throw new ArgumentNullException(nameof(restWebhook)); }
/// <inheritdoc cref="RestWebhook.ToString" /> public override string ToString() => RestWebhook.ToString();
/// <inheritdoc /> public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) => RestWebhook.GetAvatarUrl(format, size);
/// <inheritdoc /> public Task DeleteAsync(RequestOptions options = null) => RestWebhook.DeleteAsync(options);
/// <inheritdoc /> public Task ModifyAsync(Action <WebhookProperties> func, RequestOptions options = null) => RestWebhook.ModifyAsync(func, options);