fix delay

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

62
td.go
View File

@ -45,7 +45,7 @@ func ListenCW(c *tdlib.Client) {
eventFilter := func(msg *tdlib.TdMessage) bool { eventFilter := func(msg *tdlib.TdMessage) bool {
updateMsg := (*msg).(*tdlib.UpdateNewMessage) updateMsg := (*msg).(*tdlib.UpdateNewMessage)
chatID := updateMsg.Message.ChatID chatID := updateMsg.Message.ChatID
forwardInfo := updateMsg.Message.ForwardInfo forwardInfo := updateMsg.Message.ForwardInfo
if (chatID == user_chtwrsbot || if (chatID == user_chtwrsbot ||
(chatID == chat_war && cfg.Listen.War) || (chatID == chat_war && cfg.Listen.War) ||
(chatID == chat_war_mini && cfg.Listen.WarMini) || (chatID == chat_war_mini && cfg.Listen.WarMini) ||
@ -224,34 +224,36 @@ func OwnUserID(c *tdlib.Client) int32 {
} }
func clientMsg(c *tdlib.Client, m TGCommand) { func clientMsg(c *tdlib.Client, m TGCommand) {
switch m.Type { if m.Delay != 0 {
case commandSendMsg: time.Sleep(time.Duration(m.Delay * time.Second))
msgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(m.Text, nil), true, true) }
if m.ToChatID64 != 0 { switch m.Type {
c.SendMessage(m.ToChatID64, 0, false, false, nil, msgTxt) case commandSendMsg:
} else if m.ToUserID64 != 0 { msgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(m.Text, nil), true, true)
c.SendMessage(m.ToUserID64, 0, false, false, nil, msgTxt) if m.ToChatID64 != 0 {
} c.SendMessage(m.ToChatID64, 0, false, false, nil, msgTxt)
case commandRefreshMsg: } else if m.ToUserID64 != 0 {
u, err := c.GetMessage(m.FromChatID64, m.FromMsgID64) c.SendMessage(m.ToUserID64, 0, false, false, nil, msgTxt)
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)
} }
} 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)
}
} }