예제 #1
0
        public override void PostCreatedByEditor()
        {
            Attachment attach = Attachment.Create(typeof(WaitTransition), this);

            attach.ResetId();
            this.AddAttachment(attach);
        }
예제 #2
0
        public IHttpActionResult Create()
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                foreach (string file in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[file];
                    var bytes      = new byte[postedFile.ContentLength];

                    var attachment = new Attachment();

                    using (var memory = new MemoryStream())
                    {
                        postedFile.InputStream.CopyTo(memory);
                        bytes = memory.ToArray();
                    }

                    attachment.Content  = bytes;
                    attachment.FileName = postedFile.FileName;

                    attachment.AttachmentGuid   = httpRequest.Params["guid"].ToString();
                    attachment.EventRequestId   = Convert.ToInt32(httpRequest.Params["id"]);
                    attachment.TypeOfAttachment = httpRequest.Params["type"].ToString();
                    attachment.Size             = bytes.Length;

                    attachment.Create();
                }
            }

            return(Json("OK", CamelCase));
        }
예제 #3
0
 private static Attachment CreateAttachment()
 {
     using (var fs = File.OpenRead("Files/Koala.jpg"))
         return(Attachment.Create(new Attachment
         {
             Content = fs,
             FileName = "Koala.jpg",
             ContentType = "image/jpg"
         }));
 }
예제 #4
0
        public void DeserializeTest()
        {
            var jsonString = TestUtils.GetResource("Mastodon.API.Tests.Resources.get_attachment.json");
            var actual     = JsonConvert.DeserializeObject <Attachment>(jsonString);
            var expected   = Attachment.Create(
                "39071",
                "image",
                new Uri("https://d2zoeobnny43zx.cloudfront.net/media_attachments/files/000/039/071/original/1a37136a4fe604b1.png?1492771668"),
                new Uri("https://d2zoeobnny43zx.cloudfront.net/media_attachments/files/000/039/071/original/1a37136a4fe604b1.png?1492771668"),
                new Uri("https://d2zoeobnny43zx.cloudfront.net/media_attachments/files/000/039/071/small/1a37136a4fe604b1.png?1492771668"),
                new Uri("https://friends.nico/media/NB4b8WwFtCxC2ynwZis")
                );

            Assert.AreEqual(expected, actual);
            actual.GetHashCode();
        }
예제 #5
0
        public void CanCreateAttachmentFromStream()
        {
            Assert.That(Attachment.All().Count(), Is.EqualTo(0));

            // Act.
            Attachment file;

            using (var fs = File.OpenRead("Files/Koala.jpg"))
                file = Attachment.Create(new Attachment
                {
                    Content     = fs,
                    ContentType = "image/jpg"
                });

            // Assert.
            Assert.That(file.ID, Is.Not.EqualTo(ObjectId.Empty));
            Assert.That(Attachment.All().Count(), Is.EqualTo(1));
        }
예제 #6
0
    public static void LoadUI(string uiPath, System.Action <GameObject> callBack)
    {
        if (m_Objs.ContainsKey(uiPath))
        {
            return;
        }
        AssetInfo assetInfo = CreateAssetInfo(uiPath);

        Resource.Load(assetInfo, (obj) =>
        {
            AssetBundle ab    = (AssetBundle)obj;
            GameObject newObj = (GameObject)Object.Instantiate(ab.LoadAllAssets()[0]);
            Attachment.Create(newObj, assetInfo);
            m_Objs.Add(uiPath, newObj);
            if (null != callBack)
            {
                callBack(newObj);
            }
        });
    }
