-
Notifications
You must be signed in to change notification settings - Fork 927
/
define.go
40 lines (32 loc) · 937 Bytes
/
define.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package define
import (
"fmt"
"github.com/dpatrie/urbandictionary"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/commands"
)
var Command = &commands.YAGCommand{
CmdCategory: commands.CategoryFun,
Name: "Define",
Aliases: []string{"df"},
Description: "Look up an urban dictionary definition",
RequiredArgs: 1,
Arguments: []*dcmd.ArgDef{
{Name: "Topic", Type: dcmd.String},
},
RunFunc: func(data *dcmd.Data) (interface{}, error) {
qResp, err := urbandictionary.Query(data.Args[0].Str())
if err != nil {
return "Failed querying :(", err
}
if len(qResp.Results) < 1 {
return "No result :(", nil
}
result := qResp.Results[0]
cmdResp := fmt.Sprintf("**%s**: %s\n*%s*\n*(<%s>)*", result.Word, result.Definition, result.Example, result.Permalink)
if len(qResp.Results) > 1 {
cmdResp += fmt.Sprintf(" *%d more results*", len(qResp.Results)-1)
}
return cmdResp, nil
},
}