7 changed files with 244 additions and 3 deletions
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
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 |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
package cmd |
||||
|
||||
import ( |
||||
"os" |
||||
|
||||
"github.com/kf5grd/keybasebot" |
||||
"github.com/teris-io/shortid" |
||||
"samhofi.us/x/keybase/v2/types/chat1" |
||||
) |
||||
|
||||
/*var BoobsAd = chat1.UserBotCommandInput{ |
||||
Name: "eyebleach", |
||||
Usage: "", |
||||
Description: "Sends some cute critters", |
||||
}*/ |
||||
|
||||
func Boobs(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) { |
||||
path, desc, err := getRandomRedditMedia(b, "boobs", "top", 100) |
||||
if err != nil { |
||||
eid := shortid.MustGenerate() |
||||
b.Logger.Error("%s: %+v", eid, err) |
||||
b.KB.ReactByConvID(m.ConvID, m.Id, "Error: %s", eid) |
||||
return true, nil |
||||
} |
||||
// upload the image
|
||||
b.KB.UploadToConversation(m.ConvID, desc, path) |
||||
// delete the file
|
||||
err = os.Remove(path) |
||||
if err != nil { |
||||
b.Logger.Error("Unable to remove file %s", path) |
||||
} |
||||
return true, nil |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/kf5grd/keybasebot" |
||||
"github.com/kf5grd/keybasebot/pkg/kvstore" |
||||
"samhofi.us/x/keybase/v2/types/chat1" |
||||
) |
||||
|
||||
func setNsfw(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) { |
||||
b.KB.SendMessageByConvID(m.ConvID, "Pong!") |
||||
b.Logger.Info("owner command in convid %s", m.ConvID) |
||||
return true, nil |
||||
} |
||||
|
||||
func addNsfwTeam(b *keybasebot.Bot, c chat1.ConvIDStr) bool { |
||||
allowedTeams := make(map[chat1.ConvIDStr]bool) |
||||
// get the allowed teams
|
||||
data, ok := b.Meta["nsfwAllowed"] |
||||
if !ok { |
||||
// the key doesn't exist yet so go ahead and create it
|
||||
allowedTeams[c] = true |
||||
} else { |
||||
// the key exists and needs to be updated
|
||||
allowedTeams := data.(map[chat1.ConvIDStr]bool) |
||||
allowedTeams[c] = true |
||||
} |
||||
// write the key to meta
|
||||
b.Meta["nsfwAllowed"] = allowedTeams |
||||
// write the key to kvStore if enabled
|
||||
data, ok = b.Meta["kvstore"] |
||||
if ok { |
||||
team := data.(string) |
||||
kvKey := kvstore.New("nsfwAllowed", allowedTeams, -1) |
||||
err := kvstore.Put(b.KB, team, "ssh0le", kvKey) |
||||
if err != nil { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
||||
|
||||
func delNsfwTeam(b *keybasebot.Bot, c chat1.ConvIDStr) bool { |
||||
allowedTeams := make(map[chat1.ConvIDStr]bool) |
||||
// get the allowed teams
|
||||
data, ok := b.Meta["nsfwAllowed"] |
||||
if !ok { |
||||
// the key doesn't exist yet so go return
|
||||
return true |
||||
} else { |
||||
// the key exists and needs to be updated
|
||||
allowedTeams := data.(map[chat1.ConvIDStr]bool) |
||||
delete(allowedTeams, c) |
||||
} |
||||
// write the key to meta
|
||||
b.Meta["nsfwAllowed"] = allowedTeams |
||||
// write the key to kvStore if enabled
|
||||
data, ok = b.Meta["kvstore"] |
||||
if ok { |
||||
team := data.(string) |
||||
kvKey := kvstore.New("nsfwAllowed", allowedTeams, -1) |
||||
err := kvstore.Put(b.KB, team, "ssh0le", kvKey) |
||||
if err != nil { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
Loading…
Reference in new issue