예제 #7
0
        /// <summary>
        /// Bind this GraphicsSurface for drawing.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> to wich associate its rendering result to this GraphicsSurface.
        /// </param>
        public override void BindDraw(GraphicsContext ctx)
        {
            // Bind this framebuffer
            Gl.BindFramebuffer(FramebufferTarget.DrawFramebuffer, ObjectName);

            List <int> drawBuffers = new List <int>();

            for (uint i = 0; i < Gl.CurrentLimits.MaxColorAttachments; i++)
            {
                // Reset dirty binding points
                if ((_ColorBuffers[i] != null) && _ColorBuffers[i].Dirty)
                {
                    // Ensure created buffer
                    _ColorBuffers[i].Create(ctx);
                    // Ensure attached buffer
                    _ColorBuffers[i].Attach(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment0 + (int)i);
                    _ColorBuffers[i].Dirty = false;
                }

                // Collect draw buffers
                if (_ColorBuffers[i] != null)
                {
                    drawBuffers.Add(Gl.COLOR_ATTACHMENT0 + (int)i);
                }
            }

            if (_DepthAttachment != null && _DepthAttachment.Dirty)
            {
                // Ensure created buffer
                _DepthAttachment.Create(ctx);
                // Ensure attached buffer
                _DepthAttachment.Attach(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthAttachment);
                _DepthAttachment.Dirty = false;
            }

            // Validate completeness status
            Validate(ctx);

            // Update draw buffers
            Gl.DrawBuffers(drawBuffers.ToArray());
        }
예제 #8
0
        public void CanLoadAndReadAsset()
        {
            using (FileStream stream = File.OpenRead("Files/Koala.jpg"))
            {
                // Arrange.
                Attachment file = Attachment.Create(new Attachment
                {
                    Content     = stream,
                    FileName    = "Files/Koala.jpg",
                    ContentType = "image/jpg"
                });
                long contentLength = stream.Length;

                // Act.
                Attachment myFile          = Attachment.Find(file.ID);
                long       myContentLength = myFile.Content.Length;

                // Assert.
                Assert.That(myContentLength, Is.EqualTo(contentLength));
            }
        }
예제 #9
0
        public void CanSaveExistingAttachment()
        {
            // Arrange.
            using (FileStream stream = File.OpenRead("Files/Koala.jpg"))
            {
                Attachment file = Attachment.Create(new Attachment
                {
                    Content     = stream,
                    FileName    = "Files/Koala.jpg",
                    ContentType = "image/jpg"
                });
                ObjectId id = file.ID;

                // Act.
                file.FileName = "newfilename.jpg";
                file.Save();

                // Assert.
                Assert.That(file.ID, Is.EqualTo(id));
                Assert.That(Attachment.All().Count(), Is.EqualTo(1));
            }
        }
예제 #10
0
 public override Attachment CreateStartCondition(BaseNode owner)
 {
     return(Attachment.Create(typeof(PluginBehaviac.Events.StartCondition), owner as Node));
 }
예제 #11
0
        internal override void Update(ClientState state, Model model)
        {
            base.Update(state, model);

            SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;

            if (model.IsTextToSpeech.IsSpecified)
            {
                _isTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                _isPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                _isMentioningEveryone = model.MentionEveryone.Value;
            }
            if (model.RoleMentions.IsSpecified)
            {
                _roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).ToImmutableArray();
            }

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    _attachments = attachments.ToImmutable();
                }
                else
                {
                    _attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    _embeds = embeds.ToImmutable();
                }
                else
                {
                    _embeds = ImmutableArray.Create <Embed>();
                }
            }

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;
                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <SocketUser>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var val = value[i];
                        if (val.Object != null)
                        {
                            var user = Channel.GetUserAsync(val.Object.Id, CacheMode.CacheOnly).GetAwaiter().GetResult() as SocketUser;
                            if (user != null)
                            {
                                newMentions.Add(user);
                            }
                            else
                            {
                                newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object));
                            }
                        }
                    }
                    _userMentions = newMentions.ToImmutable();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text = model.Content.Value;
                _tags         = MessageHelper.ParseTags(text, Channel, guild, _userMentions);
                model.Content = text;
            }

            if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null)
            {
                var        refMsg       = model.ReferencedMessage.Value;
                ulong?     webhookId    = refMsg.WebhookId.ToNullable();
                SocketUser refMsgAuthor = null;
                if (refMsg.Author.IsSpecified)
                {
                    if (guild != null)
                    {
                        if (webhookId != null)
                        {
                            refMsgAuthor = SocketWebhookUser.Create(guild, state, refMsg.Author.Value, webhookId.Value);
                        }
                        else
                        {
                            refMsgAuthor = guild.GetUser(refMsg.Author.Value.Id);
                        }
                    }
                    else
                    {
                        refMsgAuthor = (Channel as SocketChannel).GetUser(refMsg.Author.Value.Id);
                    }
                    if (refMsgAuthor == null)
                    {
                        refMsgAuthor = SocketUnknownUser.Create(Discord, state, refMsg.Author.Value);
                    }
                }
                else
                {
                    // Message author wasn't specified in the payload, so create a completely anonymous unknown user
                    refMsgAuthor = new SocketUnknownUser(Discord, id: 0);
                }
                _referencedMessage = SocketUserMessage.Create(Discord, state, refMsgAuthor, Channel, refMsg);
            }
        }
