fix delay
This commit is contained in:
parent
97619d1a45
commit
fdf3d4e0dd
62
td.go
62
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user