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 } } }