Ejemplo n.º 1
0
        internal virtual void UpdateInstance(JsonObjectReader r)
        {
            ulong cid = r.ReadSnowflake("channel_id");

            if (cid != ChannelId)
            {
                ChannelId = cid;
                Channel   = new CachedPromise <TextChannel>(new AliasCache <IChannel, TextChannel>(ChannelUtils._globalCache), ChannelId, TextChannel.GetAsync);
            }
            // author and webhook_id should be dealt with in this method's overloads
            if (r.Contains("content"))
            {
                Content = r.ReadString("content");
            }
            if (r.Contains("timestamp"))
            {
                CreationTime = DateTime.Parse(r.ReadString("timestamp"));
            }
            if (r.Contains("edited_timestamp"))
            {
                string letStr = r.ReadNullableString("edited_timestamp"); if (letStr != null)
                {
                    LastEditTime = (DateTime?)DateTime.Parse(letStr);
                }
            }
            if (r.Contains("tts"))
            {
                IsTextToSpeech = r.ReadBoolean("tts");
            }
            if (r.Contains("mention_everyone"))
            {
                MentionedEveryone = r.ReadBoolean("mention_everyone");
            }
            if (r.Contains("mentions"))
            {
                MentionedUsers = r.ReadObjectArray <UserJson>("mentions").Select(x => User.CreateFromJson(x, null)).ToIdDic();
            }
            if (r.Contains("mention_roles"))
            {
                MentionedRoles = r.ReadObjectArray <RoleJson>("mention_roles").Select(x => Role.CreateFromJson(((IServerChannel)Channel.GetCachedValue()).ServerId, x, null)).ToIdDic();
            }
            if (r.Contains("pinned"))
            {
                IsPinned = r.ReadBoolean("pinned");
            }
            if (r.Contains("type"))
            {
                MsgType = (InternalMessageType)r.ReadInt32("type");
            }
        }
Ejemplo n.º 2
0
        internal static Message Create(JObject obj)
        {
            JsonObjectReader r  = obj.GetReader();
            ulong            id = r.ReadSnowflake("id");

            return(_cache.Mutex(() => {
                Message res;
                if (_cache.Contains(id))
                {
                    res = _cache[id];
                    res.UpdateInstance(r);
                }
                else
                {
                    res = r.Contains("webhook_id") ? (Message) new WebhookMessage(r) : new StandardMessage(r);
                }
                return res;
            }));
        }