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); }
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 )); }
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 )); }
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); } }
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 } } }
public override void Send(UniversalMessage msg) { //Send one raw message in universal format this.Send(MakeUp(msg)); }
public override void Send(UniversalMessage[] msgs) { //Send one raw message in universal format this.Send(UniversalMessage.MakeUpArray(this, msgs)); }
public void SendToQueue(UniversalMessage msg) { _messagesQueue.Enqueue(msg); }
public abstract void Send(UniversalMessage msg);
public abstract string MakeUp(UniversalMessage msg);