Ejemplo n.º 1
0
            public Webhook(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ServerId  = r.ReadSnowflake("guild_id");
                ChannelId = r.ReadSnowflake("channel_id");
            }
Ejemplo n.º 2
0
            public ServerRoleDelete(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                RoleId   = r.ReadSnowflake("role_id");
                ServerId = r.ReadSnowflake("guild_id");
            }
Ejemplo n.º 3
0
            public ReactionRemoveAll(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                MessageId = r.ReadSnowflake("message_id");
                ChannelId = r.ReadSnowflake("channel_id");
            }
Ejemplo n.º 4
0
            public RawMessage(JObject data, bool isSet)
            {
                JsonObjectReader r = data.GetReader();

                ChannelId = r.ReadSnowflake("channel_id");
                Messages  = isSet ? r.ReadSnowflakeArray("ids") : new ulong[] { r.ReadSnowflake("id") };
            }
Ejemplo n.º 5
0
            public Reaction(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ReactorId = r.ReadSnowflake("user_id");
                MessageId = r.ReadSnowflake("message_id");
                ChannelId = r.ReadSnowflake("channel_id");
                JsonObjectReader re      = r.ReadObject("emoji");
                ulong?           emojiId = re.ReadNullableSnowflake("id");
                string           name    = re.ReadString("name");

                Emoji = emojiId != null ? (Emoji) new LazyServerEmoji((ulong)emojiId, name) : new GlobalEmoji(name);
            }
Ejemplo n.º 6
0
            public ServerEmojiUpdate(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ServerId = r.ReadSnowflake("guild_id");
                Emojis   = r.ReadObjectArray <EmojiJson>("emojis").Select(x => ServerEmoji.CreateFromJson(ServerId, x, null)).ToArray();
            }
Ejemplo n.º 7
0
            public ServerRole(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ServerId = r.ReadSnowflake("server_id");
                Role     = Role.CreateFromJson(ServerId, r.ReadObject <RoleJson>("role"), null);
            }
Ejemplo n.º 8
0
            public ChannelPinsUpdate(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ChannelId = r.ReadSnowflake("channel_id");
                string ts = r.ReadNullableString("list_pin_timestamp");

                LastPinTime = ts != null?DateTime.Parse(ts) : DateTime.MinValue;
            }
Ejemplo n.º 9
0
            public ServerUserSet(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ServerId = r.ReadSnowflake("guild_id");
                Users    = r.ReadObjectArray <ServerUserJson>("members").Select(x => {
                    User res = User.CreateFromJson(x.user, ServerId);
                    LazyUser.PushServerData(ServerId, x);
                    return(res);
                }).ToArray();
            }
Ejemplo n.º 10
0
        // TODO: Make channel concrete instead of a promise, and thus fix the cast error
        protected Message(JsonObjectReader r)
        {
            Id           = r.ReadSnowflake("id");
            ChannelId    = r.ReadSnowflake("channel_id");
            Channel      = new CachedPromise <TextChannel>(new AliasCache <IChannel, TextChannel>(ChannelUtils._globalCache), ChannelId, TextChannel.GetAsync);
            Content      = r.ReadString("content");
            CreationTime = DateTime.Parse(r.ReadString("timestamp"));
            string letStr = r.ReadNullableString("edited_timestamp"); if (letStr != null)

            {
                LastEditTime = (DateTime?)DateTime.Parse(letStr);
            }

            IsTextToSpeech    = r.ReadBoolean("tts");
            MentionedEveryone = r.ReadBoolean("mention_everyone");
            MentionedUsers    = r.ReadObjectArray <UserJson>("mentions").Select(x => User.CreateFromJson(x, null)).ToIdDic();
            MentionedRoles    = r.ReadObjectArray <RoleJson>("mention_roles").Select(x => Role.CreateFromJson(((IServerChannel)Channel.GetCachedValue()).ServerId, x, null)).ToIdDic();
            IsPinned          = r.ReadBoolean("pinned");
            MsgType           = (InternalMessageType)r.ReadInt32("type");
            _cache.Add(this);
        }
Ejemplo n.º 11
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.º 12
0
 public ServerUser(JObject data, bool seperate)
 {
     if (seperate)
     {
         JsonObjectReader r = data.GetReader();
         ServerId = r.ReadSnowflake("guild_id");
         Data     = User.CreateFromJson(r.ReadObject <UserJson>("user"), ServerId);
     }
     else
     {
         var json = data.ToObject <ServerUserGatewayJson>();
         ServerId = json.guild_id;
         Data     = User.CreateFromJson(json, ServerId);
     }
 }
Ejemplo n.º 13
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;
            }));
        }
Ejemplo n.º 14
0
        internal static Message Update(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
                {
                    // TODO: Create new message object when GET Message endpoint is done
                    res = null;
                }
                return res;
            }));
        }