예제 #12
0
        internal override void Update(Model model)
        {
            base.Update(model);

            if (model.IsTextToSpeech.IsSpecified)
            {
                _isTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                _isPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                _isMentioningEveryone = model.MentionEveryone.Value;
            }
            if (model.WebhookId.IsSpecified)
            {
                _webhookId = model.WebhookId.Value;
            }

            if (model.IsBlocked.IsSpecified)
            {
                _isBlocked = model.IsBlocked.Value;
            }

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    _attachments = attachments.ToImmutable();
                }
                else
                {
                    _attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    _embeds = embeds.ToImmutable();
                }
                else
                {
                    _embeds = ImmutableArray.Create <Embed>();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text = model.Content.Value;
                _tags         = MessageHelper.ParseTags(text, null, null, ImmutableArray.Create <IUser>());
                model.Content = text;
            }
        }
예제 #13
0
        internal override void Update(ClientState state, Model model)
        {
            base.Update(state, model);

            SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;

            if (model.IsTextToSpeech.IsSpecified)
            {
                _isTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                _isPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                _isMentioningEveryone = model.MentionEveryone.Value;
            }
            if (model.RoleMentions.IsSpecified)
            {
                _roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).ToImmutableArray();
            }

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    _attachments = attachments.ToImmutable();
                }
                else
                {
                    _attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    _embeds = embeds.ToImmutable();
                }
                else
                {
                    _embeds = ImmutableArray.Create <Embed>();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text = model.Content.Value;
                _tags         = MessageHelper.ParseTags(text, Channel, guild, MentionedUsers);
                model.Content = text;
            }

            if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null)
            {
                var        refMsg       = model.ReferencedMessage.Value;
                ulong?     webhookId    = refMsg.WebhookId.ToNullable();
                SocketUser refMsgAuthor = null;
                if (refMsg.Author.IsSpecified)
                {
                    if (guild != null)
                    {
                        if (webhookId != null)
                        {
                            refMsgAuthor = SocketWebhookUser.Create(guild, state, refMsg.Author.Value, webhookId.Value);
                        }
                        else
                        {
                            refMsgAuthor = guild.GetUser(refMsg.Author.Value.Id);
                        }
                    }
                    else
                    {
                        refMsgAuthor = (Channel as SocketChannel).GetUser(refMsg.Author.Value.Id);
                    }
                    if (refMsgAuthor == null)
                    {
                        refMsgAuthor = SocketUnknownUser.Create(Discord, state, refMsg.Author.Value);
                    }
                }
                else
                {
                    // Message author wasn't specified in the payload, so create a completely anonymous unknown user
                    refMsgAuthor = new SocketUnknownUser(Discord, id: 0);
                }
                _referencedMessage = SocketUserMessage.Create(Discord, state, refMsgAuthor, Channel, refMsg);
            }

            if (model.StickerItems.IsSpecified)
            {
                var value = model.StickerItems.Value;
                if (value.Length > 0)
                {
                    var stickers = ImmutableArray.CreateBuilder <SocketSticker>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var           stickerItem = value[i];
                        SocketSticker sticker     = null;

                        if (guild != null)
                        {
                            sticker = guild.GetSticker(stickerItem.Id);
                        }

                        if (sticker == null)
                        {
                            sticker = Discord.GetSticker(stickerItem.Id);
                        }

                        // if they want to auto resolve
                        if (Discord.AlwaysResolveStickers)
                        {
                            sticker = Task.Run(async() => await Discord.GetStickerAsync(stickerItem.Id).ConfigureAwait(false)).GetAwaiter().GetResult();
                        }

                        // if its still null, create an unknown
                        if (sticker == null)
                        {
                            sticker = SocketUnknownSticker.Create(Discord, stickerItem);
                        }

                        stickers.Add(sticker);
                    }

                    _stickers = stickers.ToImmutable();
                }
                else
                {
                    _stickers = ImmutableArray.Create <SocketSticker>();
                }
            }
        }
