test
This commit is contained in:
parent
eb95205bd9
commit
ecaaf30c61
27
def.go
27
def.go
@ -1 +1,28 @@
|
|||||||
package main
|
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
|
||||||
|
)
|
||||||
|
27
main.go
27
main.go
@ -11,33 +11,6 @@ import (
|
|||||||
"github.com/Arman92/go-tdlib"
|
"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 (
|
const (
|
||||||
user_chtwrsbot = 408101137
|
user_chtwrsbot = 408101137
|
||||||
chat_darkwing = -1001080526540
|
chat_darkwing = -1001080526540
|
||||||
|
2
mq.go
2
mq.go
@ -83,7 +83,7 @@ func MQReceiveMsgWorker(id int, cmd chan<- ChatWarsCommand) {
|
|||||||
failOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Failed to declare a consumer")
|
failOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Failed to declare a consumer")
|
||||||
|
|
||||||
for d := range m {
|
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)
|
err = json.Unmarshal(d.Body, &c)
|
||||||
logOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Can't unmarshal.\n"+string(d.Body))
|
logOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Can't unmarshal.\n"+string(d.Body))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
10
td.go
10
td.go
@ -34,7 +34,15 @@ func ListenMQ(c *tdlib.Client, msgs <-chan ChatWarsCommand) {
|
|||||||
time.Sleep(time.Until(lastOwnTDMsg.Add(time.Second)))
|
time.Sleep(time.Until(lastOwnTDMsg.Add(time.Second)))
|
||||||
now = time.Now()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user