Пример #1
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());
        }
Пример #2
0
 public static async Task<RestWebhook> GetWebhookAsync(ITextChannel channel, 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, channel, model);
 }
Пример #3
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);
        }
Пример #4
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));
        }
Пример #5
0
        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);
        }
        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 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));
        }
Пример #8
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));
        }
        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));
        }
Пример #10
0
        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());
        }
Пример #11
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));
        }