Пример #1
0
        //Webhooks
        public static async Task <RestWebhook> GetWebhookAsync(IGuild guild, 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, guild, model));
        }
Пример #2
0
        //Webhooks
        public static async Task <RestWebhook> CreateWebhookAsync(ITextChannel channel, BaseDiscordClient client, string name, Stream avatar, RequestOptions options)
        {
            CreateWebhookParams args = new CreateWebhookParams {
                Name = name
            };

            if (avatar != null)
            {
                args.Avatar = new API.Image(avatar);
            }

            API.WebhookJson model = await client.ApiClient.CreateWebhookAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestWebhook.Create(client, channel, 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 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));
        }
Пример #5
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));
        }