/// <summary> /// Entry point /// </summary> /// <param name="bot"></param> /// <param name="ids"></param> /// <param name="onFinish"></param> public static void GetUsers(this PalBot bot, int[] ids, Action <User[]> onFinish) { var id = Count; Count += 1; var request = new Request(ids, onFinish); Requests.Add(id, request); foreach (var uid in ids) { bot.UserInfo(uid, (u) => { Requests[id].FetchedUsers.Add(uid, u); if (Requests[id].Finished) { onFinish(Requests[id].FetchedUsers.Values.ToArray()); Requests.Remove(id); } }, (r) => { if (r.Type == Subprofile.Types.Type.Code && r.Code == Code.NO_SUCH_WHATEVER) { Requests[id].FailedIds.Add(uid); if (Requests[id].Finished) { onFinish(Requests[id].FetchedUsers.Values.ToArray()); Requests.Remove(id); } } }); } }
/// <summary> /// Watch a packet collection for the responses. /// </summary> /// <param name="packets">The packets to send</param> /// <param name="bot">The bot to send them on</param> /// <param name="onResponse">The response handler</param> /// <param name="onlyLast">Only watch for the last response in the cluge</param> /// <returns>The original array of packets.</returns> public static Packet[] Watch(this Packet[] packets, PalBot bot, rs onResponse, bool onlyLast = true) { try { if (!onlyLast) { foreach (var p in packets) { p.Watch(bot, onResponse); } } else { packets.Last().Watch(bot, onResponse); } } catch (Exception ex) { bot.On.Trigger("e", ex); } return(packets); }
/// <summary> /// Trys to parse the string as a group and gets group info /// </summary> /// <param name="idin"></param> /// <param name="bot"></param> /// <param name="id"></param> /// <returns></returns> public static bool TryParse(string idin, PalBot bot, out GroupId id) { int oid; bool isParsed = int.TryParse(idin, out oid); if (isParsed) { id = oid; return(true); } var usrs = bot.Information.Groups.Where(t => t.Value.Name.ToLower().Trim() == idin.ToLower().Trim()).ToArray(); if (usrs.Length > 0) { id = usrs.Last().Key; return(true); } id = -1; return(false); }
/// <summary> /// Gets the group data from the bot /// </summary> /// <param name="bot"></param> /// <returns></returns> public Group GetGroup(PalBot bot) { return(bot.Information.Groups.ContainsKey(this) ? bot.Information.Groups[this] : new Group(_value, false)); }
/// <summary> /// Gets a user profile from the bot /// </summary> /// <param name="bot"></param> /// <returns></returns> public User GetUser(PalBot bot) { return(bot.Information.UserCache.ContainsKey(this) ? bot.Information.UserCache[this] : null); }