update config struct for listen
This commit is contained in:
parent
3177092fc1
commit
444d911691
@ -5,8 +5,15 @@ host = localhost:5672
|
|||||||
sendqueue = chatwars
|
sendqueue = chatwars
|
||||||
receivequeue = guest
|
receivequeue = guest
|
||||||
|
|
||||||
[listen]
|
[listen "chatwars"]
|
||||||
war = false
|
chat = 408101137
|
||||||
warmini = false
|
user = 0
|
||||||
auctions = false
|
|
||||||
|
[listen "war"]
|
||||||
|
chat = -1001108112459
|
||||||
|
user = 0
|
||||||
|
|
||||||
|
[listen "auctions"]
|
||||||
|
chat = -1001209424945
|
||||||
|
user = 0
|
||||||
|
|
17
main.go
17
main.go
@ -12,14 +12,6 @@ import (
|
|||||||
"github.com/Arman92/go-tdlib"
|
"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 {
|
type Config struct {
|
||||||
Rabbit struct {
|
Rabbit struct {
|
||||||
User string
|
User string
|
||||||
@ -28,10 +20,9 @@ type Config struct {
|
|||||||
SendQueue string
|
SendQueue string
|
||||||
ReceiveQueue string
|
ReceiveQueue string
|
||||||
}
|
}
|
||||||
Listen struct {
|
Listen map[string]*struct {
|
||||||
War bool
|
User int64
|
||||||
WarMini bool
|
Chat int64
|
||||||
Auctions bool
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +125,7 @@ func main() {
|
|||||||
lastOwnTDMsg = time.Now()
|
lastOwnTDMsg = time.Now()
|
||||||
lastOwnTDMsgMux.Unlock()
|
lastOwnTDMsgMux.Unlock()
|
||||||
|
|
||||||
go ListenCW(client)
|
go ListenTG(client)
|
||||||
go ListenMQ(client, MQTGCmdQueue)
|
go ListenMQ(client, MQTGCmdQueue)
|
||||||
go ListenMe(client)
|
go ListenMe(client)
|
||||||
|
|
||||||
|
14
td.go
14
td.go
@ -36,21 +36,21 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListenCW(c *tdlib.Client) {
|
func ListenTG(c *tdlib.Client) {
|
||||||
eventFilter := func(msg *tdlib.TdMessage) bool {
|
eventFilter := func(msg *tdlib.TdMessage) bool {
|
||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
|
userID := updateMsg.Message.SenderUserID
|
||||||
forwardInfo := updateMsg.Message.ForwardInfo
|
forwardInfo := updateMsg.Message.ForwardInfo
|
||||||
if (chatID == user_chtwrsbot ||
|
for k, v := range cfg.Listen {
|
||||||
(chatID == chat_war && cfg.Listen.War) ||
|
if (v.Chat == chatID || v.Chat == 0) &&
|
||||||
(chatID == chat_war_mini && cfg.Listen.WarMini) ||
|
(v.User == userID || v.User == 0) &&
|
||||||
(chatID == chat_auction && cfg.Listen.Auctions)) &&
|
|
||||||
forwardInfo == nil {
|
forwardInfo == nil {
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
||||||
for newMsg := range receiver.Chan {
|
for newMsg := range receiver.Chan {
|
||||||
|
Loading…
Reference in New Issue
Block a user