test delayed msg
This commit is contained in:
parent
5768855528
commit
97619d1a45
1
def.go
1
def.go
@ -16,6 +16,7 @@ type TGCommand struct {
|
||||
Text string `json:"text"`
|
||||
Document tb.Document `json:"document"`
|
||||
ParseMode int64 `json:"parse_mode"`
|
||||
Delay int64 `json:"delay"`
|
||||
}
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
|
65
td.go
65
td.go
@ -37,35 +37,7 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) {
|
||||
}
|
||||
b, _ := json.Marshal(m)
|
||||
log.Printf("****************************** New MQ command ******************************\n%s\n****************************************************************************\n", string(b))
|
||||
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)
|
||||
}
|
||||
go clientMsg(c, m)
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,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) ||
|
||||
@ -250,3 +222,36 @@ func OwnUserID(c *tdlib.Client) int32 {
|
||||
user, _ := c.GetMe()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user