예제 #1
0
 private SlackUser GetMessageUser(string userId)
 {
     return(UserCache.ContainsKey(userId) ?
            UserCache[userId] :
            new SlackUser {
         Id = userId, Name = string.Empty
     });
 }
예제 #2
0
 internal User FromUser(User user)
 {
     lock (UserCacheLocker)
     {
         if (!UserCache.ContainsKey(user))
         {
             UserCache.Add(user, false);
         }
         return(user);
     }
 }
예제 #3
0
 internal ApiUser ApiUser(User user)
 {
     lock (UserCacheLocker)
     {
         if (UserCache.ContainsKey(user))
         {
             return(UserCache[user]);
         }
         UserCache.Add(user, null);
         return(null);
     }
 }
예제 #4
0
파일: ApiUserCache.cs 프로젝트: wlk0/OCTGN
 public ApiUser ApiUser(User user)
 {
     lock (UserCacheLocker)
     {
         if (UserCache.ContainsKey(user))
         {
             return UserCache[user];
         }
         UserCache.Add(user,null);
         return null;
     }
 }
예제 #5
0
 internal void SetUserSubbed(User user, bool subbed)
 {
     lock (UserCacheLocker)
     {
         if (UserCache.ContainsKey(user))
         {
             UserCache[user] = subbed;
             return;
         }
         UserCache.Add(user, subbed);
     }
 }
예제 #6
0
 internal bool IsUserSubbed(User user)
 {
     lock (UserCacheLocker)
     {
         if (UserCache.ContainsKey(user))
         {
             return(UserCache[user]);
         }
         UserCache.Add(user, false);
         return(false);
     }
 }
예제 #7
0
파일: Kbtter.cs 프로젝트: kb10uy/Kbtter3
 /// <summary>
 /// ユーザーを取得してみる
 /// </summary>
 /// <param name="sn">SN</param>
 /// <returns>User</returns>
 public Task <User> GetUser(string sn)
 {
     return(Task <User> .Run(async() =>
     {
         if (UserCache.ContainsKey(sn))
         {
             return UserCache[sn];
         }
         var us = await Token.Users.ShowAsync(screen_name => sn);
         UserCache[sn] = us;
         return us;
     }));
 }
예제 #8
0
        public async Task <IReadOnlyList <DiscordMember> > ListGuildMembersAsync(ulong guild_id, int?limit, ulong?after)
        {
            var recmbr = new List <DiscordMember>();

            var recd = 1000;
            var last = 0ul;

            while (recd == 1000)
            {
                var tms = await ApiClient.ListGuildMembersAsync(guild_id, 1000, last == 0?null : (ulong?)last).ConfigureAwait(false);

                recd = tms.Count;

                foreach (var xtm in tms)
                {
                    if (UserCache.ContainsKey(xtm.User.Id))
                    {
                        continue;
                    }

                    var usr = new DiscordUser(xtm.User)
                    {
                        Discord = this
                    };
                    UserCache.AddOrUpdate(xtm.User.Id, usr, (id, old) =>
                    {
                        old.Username   = usr.Username;
                        old.Discord    = usr.Discord;
                        old.AvatarHash = usr.AvatarHash;

                        return(old);
                    });
                }

                var tm = tms.LastOrDefault();
                last = tm?.User.Id ?? 0;

                recmbr.AddRange(tms.Select(xtm => new DiscordMember(xtm)
                {
                    Discord = this, _guild_id = guild_id
                }));
            }

            return(new ReadOnlyCollection <DiscordMember>(recmbr));
        }
예제 #9
0
        /// <summary>
        /// Parses sub profile information given from the packet
        /// </summary>
        /// <param name="bot"></param>
        /// <param name="packet"></param>
        public void Parse(PalBot bot, Packet packet)
        {
            DataMap map;

            if (packet["IV"] != null && packet["RK"] != null)
            {
                int iv = int.Parse(packet["IV"]);
                int rk = iv != 0 ? int.Parse(packet["RK"]) : 0;
                map = new DataMap();
                map.Deserialize(Static.PalringoEncoding.GetBytes(packet.Payload), iv, packet.Payload.Length - iv - rk);
            }
            else
            {
                map = new DataMap(Static.PalringoEncoding.GetBytes(packet.Payload));
            }

            try
            {
                var contacts = map.GetValueMapAll("contacts");
                if (contacts != null)
                {
                    foreach (var item in contacts.Data)
                    {
                        UserId id;
                        if (!UserId.TryParse(item.Key, out id))
                        {
                            continue;
                        }

                        var cm = new DataMap(item.Value);
                        if (UserCache.ContainsKey(id))
                        {
                            UserCache[id].Parse(bot, cm);
                        }
                        else
                        {
                            var u = new User(id);
                            u.Parse(bot, cm);
                            UserCache.Add(id, u);
                        }
                    }
                }

                var groups = map.GetValueMap("group_sub");
                if (groups != null)
                {
                    foreach (var gm in groups.Data)
                    {
                        int id;
                        if (!int.TryParse(gm.Key, out id))
                        {
                            continue;
                        }
                        if (Groups.ContainsKey(id))
                        {
                            Groups[id].Parse(bot, new DataMap(gm.Value));
                        }
                        else
                        {
                            var gp = new Group {
                                Id = id
                            };
                            gp.Parse(bot, new DataMap(gm.Value));
                            Groups.Add(id, gp);
                            bot.On.Trigger("gj", gp);
                        }
                    }
                }

                var ext = map.GetValueMap("ext");
                if (ext != null)
                {
                    Profile.Parse(bot, ext);
                }

                if (map != null)
                {
                    Profile.Parse(bot, map);
                }
            }
            catch (Exception ex)
            {
                bot.On.Trigger("e", ex);
            }
        }