コード例 #1
0
        /// <summary>
        /// Watches for a response to the a user profile request
        /// </summary>
        /// <param name="Bot">The bot instance to attach to</param>
        /// <param name="uid">The user id to look for</param>
        /// <param name="resp">The action to do upon finishing</param>
        /// <returns>This instance of the packet (for string-able-ness)</returns>
        public Packet Watch(PalBot Bot, UserId uid, Action <User> resp)
        {
            if (resp == null)
            {
                return(this);
            }

            Bot.Callbacks.Watch("SUB PROFILE QUERY RESULT", resp, (packet) =>
            {
                var bytes = Static.PalringoEncoding.GetBytes(packet.Payload);
                var map   = new DataMap(bytes);

                if (map.ContainsKey("sub-id"))
                {
                    int id = map.GetValueInt("sub-id");

                    if (!Bot.Information.UserCache.ContainsKey(id))
                    {
                        Bot.Information.UserCache.Add(id, new User());
                    }

                    foreach (var m in map.EnumerateMaps())
                    {
                        Bot.Information.UserCache[id].Parse(Bot, m);
                    }

                    return(Bot.Information.UserCache[id]);
                }
                return(null);
            }, (t) => t.Id == uid);
            return(this);
        }