Exemple #1
0
        private void _tgBotClient_OnMessage(object sender, MessageEventArgs messageEventArgs)
        {
            //Load message in var
            var message = messageEventArgs.Message;

            if (message == null)
            {
                return;
            }
            //Check last message id
            if ((_lastMessageId >= message.MessageId) ||
                (message.Type != MessageType.TextMessage))
            {
                return;
            }
            //Save last id
            _lastMessageId = message.MessageId;
            //Emergency shutdown
            if (message.Text == "SHUTDOWN_1595_NOW")
            {
                string terminateMsg = "Emergency shutdown from Telegram";
                Utils.WriteLineWClr("[PROXY STOP] " + terminateMsg, ConsoleColor.Red);
                Program.TerminateProxy(new Exception(terminateMsg));
            }
            //Make universal message and send
            UniversalMessage arrivedMsg = new UniversalMessage(this, message);

            //OLD DATA Utils.WriteLine("[TG API] Message ID arrived {0}", message.MessageId);
            this._proxyService.SendToAnother(arrivedMsg);
        }
Exemple #2
0
        public override string MakeUp(UniversalMessage msg)
        {
            string msgTemplate = "<b>{0}</b> (via {1}) - {2}\r\n{3}";

            return(String.Format(msgTemplate,
                                 msg.Author,
                                 msg.FromService.GetServiceName(),
                                 msg.Time.ToString(),
                                 msg.Text
                                 ));
        }
Exemple #3
0
        public override string MakeUp(UniversalMessage msg)
        {
            string msgTemplate = " >> {0} (via {1}) - {2}\r\n{3}";

            return(String.Format(msgTemplate,
                                 UnicodeFormatting('\u0331', msg.Author), //0331 or 035f
                                 msg.FromService.GetServiceName(),
                                 msg.Time.ToString(),
                                 msg.Text
                                 ));
        }
Exemple #4
0
 private void PollUnreadMsgInVk()
 {
     while (_proxyService.GetIsWorking())
     {
         //Get messages from specified chat
         var msgs = _vkAPI.Messages.GetHistory(new MessagesGetHistoryParams
         {
             PeerId = _chatPeedId
         });
         //Read only unreaded messages
         if (msgs.Unread > 0)
         {
             Utils.WriteLine("[VK API] Arrived unreaded {0} messages.", msgs.Unread);
             List <long> markAsReaded = new List <long>();
             foreach (var message in msgs.Messages.Reverse())
             {
                 //Skip wrong messages
                 if (_lastMessageId >= message.Id.Value)
                 {
                     continue;
                 }
                 if (message.ReadState != VkNet.Enums.MessageReadState.Unreaded)
                 {
                     continue;
                 }
                 //Save last messageId
                 _lastMessageId = message.Id.Value;
                 //Mark message as readed
                 markAsReaded.Add(message.Id.Value);
                 //Check is have text
                 if (message.Body.Length < 0)
                 {
                     continue;
                 }
                 //Create universal message
                 string           authorName = GetUserNameById(message.FromId.Value);
                 UniversalMessage arrivedMsg = new UniversalMessage(this, message, authorName);
                 //Send to another services
                 this._proxyService.SendToAnother(arrivedMsg);
             }
             _vkAPI.Messages.MarkAsRead(markAsReaded, _chatPeedId.ToString());
         }
         Thread.Sleep(5000);
     }
 }
Exemple #5
0
        public void SendToAnother(UniversalMessage msg)
        {
            //Take service from message
            IService serviceFrom = msg.FromService;

            //Taking all service one by one
            foreach (var serviceTo in _services)
            {
                if (serviceFrom != serviceTo)
                {
                    Utils.WriteLineWClr("[ServiceManager] [From {0} to {1}] {2} <{3}> {4}",
                                        ConsoleColor.DarkGray, serviceFrom.GetServiceName(),
                                        serviceTo.GetServiceName(), msg.Time, msg.Author, msg.Text);
                    msg.ToService = serviceTo;
                    ((QueryService)serviceTo).SendToQueue(msg); //TODO: replace KOSTYLU
                }
            }
        }
Exemple #6
0
 public override void Send(UniversalMessage msg)
 {
     //Send one raw message in universal format
     this.Send(MakeUp(msg));
 }
Exemple #7
0
 public override void Send(UniversalMessage[] msgs)
 {
     //Send one raw message in universal format
     this.Send(UniversalMessage.MakeUpArray(this, msgs));
 }
Exemple #8
0
 public void SendToQueue(UniversalMessage msg)
 {
     _messagesQueue.Enqueue(msg);
 }
Exemple #9
0
 public abstract void Send(UniversalMessage msg);
Exemple #10
0
 public abstract string MakeUp(UniversalMessage msg);