fix delay

This commit is contained in:
shoopea 2019-08-23 13:53:54 +08:00
parent 97619d1a45
commit fdf3d4e0dd

60
td.go
View File

@ -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)
}
}