mirror of https://github.com/velour/catbase.git
first/last: filter channels
This commit is contained in:
parent
9585ac6c23
commit
da69df36d4
|
@ -211,7 +211,7 @@ func (p *FirstPlugin) register() {
|
|||
{Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
Handler: func(r bot.Request) bool {
|
||||
if r.Msg.IsIM || !p.enabled {
|
||||
if r.Msg.IsIM || !p.enabled || !p.enabled_channel(r) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -243,6 +243,16 @@ func (p *FirstPlugin) register() {
|
|||
p.bot.RegisterTable(p, p.handlers)
|
||||
}
|
||||
|
||||
func (p *FirstPlugin) enabled_channel(r bot.Request) bool {
|
||||
chs := p.config.GetArray("first.channels", []string{})
|
||||
for _, ch := range chs {
|
||||
if r.Msg.Channel == ch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *FirstPlugin) allowed(message msg.Message) bool {
|
||||
if message.Body == "" {
|
||||
return false
|
||||
|
|
|
@ -81,6 +81,16 @@ func (p *LastPlugin) register() {
|
|||
p.b.RegisterTable(p, p.handlers)
|
||||
}
|
||||
|
||||
func (p *LastPlugin) enabled_channel(r bot.Request) bool {
|
||||
chs := p.c.GetArray("last.channels", []string{})
|
||||
for _, ch := range chs {
|
||||
if r.Msg.Channel == ch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func nextNoon(t time.Time) time.Duration {
|
||||
day := first.Midnight(t)
|
||||
nextNoon := day.Add(12 * time.Hour)
|
||||
|
@ -97,6 +107,9 @@ func nextNoon(t time.Time) time.Duration {
|
|||
}
|
||||
|
||||
func (p *LastPlugin) recordLast(r bot.Request) bool {
|
||||
if !p.enabled_channel(r) {
|
||||
return false
|
||||
}
|
||||
ch := r.Msg.Channel
|
||||
who := r.Msg.User.Name
|
||||
day := first.Midnight(time.Now())
|
||||
|
|
Loading…
Reference in New Issue