コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
ファイル: RestWebhook.cs プロジェクト: xXBuilderBXx/DNetPlus
        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);
        }
コード例 #4
0
        //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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: ClientHelper.cs プロジェクト: patrykr5/Discord.Net
        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);
        }
コード例 #7
0
        //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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <inheritdoc />
 public Task UpdateAsync(RequestOptions options = null)
 => RestWebhook.UpdateAsync(options);
コード例 #13
0
        //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));
        }
コード例 #14
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <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);
コード例 #15
0
ファイル: GuildHelper.cs プロジェクト: xXBuilderBXx/DNetPlus
        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());
        }
コード例 #16
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <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));
 }
コード例 #17
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <inheritdoc cref="RestWebhook.ToString" />
 public override string ToString()
 => RestWebhook.ToString();
コード例 #18
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <inheritdoc />
 public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
 => RestWebhook.GetAvatarUrl(format, size);
コード例 #19
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <inheritdoc />
 public Task DeleteAsync(RequestOptions options = null)
 => RestWebhook.DeleteAsync(options);
コード例 #20
0
ファイル: IRestWebhook.cs プロジェクト: Scott-Caldwell/MODiX
 /// <inheritdoc />
 public Task ModifyAsync(Action <WebhookProperties> func, RequestOptions options = null)
 => RestWebhook.ModifyAsync(func, options);