Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &commands.YAGCommand{ CmdCategory: commands.CategoryFun, Name: "dictionary", Aliases: []string{"owldict", "owl", "dict"}, Description: "Get the definition of an English word using dictionaryapi.dev", RequiredArgs: 1, Cooldown: 5, Arguments: []*dcmd.ArgDef{ {Name: "Query", Help: "Word to search for", Type: dcmd.String}, }, DefaultEnabled: true, SlashCommandEnabled: true, RunFunc: func(data *dcmd.Data) (interface{}, error) { query := strings.ToLower(data.Args[0].Str()) url := "https://api.dictionaryapi.dev/api/v2/entries/en/" + url.QueryEscape(query) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } resp, err := http.DefaultClient.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode == 404 { return "Could not find a definition for that word.", nil } body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } var res []DictionaryResponse err = json.Unmarshal(body, &res) if err != nil || len(res[0].Meanings) == 0 { logrus.WithError(err).Error("Failed getting response from dictionarydev") return "Could not find a definition for that word.", err } var dictionary = &res[0] if len(dictionary.Meanings) == 1 || data.Context().Value(paginatedmessages.CtxKeyNoPagination) != nil { return createDictionaryDefinitionEmbed(dictionary, &dictionary.Meanings[0]), nil } return paginatedmessages.NewPaginatedResponse(data.GuildData.GS.ID, data.ChannelID, 1, len(dictionary.Meanings), func(p *paginatedmessages.PaginatedMessage, page int) (*discordgo.MessageEmbed, error) { if page > len(dictionary.Meanings) { return nil, paginatedmessages.ErrNoResults } return createDictionaryDefinitionEmbed(dictionary, &dictionary.Meanings[page-1]), nil }), nil }, }
Functions ¶
This section is empty.
Types ¶
type Definition ¶
type DictionaryResponse ¶
Click to show internal directories.
Click to hide internal directories.