diff --git a/def.go b/def.go index 9f6c231..387a997 100644 --- a/def.go +++ b/def.go @@ -16,6 +16,7 @@ type TGCommand struct { Text string `json:"text"` Document tb.Document `json:"document"` ParseMode int64 `json:"parse_mode"` + Delay int64 `json:"delay"` } type ChatWarsMessage struct { diff --git a/td.go b/td.go index 30f6b02..8018bbb 100644 --- a/td.go +++ b/td.go @@ -37,35 +37,7 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) { } b, _ := json.Marshal(m) log.Printf("****************************** New MQ command ******************************\n%s\n****************************************************************************\n", string(b)) - switch m.Type { - case commandSendMsg: - msgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(m.Text, nil), true, true) - if m.ToChatID64 != 0 { - c.SendMessage(m.ToChatID64, 0, false, false, nil, msgTxt) - } else if m.ToUserID64 != 0 { - c.SendMessage(m.ToUserID64, 0, false, false, nil, msgTxt) - } - case commandRefreshMsg: - u, err := c.GetMessage(m.FromChatID64, m.FromMsgID64) - logOnError(err, "ListenMQ : commandRefreshMsg") - if err == nil && u.Content.GetMessageContentEnum() == tdlib.MessageTextType { - txt := u.Content.(*tdlib.MessageText).Text.Text - - r := ChatWarsMessage{ - TGUserID64: ownUserID64, - TGSenderUserID64: int64(u.SenderUserID), - ID64: u.ID, - ChatID64: u.ChatID, - Text: txt, - } - - r.Date = time.Unix(int64(u.Date), 0) - - MQCWMsgQueue <- r - } - default: - log.Printf("ListenMQ : No handler for command %d.\n", m.Type) - } + go clientMsg(c, m) } } @@ -73,7 +45,7 @@ func ListenCW(c *tdlib.Client) { eventFilter := func(msg *tdlib.TdMessage) bool { updateMsg := (*msg).(*tdlib.UpdateNewMessage) chatID := updateMsg.Message.ChatID - forwardInfo := updateMsg.Message.ForwardInfo + forwardInfo := updateMsg.Message.ForwardInfo if (chatID == user_chtwrsbot || (chatID == chat_war && cfg.Listen.War) || (chatID == chat_war_mini && cfg.Listen.WarMini) || @@ -250,3 +222,36 @@ func OwnUserID(c *tdlib.Client) int32 { user, _ := c.GetMe() return user.ID } + +func clientMsg(c *tdlib.Client, m TGCommand) { + switch m.Type { + case commandSendMsg: + msgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(m.Text, nil), true, true) + if m.ToChatID64 != 0 { + c.SendMessage(m.ToChatID64, 0, false, false, nil, msgTxt) + } else if m.ToUserID64 != 0 { + c.SendMessage(m.ToUserID64, 0, false, false, nil, msgTxt) + } + case commandRefreshMsg: + u, err := c.GetMessage(m.FromChatID64, m.FromMsgID64) + logOnError(err, "ListenMQ : commandRefreshMsg") + if err == nil && u.Content.GetMessageContentEnum() == tdlib.MessageTextType { + txt := u.Content.(*tdlib.MessageText).Text.Text + + r := ChatWarsMessage{ + TGUserID64: ownUserID64, + TGSenderUserID64: int64(u.SenderUserID), + ID64: u.ID, + ChatID64: u.ChatID, + Text: txt, + } + + r.Date = time.Unix(int64(u.Date), 0) + + MQCWMsgQueue <- r + } + default: + log.Printf("ListenMQ : No handler for command %d.\n", m.Type) + } +} +}