From fdf3d4e0dd50d39c14f07018dc19a6c15aa37c27 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 23 Aug 2019 13:53:54 +0800 Subject: [PATCH] fix delay --- td.go | 62 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/td.go b/td.go index 8018bbb..0146d48 100644 --- a/td.go +++ b/td.go @@ -45,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) || @@ -224,34 +224,36 @@ func OwnUserID(c *tdlib.Client) int32 { } 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) + if m.Delay != 0 { + time.Sleep(time.Duration(m.Delay * time.Second)) + } + 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) + } }