try using locks for not spamming live message
This commit is contained in:
parent
f9dbd2a6a6
commit
02fc3d217d
15
main.go
15
main.go
@ -34,12 +34,15 @@ var (
|
|||||||
|
|
||||||
cfg Config
|
cfg Config
|
||||||
|
|
||||||
ownUserID64 = int64(0)
|
ownUserID64 = int64(0)
|
||||||
ownUserID32 = int32(0)
|
ownUserID32 = int32(0)
|
||||||
lastOwnTDMsg time.Time
|
lastOwnTDMsg time.Time
|
||||||
lastOwnTDMsgMux sync.Mutex
|
lastOwnTDMsgMux sync.Mutex
|
||||||
MQCWMsgQueue chan ChatWarsMessage
|
lastChatTDMsg map[uint64]time.Time
|
||||||
MQTGCmdQueue chan TGCommand
|
lastChatTDMsgMux map[uint64]sync.Mutex
|
||||||
|
lastChatMsgMux sync.RWMutex
|
||||||
|
MQCWMsgQueue chan ChatWarsMessage
|
||||||
|
MQTGCmdQueue chan TGCommand
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
22
td.go
22
td.go
@ -69,6 +69,28 @@ func ListenTG(c *tdlib.Client) {
|
|||||||
|
|
||||||
m.Date = time.Unix(int64(updateMsg.Message.Date), 0)
|
m.Date = time.Unix(int64(updateMsg.Message.Date), 0)
|
||||||
|
|
||||||
|
lastChatMsgMux.RLock()
|
||||||
|
if _, ok := lastChatTDMsg[m.ChatID64]; !ok {
|
||||||
|
lastChatMsgMux.RUnlock()
|
||||||
|
lastChatMsgMux.Lock()
|
||||||
|
if _, ok := lastChatTDMsg[m.ChatID64]; !ok {
|
||||||
|
lastChatTDMsg[m.ChatID64] = time.Now().Add(-1 * time.Second)
|
||||||
|
lastChatTDMsgMux[m.ChatID64] = new(sync.Mutex)
|
||||||
|
}
|
||||||
|
lastChatMsgMux.Unlock()
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
lastChatTDMsgMux[m.ChatID64].Lock()
|
||||||
|
now := time.Now()
|
||||||
|
if lastChatTDMsg[m.ChatID64].Add(time.Second).Before(now) {
|
||||||
|
lastChatTDMsg[m.ChatID64] = now
|
||||||
|
lastChatTDMsgMux[m.ChatID64].Unlock()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lastChatTDMsgMux[m.ChatID64].Unlock()
|
||||||
|
time.Sleep(time.Until(now.Add(time.Second)))
|
||||||
|
}
|
||||||
|
|
||||||
MQCWMsgQueue <- m
|
MQCWMsgQueue <- m
|
||||||
|
|
||||||
fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
|
fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
|
||||||
|
Loading…
Reference in New Issue
Block a user