test delayed msg

This commit is contained in:
shoopea 2019-08-23 13:50:58 +08:00
parent 5768855528
commit 97619d1a45
2 changed files with 36 additions and 30 deletions

1
def.go
View File

@ -16,6 +16,7 @@ type TGCommand struct {
Text string `json:"text"` Text string `json:"text"`
Document tb.Document `json:"document"` Document tb.Document `json:"document"`
ParseMode int64 `json:"parse_mode"` ParseMode int64 `json:"parse_mode"`
Delay int64 `json:"delay"`
} }
type ChatWarsMessage struct { type ChatWarsMessage struct {

63
td.go
View File

@ -37,35 +37,7 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) {
} }
b, _ := json.Marshal(m) b, _ := json.Marshal(m)
log.Printf("****************************** New MQ command ******************************\n%s\n****************************************************************************\n", string(b)) log.Printf("****************************** New MQ command ******************************\n%s\n****************************************************************************\n", string(b))
switch m.Type { go clientMsg(c, m)
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)
}
} }
} }
@ -250,3 +222,36 @@ func OwnUserID(c *tdlib.Client) int32 {
user, _ := c.GetMe() user, _ := c.GetMe()
return user.ID 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)
}
}
}