2022-09-10 17:15:32 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cwtch.im/cwtch/event"
|
|
|
|
"git.openprivacy.ca/openprivacy/log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const antispamTickTime = 30 * time.Second
|
|
|
|
|
|
|
|
type antispam struct {
|
|
|
|
bus event.Manager
|
|
|
|
queue event.Queue
|
|
|
|
breakChan chan bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *antispam) Start() {
|
|
|
|
go a.run()
|
|
|
|
}
|
|
|
|
|
2023-04-17 19:05:02 +00:00
|
|
|
func (a *antispam) Id() PluginID {
|
2022-12-03 00:23:11 +00:00
|
|
|
return ANTISPAM
|
|
|
|
}
|
|
|
|
|
2023-04-17 19:05:02 +00:00
|
|
|
func (a *antispam) Shutdown() {
|
2022-09-10 17:15:32 +00:00
|
|
|
a.breakChan <- true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *antispam) run() {
|
2023-01-25 20:32:26 +00:00
|
|
|
log.Debugf("running antispam trigger plugin")
|
2022-09-10 17:15:32 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-time.After(antispamTickTime):
|
|
|
|
// no fuss, just trigger the check. Downstream will filter out superfluous actions
|
|
|
|
a.bus.Publish(event.NewEvent(event.TriggerAntispamCheck, map[event.Field]string{}))
|
|
|
|
continue
|
|
|
|
case <-a.breakChan:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAntiSpam returns a Plugin that when started will trigger antispam payments on a regular interval
|
|
|
|
func NewAntiSpam(bus event.Manager) Plugin {
|
|
|
|
cr := &antispam{bus: bus, queue: event.NewQueue(), breakChan: make(chan bool, 1)}
|
|
|
|
return cr
|
|
|
|
}
|