Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &commands.YAGCommand{ CmdCategory: commands.CategoryFun, Name: "OwlDictionary", Aliases: []string{"owldict", "owl"}, Description: "Get the definition of an English word using the Owlbot API.", 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()) req, err := http.NewRequest("GET", "https://owlbot.info/api/v4/dictionary/"+url.QueryEscape(query), nil) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("Authorization", "Token "+confOwlbotToken.GetString()) 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 OwlbotResult err = json.Unmarshal(body, &res) if err != nil || len(res.Definitions) == 0 { return "Could not find a definition for that word.", err } if len(res.Definitions) == 1 || data.Context().Value(paginatedmessages.CtxKeyNoPagination) != nil { return createOwlbotDefinitionEmbed(&res, res.Definitions[0]), nil } _, err = paginatedmessages.CreatePaginatedMessage(data.GuildData.GS.ID, data.ChannelID, 1, len(res.Definitions), func(p *paginatedmessages.PaginatedMessage, page int) (*discordgo.MessageEmbed, error) { if page > len(res.Definitions) { return nil, paginatedmessages.ErrNoResults } return createOwlbotDefinitionEmbed(&res, res.Definitions[page-1]), nil }) return "", err }, }
Functions ¶
func ShouldRegister ¶
func ShouldRegister() bool
Types ¶
type OwlbotDefinition ¶
type OwlbotResult ¶
type OwlbotResult struct { Word string `json:"word"` Definitions []*OwlbotDefinition `json:"definitions"` Pronunciation *string `json:"pronunciation"` }
Click to show internal directories.
Click to hide internal directories.