|
|
@ -41,20 +41,18 @@ var (
|
|
|
|
mu sync.Mutex
|
|
|
|
mu sync.Mutex
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func gcInteractionData() {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
time.Sleep(time.Minute * 5)
|
|
|
|
time.Sleep(time.Minute * 5)
|
|
|
|
now := time.Now()
|
|
|
|
now := time.Now()
|
|
|
|
mu.Lock()
|
|
|
|
mu.Lock()
|
|
|
|
for _, data := range interactionMap {
|
|
|
|
for _, data := range interactionMap {
|
|
|
|
if now.After(data.created.Add(time.Minute * 5)) {
|
|
|
|
if now.After(data.created.Add(time.Minute * 5)) {
|
|
|
|
delete(interactionMap, data.id)
|
|
|
|
delete(interactionMap, data.id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mu.Unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
mu.Unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (b *botState) handleDocs(e *gateway.InteractionCreateEvent) {
|
|
|
|
func (b *botState) handleDocs(e *gateway.InteractionCreateEvent) {
|
|
|
@ -161,11 +159,8 @@ func (b *botState) onDocsComponent(e *gateway.InteractionCreateEvent, data *inte
|
|
|
|
|
|
|
|
|
|
|
|
// Admin + privileged only.
|
|
|
|
// Admin + privileged only.
|
|
|
|
// (Only check admin here to reduce total API calls).
|
|
|
|
// (Only check admin here to reduce total API calls).
|
|
|
|
|
|
|
|
// If not privileged, send ephemeral instead.
|
|
|
|
case "expand":
|
|
|
|
case "expand":
|
|
|
|
if !isAdmin() {
|
|
|
|
|
|
|
|
embed = failEmbed("Error", cannotExpand)
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
embed, data.full = b.onDocs(e, data.query, true), true
|
|
|
|
embed, data.full = b.onDocs(e, data.query, true), true
|
|
|
|
components = &[]discord.Component{
|
|
|
|
components = &[]discord.Component{
|
|
|
|
discord.ActionRowComponent{
|
|
|
|
discord.ActionRowComponent{
|
|
|
@ -179,6 +174,17 @@ func (b *botState) onDocsComponent(e *gateway.InteractionCreateEvent, data *inte
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !isAdmin() {
|
|
|
|
|
|
|
|
_ = b.state.RespondInteraction(e.ID, e.Token, api.InteractionResponse{
|
|
|
|
|
|
|
|
Type: api.MessageInteractionWithSource,
|
|
|
|
|
|
|
|
Data: &api.InteractionResponseData{
|
|
|
|
|
|
|
|
Flags: api.EphemeralResponse,
|
|
|
|
|
|
|
|
Embeds: &[]discord.Embed{embed},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "hide":
|
|
|
|
case "hide":
|
|
|
|
components = &[]discord.Component{}
|
|
|
|
components = &[]discord.Component{}
|
|
|
|
embed = b.onDocs(e, data.query, data.full)
|
|
|
|
embed = b.onDocs(e, data.query, data.full)
|
|
|
|