Add XKCD and FK (#22)

CI restart

Merge branch 'main' of git.etztech.xyz:Etzelia/sedbot into memes

Add XKCD and FK

Signed-off-by: Etzelia <etzelia@hotmail.com>

Co-authored-by: Etzelia <etzelia@hotmail.com>
Reviewed-on: https://git.etztech.xyz/Etzelia/sedbot/pulls/22
Co-Authored-By: Etzelia <etzelia@noreply.example.org>
Co-Committed-By: Etzelia <etzelia@noreply.example.org>
jup
Etzelia 2021-01-09 04:00:28 +01:00
parent 6a891d1ed1
commit bed25234bb
5 changed files with 97 additions and 1 deletions

46
discord/birb.go 100644
View File

@ -0,0 +1,46 @@
package discord
import (
"context"
"fmt"
"strconv"
"strings"
"go.etztech.xyz/falseknees"
)
func init() {
commands["birb"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
if !memeRateLimit.Try() {
return "", nil
}
client := falseknees.New()
var comic *falseknees.Comic
var err error
args := strings.Fields(cmd.message.Content)
if len(args) < 2 {
comic, err = client.Random(context.Background())
} else if strings.EqualFold(args[1], "new") {
comic, err = client.Current(context.Background())
} else {
comicNum, err := strconv.Atoi(args[1])
if err != nil {
return "", err
}
comic, err = client.Comic(context.Background(), comicNum)
}
if err != nil {
return "", err
}
return fmt.Sprintf("%d: %s\n%s", comic.Num, comic.Title, comic.Img), nil
},
help: "Get a FalseKnees comic",
}
}

View File

@ -24,7 +24,7 @@ func init() {
if userID != "" { if userID != "" {
limitArg = 2 limitArg = 2
if len(args) < 2 { if len(args) < 2 {
return "This command takes needs two arguments with a mention", nil return "This command takes two arguments with a mention", nil
} }
} else if len(args) < 1 { } else if len(args) < 1 {
return "This command takes one argument without a mention", nil return "This command takes one argument without a mention", nil

44
discord/xkcd.go 100644
View File

@ -0,0 +1,44 @@
package discord
import (
"context"
"fmt"
"strconv"
"strings"
"go.jolheiser.com/xkcd"
)
func init() {
commands["xkcd"] = command{
validate: func(cmd commandInit) bool {
return true
},
run: func(cmd commandInit) (string, error) {
if !memeRateLimit.Try() {
return "", nil
}
client := xkcd.New()
var comic *xkcd.Comic
var err error
args := strings.Fields(cmd.message.Content)
if len(args) < 2 {
comic, err = client.Current(context.Background())
} else {
comicNum, err := strconv.Atoi(args[1])
if err != nil {
return "", err
}
comic, err = client.Comic(context.Background(), comicNum)
}
if err != nil {
return "", err
}
return fmt.Sprintf("%d: %s\n%s\n%s", comic.Num, comic.SafeTitle, comic.Alt, comic.Img), nil
},
help: "Get an xkcd comic",
}
}

2
go.mod
View File

@ -7,10 +7,12 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect
github.com/pelletier/go-toml v1.8.1 github.com/pelletier/go-toml v1.8.1
go.etcd.io/bbolt v1.3.4 go.etcd.io/bbolt v1.3.4
go.etztech.xyz/falseknees v0.0.1
go.etztech.xyz/go-mcm v1.3.1 go.etztech.xyz/go-mcm v1.3.1
go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359
go.jolheiser.com/beaver v1.0.2 go.jolheiser.com/beaver v1.0.2
go.jolheiser.com/gojang v0.0.2 go.jolheiser.com/gojang v0.0.2
go.jolheiser.com/xkcd v0.0.1
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
golang.org/x/sys v0.0.0-20201024232916-9f70ab9862d5 // indirect golang.org/x/sys v0.0.0-20201024232916-9f70ab9862d5 // indirect
) )

4
go.sum
View File

@ -12,6 +12,8 @@ github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNC
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etztech.xyz/falseknees v0.0.1 h1:XjlBqMyBUH5b7e/9oedEwZ9pnz3sqMhXQv6vnQocxeM=
go.etztech.xyz/falseknees v0.0.1/go.mod h1:Acn1AwrvAArQEqhMBDlak5BvCZ3jgV8vdL8Pe5ZldRE=
go.etztech.xyz/go-mcm v1.3.1 h1:RLdOQrMgw0eP7bsfRRbXLW8c5/RaJ5Mg7i/ESFaUwvY= go.etztech.xyz/go-mcm v1.3.1 h1:RLdOQrMgw0eP7bsfRRbXLW8c5/RaJ5Mg7i/ESFaUwvY=
go.etztech.xyz/go-mcm v1.3.1/go.mod h1:Hz2YULB3sN/aQA8cPSm2d6LM3E3qTMspzfRCIAD/1dc= go.etztech.xyz/go-mcm v1.3.1/go.mod h1:Hz2YULB3sN/aQA8cPSm2d6LM3E3qTMspzfRCIAD/1dc=
go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 h1:j/ZeoAj185wHfCSYD52Kt/69i3Bzk1MXN4Qh1yP6+P4= go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 h1:j/ZeoAj185wHfCSYD52Kt/69i3Bzk1MXN4Qh1yP6+P4=
@ -20,6 +22,8 @@ go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk=
go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g= go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g=
go.jolheiser.com/gojang v0.0.2 h1:CvQETKT9sFfvuDeYVUkiR0Jh7xIs7Cayi0rZuDrXoZg= go.jolheiser.com/gojang v0.0.2 h1:CvQETKT9sFfvuDeYVUkiR0Jh7xIs7Cayi0rZuDrXoZg=
go.jolheiser.com/gojang v0.0.2/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I= go.jolheiser.com/gojang v0.0.2/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I=
go.jolheiser.com/xkcd v0.0.1 h1:pRNY2BXxUS+NMtKlm/ENumOr7g3k4VWY/QoDri9YSNU=
go.jolheiser.com/xkcd v0.0.1/go.mod h1:AzWPrZToCLfpazsZBkeu/nPuIvurMqfCOptiydz7Dvk=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=