From ecaaf30c610ed53f42a164355e6ae1dbef9546a9 Mon Sep 17 00:00:00 2001 From: shoopea Date: Wed, 15 May 2019 14:43:17 +0800 Subject: [PATCH] test --- def.go | 27 +++++++++++++++++++++++++++ main.go | 27 --------------------------- mq.go | 2 +- td.go | 10 +++++++++- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/def.go b/def.go index 06ab7d0..4732754 100644 --- a/def.go +++ b/def.go @@ -1 +1,28 @@ package main + +type ChatWarsMessage struct { + UserID64 int64 `json:"user_id"` + SenderUserID64 int64 `json:"sender_user_id"` + Date time.Time `json:"date"` + ID64 int64 `json:"id"` + ChatID64 int64 `json:"chat_id"` + Text string `json:"text"` +} + +type ChatWarsCommand struct { + Type int64 `json:"type"` + FromChatID64 int64 `json:"from_chat_id"` + FromUserID64 int64 `json:"from_user_id"` + FromMsgID64 int64 `json:"from_msg_id"` + ToChatID64 int64 `json:"to_chat_id"` + ToUserID64 int64 `json:"to_user_id"` + Text int64 `json:"text"` +} + +const ( + commandForwardMsg = 1 + commandReplyMsg = 2 + commandSendMsg = 3 + commandDeleteMsg = 4 + commandRefreshMsg = 5 +) diff --git a/main.go b/main.go index 5ed0485..5579a7e 100644 --- a/main.go +++ b/main.go @@ -11,33 +11,6 @@ import ( "github.com/Arman92/go-tdlib" ) -type ChatWarsMessage struct { - UserID64 int64 `json:"user_id"` - SenderUserID64 int64 `json:"sender_user_id"` - Date time.Time `json:"date"` - ID64 int64 `json:"id"` - ChatID64 int64 `json:"chat_id"` - Text string `json:"text"` -} - -type ChatWarsCommand struct { - Type int64 `json:"type"` - FromChatID64 int64 `json:"from_chat_id"` - FromUserID64 int64 `json:"from_user_id"` - FromMsgID64 int64 `json:"from_msg_id"` - ToChatID64 int64 `json:"to_chat_id"` - ToUserID64 int64 `json:"to_user_id"` - Text int64 `json:"text"` -} - -const ( - commandForwardMsg = 1 - commandReplyMsg = 2 - commandSendMsg = 3 - commandDeleteMsg = 4 - commandRefreshMsg = 5 -) - const ( user_chtwrsbot = 408101137 chat_darkwing = -1001080526540 diff --git a/mq.go b/mq.go index c4fdcb2..932f223 100644 --- a/mq.go +++ b/mq.go @@ -83,7 +83,7 @@ func MQReceiveMsgWorker(id int, cmd chan<- ChatWarsCommand) { failOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Failed to declare a consumer") for d := range m { - log.Printf("MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Received a message: %s", string(d.Body)) + //log.Printf("MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Received a message:\n %s", string(d.Body)) err = json.Unmarshal(d.Body, &c) logOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Can't unmarshal.\n"+string(d.Body)) if err == nil { diff --git a/td.go b/td.go index f7cf7a8..d4c3bb2 100644 --- a/td.go +++ b/td.go @@ -34,7 +34,15 @@ func ListenMQ(c *tdlib.Client, msgs <-chan ChatWarsCommand) { time.Sleep(time.Until(lastOwnTDMsg.Add(time.Second))) now = time.Now() } - log.Printf("ListenMQ : Consuming msg %d\n", m.Type) + 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) + } + } } }