private static void CallBackSynch(object SynchData) { SynchObject synchObject = (SynchObject)SynchData; Console.WriteLine(synchObject.bot.Name); dynamic getLongPollServer = JObject.Parse(new HttpRequest(Program.Api).Post("messages.getLongPollServer?need_pts=1&lp_version=3&" + synchObject.bot.Token).ToString()); string server = getLongPollServer.response.server; string key = getLongPollServer.response.key; string ts = getLongPollServer.response.ts; bool sync = false; while (!sync) { dynamic requestUserLongPoll = JObject.Parse(new HttpRequest().Post("https://" + server + "?act=a_check&key=" + key + "&ts=" + ts + "&wait=25&mode=2&version=2").ToString()); foreach (JArray update in requestUserLongPoll.updates) { if ((int)update[0] == 4) { int PeerId = (int)update[3]; if (PeerId > 2000000000) { string text = (string)update[5]; if (text == synchObject.synchMessage.ToString()) { Console.WriteLine(PeerId); Thread.Sleep(synchObject.bot.Class * 100); GroupAssoc.ReWriteAssoc(synchObject.message.PeerId, PeerId, synchObject.bot); sync = true; } } } } ts = requestUserLongPoll.ts; } return; }
public static void GroupSynch(Messages command = null) { if (command == null) { command = Messages.Current; } int synch_message = new Random().Next(0, 999999) * 15; foreach (int botid in command.GroupId.BotsCatalog) { if (botid > 0) { object obj = new SynchObject { message = command, bot = Bots.GetBot(botid), synchMessage = synch_message }; Thread synch = new Thread(CallBackSynch); synch.Start(obj); } } Functions.SendMessage(synch_message.ToString(), command.GroupId.Id, 0); }