made simplefun plugin

This commit is contained in:
2024-04-14 22:26:30 +02:00
parent 410c28bda9
commit d814d39cf1
22 changed files with 96 additions and 39 deletions

View File

@@ -4,10 +4,10 @@ import (
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/struct_cmd"
"github.com/vaporvee/acecore/cmd"
)
var Plugin = &struct_cmd.Plugin{
var Plugin = &cmd.Plugin{
Name: "testplugin",
Register: func(e *events.Ready) error {
app, err := e.Client().Rest().GetCurrentApplication()
@@ -17,7 +17,7 @@ var Plugin = &struct_cmd.Plugin{
logrus.Infof("%s has a working plugin called \"testplugin\"", app.Bot.Username)
return nil
},
Commands: []struct_cmd.Command{
Commands: []cmd.Command{
{
Definition: discord.SlashCommandCreate{
Name: "testplugincommand",

View File

@@ -0,0 +1,40 @@
package main
import (
"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_ask = cmd.Command{
Definition: discord.SlashCommandCreate{
Name: "ask",
Description: "Ask anything and get a gif as response!",
Contexts: []discord.InteractionContextType{
discord.InteractionContextTypeGuild,
discord.InteractionContextTypePrivateChannel,
discord.InteractionContextTypeBotDM,
},
IntegrationTypes: []discord.ApplicationIntegrationType{
discord.ApplicationIntegrationTypeGuildInstall,
discord.ApplicationIntegrationTypeUserInstall,
},
Options: []discord.ApplicationCommandOption{
&discord.ApplicationCommandOptionString{
Name: "question",
Description: "The question you want to ask",
Required: true,
},
},
},
Interact: func(e *events.ApplicationCommandInteractionCreate) {
err := e.CreateMessage(discord.NewMessageCreateBuilder().
AddEmbeds(discord.NewEmbedBuilder().SetImage(simpleGetFromAPI("image", "https://yesno.wtf/api").(string)).SetColor(custom.GetColor("primary")).Build()).
Build())
if err != nil {
logrus.Error(err)
}
},
}

View 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
}

View File

@@ -0,0 +1,33 @@
package main
import (
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/cmd"
)
var cmd_dadjoke = cmd.Command{
Definition: discord.SlashCommandCreate{
Name: "dadjoke",
Description: "Gives you a random joke that is as bad as your dad would tell them",
Contexts: []discord.InteractionContextType{
discord.InteractionContextTypeGuild,
discord.InteractionContextTypePrivateChannel,
discord.InteractionContextTypeBotDM,
},
IntegrationTypes: []discord.ApplicationIntegrationType{
discord.ApplicationIntegrationTypeGuildInstall,
discord.ApplicationIntegrationTypeUserInstall,
},
},
Interact: func(e *events.ApplicationCommandInteractionCreate) {
joke := simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string)
err := e.CreateMessage(discord.NewMessageCreateBuilder().
SetContent(joke).
Build())
if err != nil {
logrus.Error(err)
}
},
}

View File

@@ -0,0 +1,3 @@
module simplefun
go 1.22.1

View File

@@ -0,0 +1,20 @@
package main
import (
"github.com/disgoorg/disgo/events"
"github.com/sirupsen/logrus"
"github.com/vaporvee/acecore/cmd"
)
var Plugin = &cmd.Plugin{
Name: "Simple Fun",
Register: func(e *events.Ready) error {
app, err := e.Client().Rest().GetCurrentApplication()
if err != nil {
return err
}
logrus.Infof("%s has a working plugin called \"testplugin\"", app.Bot.Username)
return nil
},
Commands: []cmd.Command{cmd_ask, cmd_cat, cmd_dadjoke},
}

View File

@@ -0,0 +1,34 @@
package main
import (
"encoding/json"
"io"
"net/http"
"github.com/sirupsen/logrus"
)
func simpleGetFromAPI(key string, url string) interface{} {
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
logrus.Error("Error creating request:", err)
}
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
logrus.Error("Error making request:", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
logrus.Error("Error reading response body:", err)
}
var result map[string]interface{}
err = json.Unmarshal(body, &result)
if err != nil {
logrus.Error("Error decoding JSON:", err)
}
return result[key]
}