This repository was archived by the owner on Nov 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
74 lines (65 loc) · 2.92 KB
/
request.go
File metadata and controls
74 lines (65 loc) · 2.92 KB
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
package contract
import (
"time"
"github.com/golang-jwt/jwt/v4"
)
type Request struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
ContextId string `json:"contextId,omitempty" yaml:"contextId,omitempty"`
IntentId string `json:"intentId,omitempty" yaml:"intentId,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
Bot User `json:"bot,omitempty" yaml:"bot,omitempty"`
Author User `json:"author,omitempty" yaml:"author,omitempty"`
ChannelId string `json:"channelId,omitempty" yaml:"channelId,omitempty"`
ServerId string `json:"serverId,omitempty" yaml:"serverId,omitempty"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Mentions []User `json:"mentions,omitempty" yaml:"mentions,omitempty"`
Content string `json:"content,omitempty" yaml:"content,omitempty"`
Application Application `json:"application,omitempty" yaml:"application,omitempty"`
QueryParams map[string][]string `json:"queryParams,omitempty"`
}
type User struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Discriminator string `json:"discriminator" yaml:"discriminator"`
}
type Server struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
OwnerId string `json:"ownerId,omitempty" yaml:"ownerId,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
UserCount int32 `json:"userCount,omitempty" yaml:"userCount,omitempty"`
IconUrl string `json:"iconUrl,omitempty" yaml:"iconUrl,omitempty"`
SystemChannelId string `json:"systemChannelId,omitempty" yaml:"systemChannelId,omitempty"`
}
type Application struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Icon string `json:"icon,omitempty" yaml:"icon,omitempty"`
Owner User `json:"owner,omitempty" yaml:"owner,omitempty"`
}
// Server returns the full server for the ServerId
func (r Request) Server() Server {
for _, server := range r.Servers {
if server.Id == r.ServerId {
return server
}
}
return Server{Id: r.ServerId}
}
// JwtClaims returns jwt claims populated with values from request
func (r Request) JwtClaims(expiresIn time.Duration) JwtClaims {
return JwtClaims{
ContextId: r.ContextId,
IntentId: r.IntentId,
ChannelId: r.ChannelId,
AuthorId: r.Author.Id,
ServerId: r.ServerId,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(expiresIn).Unix(),
IssuedAt: time.Now().Unix(),
NotBefore: time.Now().Unix(),
},
}
}