Example #1
0
        //После успешной отправки возвращает true
        private static bool SendMessage(string message, long?userID, VkNet.Model.Keyboard.MessageKeyboard keyboard, string payload)
        {
            bool isSended;

            try
            {
                api.Authorize(new ApiAuthParams()
                {
                    AccessToken = LPListener.groupToken
                });
                Random rnd = new Random();

                //One of the parameters specified was missing or invalid: you should specify peer_id, user_id, domain, chat_id or user_ids param
                api.Messages.Send(new MessagesSendParams
                {
                    RandomId = rnd.Next(),
                    UserId   = userID,
                    Message  = message,

                    Payload = payload,
                });
                isSended = true;
            }
            catch (Exception ex)
            {
                LPListener.ErrorLogging(ex);
                LPListener.ReadError();
                isSended = false;
            }
            return(isSended);
        }
Example #2
0
        public void VKScheduler()
        {
            //LPListener lpl = new LPListener();
            key_linked.AddButton("Удалить привязку", null, LPListener.decine);
            MessageKeyboard keyboard_linked = key_linked.Build();

            //Очищать очередь сообщений - отправлять в ВК
            while (true)
            {
                try
                {
                    if (chatMessages.Count > 0)

                    {
                        //Берем элемент в начале очереди
                        VKparams el     = chatMessages.Peek();
                        string   msg    = el.messageToSend;
                        long?    vkid   = el.vkID;
                        bool     sended = false;
                        if (msg != null && vkid != null)
                        {
                            sended = SendMessage(msg, vkid, keyboard_linked, null);
                        }

                        if (sended == true)
                        {
                            el = chatMessages.Dequeue();
                        }

                        Thread.Sleep(delay * 1000);
                    }
                }
                catch (Exception ex)
                {
                    LPListener.ErrorLogging(ex);
                    LPListener.ReadError();
                }
            }
        }
Example #3
0
        public void TCPServerStart()
        {
            string message;

            TcpListener server = null;

            try
            {
                IPAddress localAddr = IPAddress.Parse("127.0.0.1");
                server = new TcpListener(localAddr, port);

                // запуск слушателя
                server.Start();

                // Buffer for reading data
                Byte[] bytes = new Byte[256];
                String data  = null;

                while (true)
                {
                    Console.WriteLine("Ожидание подключений... ");

                    // получаем входящее подключение
                    TcpClient client = server.AcceptTcpClient();
                    Console.WriteLine("Подключен клиент. Выполнение запроса...");
                    // получаем сетевой поток для чтения и записи
                    NetworkStream stream = client.GetStream();

                    //Не читается сообщение
                    int i;
                    data = null;

                    // Loop to receive all the data sent by the client.
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        // Translate data bytes to a ASCII string.
                        data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
                        Console.WriteLine("Received: {0}", data);

                        List <long?> idList = MySQLClass.GetVKID();

                        //Read messages from PLUGIN CHAT -> Send TO BOT Community VK
                        foreach (long?id in idList)
                        {
                            LPListener.SendMessage(data, id);

                            Thread.Sleep(delay * 1000);
                        }
                    }

                    // получаем сообщение
                    StringBuilder builder = new StringBuilder();
                    //
                    Thread.Sleep(delay * 1000);
                    // закрываем поток

                    client.Close();
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }
            finally
            {
            }
        }