dadjoke

package
v2.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &commands.YAGCommand{
	Cooldown:            5,
	CmdCategory:         commands.CategoryFun,
	Name:                "DadJoke",
	Description:         "Generates a dad joke using the API from icanhazdadjoke.",
	DefaultEnabled:      true,
	SlashCommandEnabled: true,
	RunFunc: func(data *dcmd.Data) (interface{}, error) {
		req, err := http.NewRequest("GET", "https://icanhazdadjoke.com", nil)
		if err != nil {
			return nil, err
		}

		req.Header.Set("Accept", "application/json")
		req.Header.Add("User-Agent", "YAGPDB.xyz (https://github.com/botlabs-gg/yagpdb)")

		apiResp, err := http.DefaultClient.Do(req)
		if err != nil {
			return nil, err
		}
		defer apiResp.Body.Close()
		bytes, err := io.ReadAll(apiResp.Body)
		if err != nil {
			return nil, err
		}
		var joke Joke
		err = json.Unmarshal(bytes, &joke)
		if err != nil {
			return nil, err
		}

		resp := joke.Joke
		return resp, nil
	},
}

Functions

This section is empty.

Types

type Joke

type Joke struct {
	ID     string `json:"id"`
	Joke   string `json:"joke"`
	Status int    `json:"status"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL