...
1 package search
2
3 import (
4 "log"
5 "os"
6
7 "github.com/bwmarrin/discordgo"
8 "go.formulabun.club/discord/context"
9 "go.formulabun.club/replays/store"
10 "go.formulabun.club/srb2kart/conversion"
11 )
12
13 var logger = log.New(os.Stdout, "/records search ", log.LstdFlags)
14
15 var oneFloat = float64(1)
16
17 var mapOption = &discordgo.ApplicationCommandOption{
18 Type: discordgo.ApplicationCommandOptionString,
19 Name: "map",
20 Description: "the name of the map",
21 Required: true,
22 MinValue: &oneFloat,
23 }
24
25 var CommandOption = &discordgo.ApplicationCommandOption{
26 Type: discordgo.ApplicationCommandOptionSubCommand,
27 Name: "search",
28 Description: "Search records",
29 Options: []*discordgo.ApplicationCommandOption{mapOption},
30 }
31
32 func Reply(c *context.DiscordContext, options []*discordgo.ApplicationCommandInteractionDataOption) discordgo.InteractionResponse {
33 var searchData store.Replay
34
35 for _, option := range options {
36 switch option.Name {
37 case mapOption.Name:
38
39 mapID, _ := conversion.MapIdToNumber(option.Value.(string))
40 searchData.GameMap = uint16(mapID)
41 }
42 }
43
44 replays, err := c.ReplayDB.FindReplay(searchData)
45 if err != nil {
46 return discordgo.InteractionResponse{
47 discordgo.InteractionResponseChannelMessageWithSource,
48 &discordgo.InteractionResponseData{Content: "Something terrible happened D:", Flags: discordgo.MessageFlagsEphemeral},
49 }
50 }
51
52 var components []discordgo.MessageComponent
53 embeds := format(searchData, replays)
54
55 if len(replays) > 0 {
56 button := makeButton(searchData)
57
58 components = []discordgo.MessageComponent{discordgo.ActionsRow{
59 []discordgo.MessageComponent{
60 button,
61 },
62 }}
63 }
64
65 return discordgo.InteractionResponse{
66 discordgo.InteractionResponseChannelMessageWithSource,
67 &discordgo.InteractionResponseData{
68 Embeds: embeds,
69 Components: components,
70 },
71 }
72 }
73
View as plain text