/
karma.go
82 lines (74 loc) · 2.18 KB
/
karma.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
package commands
import (
"github.com/bwmarrin/discordgo"
"github.com/corentings/stouuf-bot/services"
)
var KarmaCommand = discordgo.ApplicationCommand{
Name: "karma",
Description: "Karma main command",
Options: []*discordgo.ApplicationCommandOption{
{
Name: "add",
Description: "add karma",
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user-option",
Description: "User option",
Required: true,
},
},
},
{
Name: "show",
Description: "show karma",
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user-option",
Description: "User option",
Required: false,
},
},
},
{
Name: "help",
Description: "help",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
},
}
func KarmaCommandHandler() func(s *discordgo.Session, i *discordgo.InteractionCreate) {
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
options := i.ApplicationCommandData().Options
karmaCommand := services.GetServiceContainer().InjectKarmaCommandHandler()
var embed *discordgo.MessageEmbed
var err error
switch options[0].Name {
case "add":
embed, err = karmaCommand.AddKarmaCommandHandler(s, i)
case "show":
embed, err = karmaCommand.ShowKarmaCommandHandler(s, i)
default:
embed, err = karmaCommand.HelpKarmaCommandHandler(s, i)
}
if err != nil {
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{embed},
Flags: discordgo.MessageFlagsEphemeral,
},
})
return
}
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{embed},
},
})
}
}