renamed files because folders are stupid in golang

This commit is contained in:
2024-02-20 18:20:32 +01:00
parent b6b2493b5c
commit 8c801a3e0a
4 changed files with 0 additions and 0 deletions

53
cmd_dadjoke.go Normal file
View File

@@ -0,0 +1,53 @@
package main
import (
"encoding/json"
"io"
"log"
"net/http"
"github.com/bwmarrin/discordgo"
)
var dadjoke_command Command = Command{
Definition: discordgo.ApplicationCommand{
Name: "dadjoke",
Description: "Gives you a random joke that is as bad as your dad would tell them",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://icanhazdadjoke.com/", nil)
if err != nil {
log.Println("Error creating request:", err)
return
}
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Println("Error making request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("Error reading response body:", err)
return
}
type Joke struct {
Joke string `json:"joke"`
}
var joke Joke
err = json.Unmarshal(body, &joke)
if err != nil {
log.Println("Error decoding JSON:", err)
return
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: joke.Joke,
},
})
},
}