예제 #14
0
        internal SocketResolvableData(DiscordSocketClient discord, ulong?guildId, T model)
        {
            var guild = guildId.HasValue ? discord.GetGuild(guildId.Value) : null;

            var resolved = model.Resolved.Value;

            if (resolved.Users.IsSpecified)
            {
                foreach (var user in resolved.Users.Value)
                {
                    var socketUser = discord.GetOrCreateUser(discord.State, user.Value);

                    Users.Add(ulong.Parse(user.Key), socketUser);
                }
            }

            if (resolved.Channels.IsSpecified)
            {
                foreach (var channel in resolved.Channels.Value)
                {
                    SocketChannel socketChannel = guild != null
                        ? guild.GetChannel(channel.Value.Id)
                        : discord.GetChannel(channel.Value.Id);

                    if (socketChannel == null)
                    {
                        var channelModel = guild != null
                            ? discord.Rest.ApiClient.GetChannelAsync(guild.Id, channel.Value.Id).ConfigureAwait(false).GetAwaiter().GetResult()
                            : discord.Rest.ApiClient.GetChannelAsync(channel.Value.Id).ConfigureAwait(false).GetAwaiter().GetResult();

                        socketChannel = guild != null
                            ? SocketGuildChannel.Create(guild, discord.State, channelModel)
                            : (SocketChannel)SocketChannel.CreatePrivate(discord, discord.State, channelModel);
                    }

                    discord.State.AddChannel(socketChannel);
                    Channels.Add(ulong.Parse(channel.Key), socketChannel);
                }
            }

            if (resolved.Members.IsSpecified && guild != null)
            {
                foreach (var member in resolved.Members.Value)
                {
                    member.Value.User = resolved.Users.Value[member.Key];
                    var user = guild.AddOrUpdateUser(member.Value);
                    GuildMembers.Add(ulong.Parse(member.Key), user);
                }
            }

            if (resolved.Roles.IsSpecified)
            {
                foreach (var role in resolved.Roles.Value)
                {
                    var socketRole = guild.AddOrUpdateRole(role.Value);
                    Roles.Add(ulong.Parse(role.Key), socketRole);
                }
            }

            if (resolved.Messages.IsSpecified)
            {
                foreach (var msg in resolved.Messages.Value)
                {
                    var channel = discord.GetChannel(msg.Value.ChannelId) as ISocketMessageChannel;

                    SocketUser author;
                    if (guild != null)
                    {
                        if (msg.Value.WebhookId.IsSpecified)
                        {
                            author = SocketWebhookUser.Create(guild, discord.State, msg.Value.Author.Value, msg.Value.WebhookId.Value);
                        }
                        else
                        {
                            author = guild.GetUser(msg.Value.Author.Value.Id);
                        }
                    }
                    else
                    {
                        author = (channel as SocketChannel).GetUser(msg.Value.Author.Value.Id);
                    }

                    if (channel == null)
                    {
                        if (!msg.Value.GuildId.IsSpecified)  // assume it is a DM
                        {
                            channel = discord.CreateDMChannel(msg.Value.ChannelId, msg.Value.Author.Value, discord.State);
                        }
                    }

                    var message = SocketMessage.Create(discord, discord.State, author, channel, msg.Value);
                    Messages.Add(message.Id, message);
                }
            }

            if (resolved.Attachments.IsSpecified)
            {
                foreach (var attachment in resolved.Attachments.Value)
                {
                    var discordAttachment = Attachment.Create(attachment.Value);

                    Attachments.Add(ulong.Parse(attachment.Key), discordAttachment);
                }
            }
        }
