Ejemplo n.º 1
0
 public static void SaveBot(Bots bot)
 {
     DataBase.Connect();
     DataBase.Query("UPDATE Bots SET " +
                    "bGroupsCount = " + bot.GroupsCount + ", " +
                    "bGroups = '" + GroupAssoc.Encode(bot.groupAssocs) + "' " +
                    "WHERE bID = " + bot.Id).ExecuteNonQuery();
     DataBase.Close();
     Console.WriteLine("[system] Бот " + bot.Name + " обновлён");
 }
Ejemplo n.º 2
0
        public static void SendMessage(int replyMessage, string replyText, int destinationChat, int botClass = 0)
        {
            Thread.Sleep(new Random().Next(50, 150));
            Groups group = Groups.GetGroup(destinationChat);

            if (group.BotsCatalog[botClass] > -1)
            {
                if (botClass > 0)
                {
                    destinationChat = GroupAssoc.GetAssoc(destinationChat, Bots.GetBot(group.BotsCatalog[botClass]));
                }
                new HttpRequest(Program.Api).Post("messages.send?peer_id=" + destinationChat + "&message=" + replyText + "&forward_messages=" + replyMessage + "&" + Bots.GetBot(group.BotsCatalog[botClass]).Token);
            }
        }
Ejemplo n.º 3
0
        public List <GroupAssoc> groupAssocs;   // База ассоциаций групп и пиров


        public static void CreateList()
        {
            DataBase.Connect();
            DataBase.Reader = DataBase.Query("SELECT * FROM Bots").ExecuteReader();
            while (DataBase.Reader.Read())
            {
                Bots added_bot = new Bots
                {
                    Name        = (string)DataBase.Reader["bName"],
                    Id          = (int)DataBase.Reader["bID"],
                    Token       = "access_token=" + (string)DataBase.Reader["bToken"] + Program.ApiVer,
                    Class       = (int)DataBase.Reader["bClass"],
                    GroupsCount = (int)DataBase.Reader["bGroupsCount"],
                    groupAssocs = GroupAssoc.Decode(DataBase.Reader["bGroups"].ToString())
                };
                List.Add(added_bot);
            }
            DataBase.Close();
            Console.WriteLine("[system] Список ботов загружен");
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 public static List <GroupAssoc> Decode(string encryptedString)
 {
     if (encryptedString != "")
     {
         List <GroupAssoc> groupAssocs  = new List <GroupAssoc>();
         string[]          associations = encryptedString.Split('|');
         foreach (string association in associations)
         {
             if (association != "")
             {
                 GroupAssoc groupAssoc = new GroupAssoc();
                 string[]   assoc2     = association.Split('=');
                 groupAssoc.Id   = Convert.ToInt32(assoc2[0]);
                 groupAssoc.Peer = Convert.ToInt32(assoc2[1]);
                 groupAssocs.Add(groupAssoc);
             }
         }
         return(groupAssocs);
     }
     else
     {
         return(new List <GroupAssoc>());
     }
 }