refactor funbot to packages
This commit is contained in:
parent
21c6e7a748
commit
5d96c929bb
5 changed files with 182 additions and 160 deletions
46
cmd/funbot/command/img.go
Normal file
46
cmd/funbot/command/img.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/events"
|
||||
"grow.rievo.dev/discordBots/cmd/funbot/imgur"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Listener(event *events.ApplicationCommandInteractionCreate) {
|
||||
data := event.SlashCommandInteractionData()
|
||||
if data.CommandName() == "img" {
|
||||
handlerImg(event)
|
||||
}
|
||||
}
|
||||
|
||||
func handlerImg(event *events.ApplicationCommandInteractionCreate) {
|
||||
data := event.SlashCommandInteractionData()
|
||||
value := data.String("type")
|
||||
|
||||
link, err := func(value string) (string, error) {
|
||||
switch {
|
||||
case strings.HasPrefix(value, "imgur-"):
|
||||
link, err := imgur.GetRandomImgur(strings.TrimPrefix(value, "imgur-"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return link, nil
|
||||
default:
|
||||
return "", errors.New("value not found")
|
||||
}
|
||||
}(value)
|
||||
if err != nil {
|
||||
event.Client().Logger().Error("error on getting link: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = event.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent(link).
|
||||
SetEphemeral(false).Build())
|
||||
if err != nil {
|
||||
event.Client().Logger().Error("error on sending response: ", err)
|
||||
return
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue