Update dependencies, send expand in ephemeral sans permissions

master
ALI Hamza 2021-09-08 16:47:13 +07:00
parent d088e909c3
commit db2522e982
Signed by: hamza
GPG Key ID: 22473A32291F8CB6
4 changed files with 26 additions and 16 deletions

@ -41,20 +41,18 @@ var (
mu sync.Mutex
)
func init() {
go func() {
for {
time.Sleep(time.Minute * 5)
now := time.Now()
mu.Lock()
for _, data := range interactionMap {
if now.After(data.created.Add(time.Minute * 5)) {
delete(interactionMap, data.id)
}
func gcInteractionData() {
for {
time.Sleep(time.Minute * 5)
now := time.Now()
mu.Lock()
for _, data := range interactionMap {
if now.After(data.created.Add(time.Minute * 5)) {
delete(interactionMap, data.id)
}
mu.Unlock()
}
}()
mu.Unlock()
}
}
func (b *botState) handleDocs(e *gateway.InteractionCreateEvent) {
@ -161,11 +159,8 @@ func (b *botState) onDocsComponent(e *gateway.InteractionCreateEvent, data *inte
// Admin + privileged only.
// (Only check admin here to reduce total API calls).
// If not privileged, send ephemeral instead.
case "expand":
if !isAdmin() {
embed = failEmbed("Error", cannotExpand)
break
}
embed, data.full = b.onDocs(e, data.query, true), true
components = &[]discord.Component{
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":
components = &[]discord.Component{}
embed = b.onDocs(e, data.query, data.full)

@ -12,6 +12,7 @@ require (
require (
github.com/PuerkitoBio/goquery v1.7.1 // indirect
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect

@ -6,6 +6,8 @@ github.com/diamondburned/arikawa/v3 v3.0.0-20210824182349-f334491deed4 h1:Lj1nG3
github.com/diamondburned/arikawa/v3 v3.0.0-20210824182349-f334491deed4/go.mod h1:sNqM/iGXuH87wEH1rpQBEY1PR0AAkRKJuUhJGOdo7To=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.1 h1:1RHtYaVstlEJ5v8b3PNUIpa7D0cfg3qT7n7WbWjb5ZQ=
github.com/diamondburned/arikawa/v3 v3.0.0-rc.1/go.mod h1:sNqM/iGXuH87wEH1rpQBEY1PR0AAkRKJuUhJGOdo7To=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=

@ -85,6 +85,7 @@ func main() {
return
}
go gcInteractionData()
select {}
}