made simplefun plugin
This commit is contained in:
60
plugin_src/simplefun/cmd_cat.go
Normal file
60
plugin_src/simplefun/cmd_cat.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/events"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vaporvee/acecore/cmd"
|
||||
"github.com/vaporvee/acecore/custom"
|
||||
)
|
||||
|
||||
var cmd_cat = cmd.Command{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "cat",
|
||||
Description: "Random cat pictures",
|
||||
Contexts: []discord.InteractionContextType{
|
||||
discord.InteractionContextTypeGuild,
|
||||
discord.InteractionContextTypePrivateChannel,
|
||||
discord.InteractionContextTypeBotDM,
|
||||
},
|
||||
IntegrationTypes: []discord.ApplicationIntegrationType{
|
||||
discord.ApplicationIntegrationTypeGuildInstall,
|
||||
discord.ApplicationIntegrationTypeUserInstall,
|
||||
},
|
||||
},
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
cat, err := GetCatImageURL()
|
||||
if err == nil {
|
||||
err = e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
AddEmbeds(discord.NewEmbedBuilder().SetDescription(cat.Fact).SetImage(cat.Image).SetColor(custom.GetColor("primary")).Build()).
|
||||
Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
type Cat struct {
|
||||
Image string `json:"image"`
|
||||
Fact string `json:"fact"`
|
||||
}
|
||||
|
||||
func GetCatImageURL() (Cat, error) {
|
||||
resp, err := http.Get("https://some-random-api.com/animal/cat")
|
||||
var cat Cat
|
||||
if err != nil {
|
||||
return cat, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return cat, err
|
||||
}
|
||||
err = json.Unmarshal(body, &cat)
|
||||
return cat, err
|
||||
}
|
Reference in New Issue
Block a user