예제 #15
0
        internal override void Update(ClientState state, Model model)
        {
            base.Update(state, model);

            if (model.IsTextToSpeech.IsSpecified)
            {
                _isTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                _isPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                _isMentioningEveryone = model.MentionEveryone.Value;
            }

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    _attachments = attachments.ToImmutable();
                }
                else
                {
                    _attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    _embeds = embeds.ToImmutable();
                }
                else
                {
                    _embeds = ImmutableArray.Create <Embed>();
                }
            }

            IReadOnlyCollection <IUser> mentions = ImmutableArray.Create <SocketUnknownUser>(); //Is passed to ParseTags to get real mention collection

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;
                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <SocketUnknownUser>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var val = value[i];
                        if (val.Object != null)
                        {
                            newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object));
                        }
                    }
                    mentions = newMentions.ToImmutable();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text  = model.Content.Value;
                var guild = (Channel as SocketGuildChannel)?.Guild;
                _tags         = MessageHelper.ParseTags(text, Channel, guild, mentions);
                model.Content = text;
            }
        }
예제 #16
0
        internal void Update(Model model)
        {
            Id        = model.Id;
            CreatedAt = SnowflakeUtils.FromSnowflake(Id);

            if (model.IsTextToSpeech.IsSpecified)
            {
                IsTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                IsPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                EditedTimestamp = model.EditedTimestamp.Value;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                MentionedEveryone = model.MentionEveryone.Value;
            }
            if (model.RoleMentions.IsSpecified)
            {
                MentionedRoleIds = model.RoleMentions.Value.ToImmutableArray();
            }

            MentionedUserIds    = new List <ulong>();
            MentionedChannelIds = new List <ulong>();

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    Attachments = attachments.ToImmutable();
                }
                else
                {
                    Attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    Embeds = embeds.ToImmutable();
                }
                else
                {
                    Embeds = ImmutableArray.Create <Embed>();
                }
            }

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;

                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <ulong>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var val = value[i];
                        if (val.Object != null)
                        {
                            newMentions.Add(val.Object.Id);
                        }
                    }
                    MentionedUserIds = newMentions.ToReadOnlyCollection();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text = model.Content.Value;
                model.Content = text;
            }
        }
예제 #17
0
        internal override void Update(ClientState state, Model model)
        {
            base.Update(state, model);

            SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;

            if (model.IsTextToSpeech.IsSpecified)
            {
                _isTTS = model.IsTextToSpeech.Value;
            }
            if (model.Pinned.IsSpecified)
            {
                _isPinned = model.Pinned.Value;
            }
            if (model.EditedTimestamp.IsSpecified)
            {
                _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks;
            }
            if (model.MentionEveryone.IsSpecified)
            {
                _isMentioningEveryone = model.MentionEveryone.Value;
            }
            if (model.Flags.IsSpecified)
            {
                _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed);
            }
            if (model.RoleMentions.IsSpecified)
            {
                _roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).ToImmutableArray();
            }

            if (model.Attachments.IsSpecified)
            {
                var value = model.Attachments.Value;
                if (value.Length > 0)
                {
                    var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        attachments.Add(Attachment.Create(value[i]));
                    }
                    _attachments = attachments.ToImmutable();
                }
                else
                {
                    _attachments = ImmutableArray.Create <Attachment>();
                }
            }

            if (model.Embeds.IsSpecified)
            {
                var value = model.Embeds.Value;
                if (value.Length > 0)
                {
                    var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        embeds.Add(value[i].ToEntity());
                    }
                    _embeds = embeds.ToImmutable();
                }
                else
                {
                    _embeds = ImmutableArray.Create <Embed>();
                }
            }

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;
                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <SocketUser>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var val       = value[i];
                        var guildUser = guild.GetUser(val.Id);
                        if (guildUser != null)
                        {
                            newMentions.Add(guildUser);
                        }
                        else if (val.Object != null)
                        {
                            newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object));
                        }
                    }
                    _userMentions = newMentions.ToImmutable();
                }
            }

            if (model.Content.IsSpecified)
            {
                var text = model.Content.Value;
                _tags         = MessageHelper.ParseTags(text, Channel, guild, _userMentions);
                model.Content = text;
            }
        }