- Introduce Discord adapter in the robot lifecycle to enable integration with Discord events. - Update the integration dispatcher to recognize and handle events from Discord. - Modify the configuration structure to include settings for Discord integration. - Enhance the integration parsing logic to support Discord configurations.
44 lines
742 B
Go
44 lines
742 B
Go
package discord
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
dedupTTL = 24 * time.Hour
|
|
dedupCleanInterval = time.Hour
|
|
)
|
|
|
|
type dedupStore struct {
|
|
m sync.Map
|
|
}
|
|
|
|
func newDedupStore() *dedupStore {
|
|
return &dedupStore{}
|
|
}
|
|
|
|
func (d *dedupStore) markSeen(key string) bool {
|
|
now := time.Now().Unix()
|
|
_, loaded := d.m.LoadOrStore(key, now)
|
|
return !loaded
|
|
}
|
|
|
|
func (d *dedupStore) cleaner(stopCh <-chan struct{}) {
|
|
ticker := time.NewTicker(dedupCleanInterval)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-stopCh:
|
|
return
|
|
case <-ticker.C:
|
|
cutoff := time.Now().Add(-dedupTTL).Unix()
|
|
d.m.Range(func(key, value any) bool {
|
|
if ts, ok := value.(int64); ok && ts < cutoff {
|
|
d.m.Delete(key)
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
}
|
|
}
|