Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d27bc5383 | |||
| 1e1f7e7898 | |||
| 489139f66b |
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,3 +15,6 @@ app
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
# VSCODE
|
||||||
|
.vscode
|
||||||
@ -8,11 +8,11 @@ import (
|
|||||||
"samhofi.us/x/keybase/v2/types/chat1"
|
"samhofi.us/x/keybase/v2/types/chat1"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*var BoobsAd = chat1.UserBotCommandInput{
|
var BoobsAd = chat1.UserBotCommandInput{
|
||||||
Name: "eyebleach",
|
Name: "boobs",
|
||||||
Usage: "",
|
Usage: "",
|
||||||
Description: "Sends some cute critters",
|
Description: "Sends some titties",
|
||||||
}*/
|
}
|
||||||
|
|
||||||
func Boobs(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
|
func Boobs(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
|
||||||
path, desc, err := getRandomRedditMedia(b, "boobs", "top", 100)
|
path, desc, err := getRandomRedditMedia(b, "boobs", "top", 100)
|
||||||
|
|||||||
33
cmd/nsfw.go
33
cmd/nsfw.go
@ -79,7 +79,11 @@ func addNsfwTeam(b *keybasebot.Bot, c chat1.ConvIDStr) bool {
|
|||||||
// the key doesn't exist yet so go ahead and create it
|
// the key doesn't exist yet so go ahead and create it
|
||||||
allowedTeams[c] = true
|
allowedTeams[c] = true
|
||||||
} else {
|
} else {
|
||||||
// the key exists and needs to be updated
|
// the key exists
|
||||||
|
if allowedTeams[c] == true {
|
||||||
|
// its already allowed so just return
|
||||||
|
return true
|
||||||
|
}
|
||||||
allowedTeams = data.(map[chat1.ConvIDStr]bool)
|
allowedTeams = data.(map[chat1.ConvIDStr]bool)
|
||||||
allowedTeams[c] = true
|
allowedTeams[c] = true
|
||||||
}
|
}
|
||||||
@ -95,6 +99,19 @@ func addNsfwTeam(b *keybasebot.Bot, c chat1.ConvIDStr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// now we need to add the key to the Commands/Ads and re-advertise
|
||||||
|
b.ClearCommands()
|
||||||
|
b.Commands = append(b.Commands,
|
||||||
|
keybasebot.BotCommand{
|
||||||
|
Name: "boobs",
|
||||||
|
Ad: &BoobsAd,
|
||||||
|
AdType: "conv",
|
||||||
|
AdTeamName: "",
|
||||||
|
AdConv: c,
|
||||||
|
Run: FakeNsfwAction,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
b.AdvertiseCommands()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,9 +139,23 @@ func delNsfwTeam(b *keybasebot.Bot, c chat1.ConvIDStr) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// then delete the advertisement
|
||||||
|
b.ClearCommands()
|
||||||
|
oldCommands := b.Commands
|
||||||
|
b.Commands = nil
|
||||||
|
for _, cmd := range oldCommands {
|
||||||
|
if cmd.AdConv != c {
|
||||||
|
b.Commands = append(b.Commands, cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.AdvertiseCommands()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FakeNsfwAction(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func isConversationId(s string) bool {
|
func isConversationId(s string) bool {
|
||||||
if len(s) != 64 {
|
if len(s) != 64 {
|
||||||
return false
|
return false
|
||||||
|
|||||||
6
go.mod
6
go.mod
@ -9,13 +9,13 @@ require (
|
|||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
github.com/golang/protobuf v1.4.3 // indirect
|
github.com/golang/protobuf v1.4.3 // indirect
|
||||||
github.com/google/go-querystring v1.0.0 // indirect
|
github.com/google/go-querystring v1.0.0 // indirect
|
||||||
github.com/google/uuid v1.1.5
|
github.com/google/uuid v1.2.0
|
||||||
github.com/jzelinskie/geddit v0.0.0-20200521013404-78c28c13fba2
|
github.com/jzelinskie/geddit v0.0.0-20200521013404-78c28c13fba2
|
||||||
github.com/kf5grd/keybasebot v1.5.0
|
github.com/kf5grd/keybasebot v1.7.0
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125
|
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
|
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3 // indirect
|
golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
samhofi.us/x/keybase/v2 v2.0.8
|
samhofi.us/x/keybase/v2 v2.0.8
|
||||||
|
|||||||
6
go.sum
6
go.sum
@ -111,6 +111,8 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf
|
|||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/google/uuid v1.1.5 h1:kxhtnfFVi+rYdOALN0B3k9UT86zVJKfBimRaciULW4I=
|
github.com/google/uuid v1.1.5 h1:kxhtnfFVi+rYdOALN0B3k9UT86zVJKfBimRaciULW4I=
|
||||||
github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
||||||
|
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
@ -124,6 +126,8 @@ github.com/kf5grd/keybasebot v1.4.1 h1:6VTcDnCiYWtEtxSOEFvKF5R7VwabR3pSEONWV81WS
|
|||||||
github.com/kf5grd/keybasebot v1.4.1/go.mod h1:8T07cWZZrl2G6hTRsL9x2SBwaH8gEZocF9NRknSU3dY=
|
github.com/kf5grd/keybasebot v1.4.1/go.mod h1:8T07cWZZrl2G6hTRsL9x2SBwaH8gEZocF9NRknSU3dY=
|
||||||
github.com/kf5grd/keybasebot v1.5.0 h1:pLexa3GxSFCaypqN6QYhb4mPD2zaMHkhwChxN0Tkwug=
|
github.com/kf5grd/keybasebot v1.5.0 h1:pLexa3GxSFCaypqN6QYhb4mPD2zaMHkhwChxN0Tkwug=
|
||||||
github.com/kf5grd/keybasebot v1.5.0/go.mod h1:8T07cWZZrl2G6hTRsL9x2SBwaH8gEZocF9NRknSU3dY=
|
github.com/kf5grd/keybasebot v1.5.0/go.mod h1:8T07cWZZrl2G6hTRsL9x2SBwaH8gEZocF9NRknSU3dY=
|
||||||
|
github.com/kf5grd/keybasebot v1.7.0 h1:8Jl6RSYEIyzniZ7UFyH/fjTlsM0tZHTCZ5F8bq8JTDA=
|
||||||
|
github.com/kf5grd/keybasebot v1.7.0/go.mod h1:8T07cWZZrl2G6hTRsL9x2SBwaH8gEZocF9NRknSU3dY=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
@ -217,6 +221,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
|
|||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
||||||
|
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
|||||||
30
main.go
30
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -82,19 +83,20 @@ func run(c *cli.Context) error {
|
|||||||
b.Debug = c.Bool("debug")
|
b.Debug = c.Bool("debug")
|
||||||
b.JSON = c.Bool("json")
|
b.JSON = c.Bool("json")
|
||||||
b.LogWriter = os.Stdout
|
b.LogWriter = os.Stdout
|
||||||
b.LogConv = chat1.ConvIDStr(c.String("log-convid"))
|
//b.LogConv = chat1.ConvIDStr(c.String("log-convid"))
|
||||||
// set the bot owner for private commands
|
// set the bot owner for private commands
|
||||||
if c.String("owner") != "" {
|
if c.String("owner") != "" {
|
||||||
b.Meta["owner"] = c.String("owner")
|
b.Meta["owner"] = c.String("owner")
|
||||||
}
|
}
|
||||||
|
allowedTeams := make(map[chat1.ConvIDStr]bool)
|
||||||
if c.String("kvstore-team") != "" {
|
if c.String("kvstore-team") != "" {
|
||||||
b.Meta["kvstore"] = c.String("kvstore-team")
|
b.Meta["kvstore"] = c.String("kvstore-team")
|
||||||
loadNsfwAllowed(b)
|
allowedTeams = loadNsfwAllowed(b)
|
||||||
}
|
}
|
||||||
// set reddit login, which enables reddit commands
|
// set reddit login, which enables reddit commands
|
||||||
if c.String("reddit-user") != "" && c.String("reddit-pass") != "" {
|
if c.String("reddit-user") != "" && c.String("reddit-pass") != "" {
|
||||||
b.Meta["reddit-user"] = c.String("reddit-user")
|
b.Meta["reddit-user"] = c.String("reddit-user")
|
||||||
b.Meta["reddit-pass"] = c.String("reddit-user")
|
b.Meta["reddit-pass"] = c.String("reddit-pass")
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the bot commands
|
// register the bot commands
|
||||||
@ -166,7 +168,7 @@ func run(c *cli.Context) error {
|
|||||||
},
|
},
|
||||||
keybasebot.BotCommand{
|
keybasebot.BotCommand{
|
||||||
Name: "boobs",
|
Name: "boobs",
|
||||||
Ad: nil,
|
Ad: nil, // send nil advertisement and send fake per-convid ones later
|
||||||
Run: keybasebot.Adapt(
|
Run: keybasebot.Adapt(
|
||||||
cmd.Boobs,
|
cmd.Boobs,
|
||||||
keybasebot.MessageType("text"),
|
keybasebot.MessageType("text"),
|
||||||
@ -175,6 +177,22 @@ func run(c *cli.Context) error {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
for convID, allowed := range allowedTeams {
|
||||||
|
fmt.Printf("loading NSFW conversations\n")
|
||||||
|
if allowed {
|
||||||
|
fmt.Printf("NSFW allowed in %s\n", string(convID))
|
||||||
|
b.Commands = append(b.Commands,
|
||||||
|
keybasebot.BotCommand{
|
||||||
|
Name: "boobs",
|
||||||
|
Ad: &cmd.BoobsAd,
|
||||||
|
AdType: "conv",
|
||||||
|
AdTeamName: "",
|
||||||
|
AdConv: convID,
|
||||||
|
Run: cmd.FakeNsfwAction,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// catch ctrl-c so we can clean up
|
// catch ctrl-c so we can clean up
|
||||||
@ -190,16 +208,14 @@ func run(c *cli.Context) error {
|
|||||||
}()
|
}()
|
||||||
// then run
|
// then run
|
||||||
b.Run()
|
b.Run()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadNsfwAllowed(b *keybasebot.Bot) {
|
func loadNsfwAllowed(b *keybasebot.Bot) (allowedTeams map[chat1.ConvIDStr]bool) {
|
||||||
// get the team from meta
|
// get the team from meta
|
||||||
data, ok := b.Meta["kvstore"]
|
data, ok := b.Meta["kvstore"]
|
||||||
if ok {
|
if ok {
|
||||||
// make something to fill
|
// make something to fill
|
||||||
allowedTeams := make(map[chat1.ConvIDStr]bool)
|
|
||||||
team := data.(string)
|
team := data.(string)
|
||||||
kvKey := kvstore.New("nsfwAllowed", &allowedTeams, -1)
|
kvKey := kvstore.New("nsfwAllowed", &allowedTeams, -1)
|
||||||
err := kvstore.Get(b.KB, team, "ssh0le", &kvKey)
|
err := kvstore.Get(b.KB, team, "ssh0le", &kvKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user