/
nekos.go
94 lines (81 loc) · 2.2 KB
/
nekos.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cmd
import (
"context"
"encoding/json"
"fmt"
"github.com/0supa/degen/client"
"github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/api/cmdroute"
"github.com/diamondburned/arikawa/v3/discord"
)
type nekoResponse struct {
URL string `json:"url"`
}
var verbs = map[string]string{
"kiss": "kisses",
"hug": "hugs",
"pat": "pats",
"tickle": "tickles",
"cuddle": "cuddles with",
}
func init() {
RegisterCommand(Command{
Name: "nekos",
DiscordData: api.CreateCommandData{
Name: "nekos",
Description: "Get a weeb gif for a specific action",
Options: []discord.CommandOption{
&discord.StringOption{
OptionName: "action",
Description: "The action you want a gif for",
Required: true,
Choices: []discord.StringChoice{
{Name: "Kiss", Value: "kiss"},
{Name: "Hug", Value: "hug"},
{Name: "Pat", Value: "pat"},
{Name: "Ticke", Value: "tickle"},
{Name: "Cuddle", Value: "cuddle"},
},
},
&discord.UserOption{
OptionName: "receiver",
Description: "The user that gets your action",
Required: false,
},
},
},
DiscordHandler: func(ctx context.Context, cmd cmdroute.CommandData) *api.InteractionResponseData {
var options struct {
Action string `discord:"action"`
Target discord.UserID `discord:"receiver?"`
}
if err := cmd.Data.Options.Unmarshal(&options); err != nil {
return ErrorResponse(err)
}
res, err := client.HTTP.Get("https://nekos.life/api/v2/img/" + options.Action)
if err != nil {
return ErrorResponse(err)
}
data := nekoResponse{}
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return ErrorResponse(err)
}
Sender := cmd.Event.Sender()
var adj = "themself"
if Sender.ID != options.Target {
adj = options.Target.Mention()
}
var description string
if options.Target != 0 {
description = fmt.Sprintf("%s %s %s", Sender.Mention(), verbs[options.Action], adj)
}
return &api.InteractionResponseData{
Embeds: &[]discord.Embed{{
// Color: 0x3092790,
Image: &discord.EmbedImage{URL: data.URL},
Description: description,
}},
}
},
})
}