update config struct for listen

This commit is contained in:
shoopea 2019-10-12 13:26:11 +08:00
parent 3177092fc1
commit 444d911691
3 changed files with 24 additions and 26 deletions

View File

@ -5,8 +5,15 @@ host = localhost:5672
sendqueue = chatwars
receivequeue = guest
[listen]
war = false
warmini = false
auctions = false
[listen "chatwars"]
chat = 408101137
user = 0
[listen "war"]
chat = -1001108112459
user = 0
[listen "auctions"]
chat = -1001209424945
user = 0

17
main.go
View File

@ -12,14 +12,6 @@ import (
"github.com/Arman92/go-tdlib"
)
const (
user_chtwrsbot = 408101137
chat_darkwing = -1001080526540
chat_war = -1001108112459
chat_war_mini = -1001277259728
chat_auction = -1001209424945
)
type Config struct {
Rabbit struct {
User string
@ -28,10 +20,9 @@ type Config struct {
SendQueue string
ReceiveQueue string
}
Listen struct {
War bool
WarMini bool
Auctions bool
Listen map[string]*struct {
User int64
Chat int64
}
}
@ -134,7 +125,7 @@ func main() {
lastOwnTDMsg = time.Now()
lastOwnTDMsgMux.Unlock()
go ListenCW(client)
go ListenTG(client)
go ListenMQ(client, MQTGCmdQueue)
go ListenMe(client)

18
td.go
View File

@ -36,20 +36,20 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) {
}
}
func ListenCW(c *tdlib.Client) {
func ListenTG(c *tdlib.Client) {
eventFilter := func(msg *tdlib.TdMessage) bool {
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
chatID := updateMsg.Message.ChatID
userID := updateMsg.Message.SenderUserID
forwardInfo := updateMsg.Message.ForwardInfo
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
} else {
return false
for k, v := range cfg.Listen {
if (v.Chat == chatID || v.Chat == 0) &&
(v.User == userID || v.User == 0) &&
forwardInfo == nil {
return true
}
}
return false
}
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)