You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

package main
import (
"fmt"
"github.com/kf5grd/keybasebot"
"samhofi.us/x/keybase/v2"
"samhofi.us/x/keybase/v2/types/chat1"
)
func nsfwFilter() keybasebot.Adapter {
return func(action keybasebot.BotAction) keybasebot.BotAction {
return func(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
// if its not a team, nsfw is always allowed
if m.Channel.MembersType == keybase.USER {
b.Logger.Debug("boobs are allowed in %s", m.Channel.Name)
return action(m, b)
}
// if the team is in the allowed list, nsfw is allowed
if m.Channel.MembersType == keybase.TEAM {
data, ok := b.Meta["nsfwAllowed"]
if !ok {
err := fmt.Errorf("Unable to fetch allowed teams from meta")
return false, err
}
allowedTeams := data.(map[chat1.ConvIDStr]bool)
if isAllowed := allowedTeams[m.ConvID]; isAllowed {
return action(m, b)
}
}
// if the team is not allowed, fail silently
b.Logger.Debug("boobs are not allowed in %s", m.Channel.Name)
return true, nil
}
}
}
func requireOwner() keybasebot.Adapter {
return func(action keybasebot.BotAction) keybasebot.BotAction {
return func(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
b.Logger.Debug("checking owner command auth")
// if the team is in the allowed list, nsfw is allowed
data, ok := b.Meta["owner"]
if !ok {
b.Logger.Debug("unable to fetch owner from meta")
err := fmt.Errorf("owner command used without owner set")
return false, err
}
myOwner := data.(string)
if m.Sender.Username == myOwner {
b.Logger.Debug("owner command approved")
return action(m, b)
}
// if the team is not allowed, fail silently
b.Logger.Info("@%s tried to user owner command without auth.", m.Sender.Username)
return true, nil
}
}
}