...
1 package search
2
3 import (
4 "bytes"
5 "encoding/binary"
6
7 "github.com/bwmarrin/discordgo"
8 "github.com/bwmarrin/snowflake"
9 "go.formulabun.club/discord/slashrecords/download"
10 "go.formulabun.club/replays/store"
11 )
12
13 var node = initNode()
14
15 func initNode() *snowflake.Node {
16 var name = "Formula bun"
17 buff := bytes.NewBufferString(name)
18 byteSlice := make([]byte, 64)
19 _, err := buff.Read(byteSlice)
20 if err != nil {
21 logger.Fatal(err)
22 }
23 value, n := binary.Varint(byteSlice)
24 if n == 0 {
25 logger.Fatal("Could not create snowflake node")
26 }
27 node, err := snowflake.NewNode(value)
28 if err != nil {
29 logger.Fatal(err)
30 }
31 return node
32 }
33
34 func makeButton(replay store.Replay) discordgo.Button {
35 id := node.Generate()
36 download.AddPendingDownload(id, replay)
37 return discordgo.Button{
38 Label: "Download top replay",
39 Style: discordgo.PrimaryButton,
40 Disabled: false,
41 CustomID: id.String(),
42 }
43 }
44
View as plain text