test
This commit is contained in:
parent
27dba642f7
commit
5125130724
@ -4,3 +4,9 @@ password = guest
|
||||
host = localhost:5672
|
||||
sendqueue = chatwars
|
||||
receivequeue = guest
|
||||
|
||||
[listen]
|
||||
war = false
|
||||
warmini = false
|
||||
auctions = false
|
||||
|
11
main.go
11
main.go
@ -54,6 +54,11 @@ type Config struct {
|
||||
SendQueue string
|
||||
ReceiveQueue string
|
||||
}
|
||||
Listen struct {
|
||||
War bool
|
||||
WarMini bool
|
||||
Auctions bool
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
@ -66,6 +71,7 @@ var (
|
||||
|
||||
ownUserID64 = int64(0)
|
||||
ownUserID32 = int32(0)
|
||||
lastOwnTDMsg = time.Time
|
||||
MQCWMsgQueue chan ChatWarsMessage
|
||||
MQCWCmdQueue chan ChatWarsCommand
|
||||
)
|
||||
@ -150,7 +156,12 @@ func main() {
|
||||
go MQReceiveMsgWorker(w, MQCWCmdQueue)
|
||||
}
|
||||
|
||||
lastOwnTDMsg = time.Now()
|
||||
|
||||
go ListenCW(client)
|
||||
go ListenMQ(client, MQCWCmdQueue)
|
||||
go ListenMe(client)
|
||||
|
||||
fmt.Println("Started !")
|
||||
|
||||
// Main loop
|
||||
|
35
td.go
35
td.go
@ -14,13 +14,46 @@ func ListenCW(c *tdlib.Client) {
|
||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||
chatID := updateMsg.Message.ChatID
|
||||
forwardInfo := updateMsg.Message.ForwardInfo
|
||||
if (chatID == user_chtwrsbot || chatID == chat_war || chatID == chat_war_mini || chatID == chat_auction) && forwardInfo == nil {
|
||||
if (chatID == user_chtwrsbot ||
|
||||
(chatID == chat_war && cfg.Listen.War) ||
|
||||
(chatID == chat_war_mini && cfg.Listen.WarMini) ||
|
||||
(chatID == chat_auction && cfg.Listen.Auctions)) &&
|
||||
forwardInfo == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
||||
for newMsg := range receiver.Chan {
|
||||
lastOwnTDMsg = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func ListenMQ(c *tdlib.Client, msgs <-chan ChatWarsCommand) {
|
||||
for m := range msgs {
|
||||
for now := time.Now(); lastOwnTDMsg.Add(time.Second) > now; {
|
||||
log.Printf("ListenMQ : channel busy, waiting before acting...\n")
|
||||
time.Sleep(time.Until(lastOwnTDMsg.Add(time.Second)))
|
||||
now = time.Now()
|
||||
}
|
||||
log.Printf("ListenMQ : Consuming msg\n")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func ListenMe(c *tdlib.Client) {
|
||||
eventFilter := func(msg *tdlib.TdMessage) bool {
|
||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||
senderUserID := updateMsg.Message.SenderUserID
|
||||
if senderUserID == ownUserID32 {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
||||
for newMsg := range receiver.Chan {
|
||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||
|
Loading…
Reference in New Issue
Block a user