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
|
package api
import (
"context"
"strings"
"github.com/kyren223/eko/internal/data"
"github.com/kyren223/eko/internal/packet"
"github.com/kyren223/eko/pkg/snowflake"
)
const hex = "0123456789abcdefABCDEF"
func isValidHexColor(color string) (bool, string) {
if len(color) != 7 {
return false, "color must be hex with length of 7"
}
if color[0] != '#' {
return false, "color must start with '#'"
}
for _, c := range color[1:] {
if !strings.ContainsRune(hex, c) {
return false, "color must start with '#' and contain exactly 6 digits 0-9, a-f, A-F"
}
}
return true, ""
}
func IsNetworkAdmin(ctx context.Context, queries *data.Queries, userId, networkId snowflake.ID) (bool, error) {
userNetwork, err := queries.GetUserNetwork(ctx, data.GetUserNetworkParams{
UserID: userId,
NetworkID: networkId,
})
if err != nil {
return false, err
}
isAdmin := userNetwork.IsAdmin && userNetwork.IsMember && !userNetwork.IsBanned
return isAdmin, nil
}
func GetSingleNetworkInfo(ctx context.Context, queries *data.Queries, network data.Network) (packet.Payload, error) {
frequencies, err := queries.GetNetworkFrequencies(ctx, network.ID)
if err != nil {
return nil, err
}
members, err := queries.GetNetworkMembers(ctx, network.ID)
if err != nil {
return nil, err
}
fullNetwork := packet.FullNetwork{
Network: network,
Frequencies: frequencies,
Members: members,
Position: -1,
}
return &packet.NetworksInfo{
Networks: []packet.FullNetwork{fullNetwork},
RemoveNetworks: nil,
Set: false,
}, nil
}
|