Exemplo n.º 1
0
        public static void InviteBot(Messages command = null)
        {
            int botClass = Convert.ToInt32(command.Args);

            if (command == null)
            {
                command = Messages.Current;
            }
            List <Bots> BotClass = Bots.GetClassList(botClass);

            if (botClass == 1)
            {
                if (command.GroupId.BotsCatalog[botClass] == -1)
                {
                    int botNum = new Random().Next(0, BotClass.Count);
                    Console.WriteLine(botNum);
                    command.GroupId.BotsCatalog[botClass] = BotClass[botNum].Id;
                    int chat_id = command.PeerId;
                    if (chat_id > 2000000000)
                    {
                        chat_id -= 2000000000;
                    }
                    //string res = new HttpRequest(Program.Api).Post("messages.addChatUser?chat_id=" + chat_id + "&user_id=" + BotClass[botNum].Id + "&" + Bots.List[0].Token + Program.ApiVer).ToString();
                    BotClass[botNum].GroupsCount++;
                    BotClass[botNum].groupAssocs.Add(new GroupAssoc {
                        Id = command.GroupId.Id, Peer = 2000000000 + BotClass[botNum].GroupsCount
                    });
                    Bots.SaveBot(BotClass[botNum]);
                    Groups.SaveGroup(command.GroupId);
                    //Functions.SendReply("Я откликнулся на твой зов!", GroupAssoc.GetAssoc(command.GroupId.Id, BotClass[botNum]).Peer, BotClass[botNum].Token);
                }
            }
        }
Exemplo n.º 2
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 + " обновлён");
 }
Exemplo n.º 3
0
 public static int GetAssoc(Groups group, Bots bot)
 {
     foreach (GroupAssoc groupAssoc in bot.groupAssocs)
     {
         if (groupAssoc.Id == group.Id)
         {
             return(groupAssoc.Peer);
         }
     }
     return(-1);
 }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
 public static void ReWriteAssoc(int group, int peer, Bots bot)
 {
     foreach (GroupAssoc groupAssoc in bot.groupAssocs)
     {
         if (groupAssoc.Id == group)
         {
             groupAssoc.Peer = peer;
             Bots.SaveBot(bot);
             return;
         }
     }
     bot.groupAssocs.Add(new GroupAssoc {
         Id = group, Peer = peer
     });
     Bots.SaveBot(bot);
     return;
 }
Exemplo n.º 6
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] Список ботов загружен");
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        //-----------------------------------------

        static void Main(string[] args)
        {
            //----Настройки окна------------
            Console.SetWindowSize(130, 10);
            Console.Title           = "VK Bot";
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.BackgroundColor = ConsoleColor.White;
            Console.Clear();
            //------------------------------

            Console.WriteLine(">> Начало работы...");
            Console.WriteLine("");
            Bots.CreateList();
            Console.WriteLine(" Загружено ботов: " + Bots.List.Count);
            Console.WriteLine(" Основной бот: " + Bots.List[0].Name);
            Token = Bots.List[0].Token;
            Groups.CreateList();
            Console.WriteLine(" Бесед загружено: " + Groups.List.Count);
            User.CreteList();
            Console.WriteLine(" Пользователей загружено: " + User.List.Count);
            Console.WriteLine("");

            try
            {
                dynamic getLongPollServer = JObject.Parse(new HttpRequest(Api).Post("messages.getLongPollServer?need_pts=1&lp_version=3&" + Token).ToString());

                server = getLongPollServer.response.server;
                key    = getLongPollServer.response.key;
                ts     = getLongPollServer.response.ts;
                Console.WriteLine("Данные получены");
            }
            catch
            {
                Console.WriteLine("Ошибка получения данных");
                Console.ReadLine();
                Environment.Exit(0);
            }

            Console.WriteLine("Сервер:" + server + "\nКлюч: " + key + "\nВременной штамп: " + ts);
            Console.WriteLine("========================================");
            Thread.Sleep(50);

            Thread CallBack = new Thread(Program.CallBack);

            CallBack.Start();
            Thread.Sleep(100);
            Thread MessageProcessing = new Thread(Processing.General);

            MessageProcessing.Start();
            Thread.Sleep(100);
            Thread EventProcessing = new Thread(Events.EventTimer);

            EventProcessing.Start();
            Thread.Sleep(100);

            Console.WriteLine("Консоль доступна");
            Console.WriteLine("");

            while (true)
            {
                string local_command = Console.ReadLine();
                switch (local_command)
                {
                case "stop":
                    CallBack.Abort();
                    MessageProcessing.Abort();
                    EventProcessing.Abort();
                    Environment.Exit(0);
                    break;

                case "json":
                    if (json_mode)
                    {
                        json_mode = false;
                        Console.WriteLine("Json режим деактивирован");
                    }
                    else
                    {
                        json_mode = true;
                        Console.WriteLine("Json режим активирован");
                    }
                    break;

                case "add user":
                    Console.Write("Name: ");
                    User.Add(User.List.Count + 1, Console.ReadLine());
                    break;

                case "user count":
                    Console.WriteLine("Пользователей зарегестрировано: " + User.List.Count);
                    break;

                case "stats":
                    Console.WriteLine("Сообщений на обработке: " + Messages.List.Count);
                    Console.WriteLine("Сообщений: " + Messages.MCount);
                    Console.WriteLine("Команд: " + Messages.CCount);
                    Console.WriteLine("Команд обработано: " + Messages.FCount);
                    break;
                }
            }
        }