feat: Add interaction's reply method
This commit is contained in:
parent
ed81d98623
commit
d3ba8fbbf1
10 changed files with 133 additions and 117 deletions
|
@ -66,8 +66,6 @@ func getLength(data dataType, coll *mongo.Collection, filter bson.D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataLengthRun(s *discordgo.Session, m any) {
|
func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
var i *discordgo.Interaction
|
|
||||||
var referance *discordgo.MessageReference
|
|
||||||
var username, userId, channelId string
|
var username, userId, channelId string
|
||||||
var textLength,
|
var textLength,
|
||||||
muffinLength,
|
muffinLength,
|
||||||
|
@ -80,19 +78,11 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
username = m.Author.Username
|
username = m.Author.Username
|
||||||
userId = m.Author.ID
|
userId = m.Author.ID
|
||||||
channelId = m.ChannelID
|
channelId = m.ChannelID
|
||||||
referance = m.Reference()
|
case *utils.InteractionCreate:
|
||||||
case *discordgo.InteractionCreate:
|
m.DeferReply(true)
|
||||||
username = m.Member.User.Username
|
username = m.Member.User.Username
|
||||||
userId = m.Member.User.ID
|
userId = m.Member.User.ID
|
||||||
channelId = m.ChannelID
|
channelId = m.ChannelID
|
||||||
i = m.Interaction
|
|
||||||
s.InteractionRespond(i,
|
|
||||||
&discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go getLength(text, databases.Texts, bson.D{{}})
|
go getLength(text, databases.Texts, bson.D{{}})
|
||||||
|
@ -161,11 +151,11 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(channelId, embed, referance)
|
s.ChannelMessageSendEmbedReply(channelId, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(i, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,19 +67,10 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
Color: utils.EmbedFail,
|
Color: utils.EmbedFail,
|
||||||
}, m.Reference())
|
}, m.Reference())
|
||||||
}
|
}
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.DeferReply(true)
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
optsMap := map[string]*discordgo.ApplicationCommandInteractionDataOption{}
|
if opt, ok := m.Options["단어"]; ok {
|
||||||
for _, opt := range m.ApplicationCommandData().Options {
|
|
||||||
optsMap[opt.Name] = opt
|
|
||||||
}
|
|
||||||
if opt, ok := optsMap["단어"]; ok {
|
|
||||||
command = opt.StringValue()
|
command = opt.StringValue()
|
||||||
}
|
}
|
||||||
userId = m.Member.User.ID
|
userId = m.Member.User.ID
|
||||||
|
@ -96,8 +87,8 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -108,8 +99,8 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -165,8 +156,8 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
Components: components,
|
Components: components,
|
||||||
Reference: m.Reference(),
|
Reference: m.Reference(),
|
||||||
})
|
})
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
Components: &components,
|
Components: &components,
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,7 @@ package commands
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,13 +43,13 @@ type MsgContext struct {
|
||||||
|
|
||||||
type ChatInputContext struct {
|
type ChatInputContext struct {
|
||||||
Session *discordgo.Session
|
Session *discordgo.Session
|
||||||
Inter *discordgo.InteractionCreate
|
Inter *utils.InteractionCreate
|
||||||
Command *Command
|
Command *Command
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComponentContext struct {
|
type ComponentContext struct {
|
||||||
Session *discordgo.Session
|
Session *discordgo.Session
|
||||||
Inter *discordgo.InteractionCreate
|
Inter *utils.InteractionCreate
|
||||||
Component *Component
|
Component *Component
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,16 +105,26 @@ func (d *DiscommandStruct) ChatInputRun(name string, s *discordgo.Session, i *di
|
||||||
if command == nil {
|
if command == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
command.ChatInputRun(&ChatInputContext{s, i, command})
|
command.ChatInputRun(&ChatInputContext{s, &utils.InteractionCreate{
|
||||||
|
InteractionCreate: i,
|
||||||
|
Session: s,
|
||||||
|
Options: utils.GetInteractionOptions(i),
|
||||||
|
}, command})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (d *DiscommandStruct) ComponentRun(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
for _, c := range d.Components {
|
for _, c := range d.Components {
|
||||||
if (!c.Parse(&ComponentContext{s, i, c})) {
|
if (!c.Parse(&ComponentContext{s, &utils.InteractionCreate{
|
||||||
|
InteractionCreate: i,
|
||||||
|
Session: s,
|
||||||
|
}, c})) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Run(&ComponentContext{s, i, c})
|
c.Run(&ComponentContext{s, &utils.InteractionCreate{
|
||||||
|
InteractionCreate: i,
|
||||||
|
Session: s,
|
||||||
|
}, c})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,13 +72,11 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
commandName = Discommand.Aliases[strings.Join(*args, " ")]
|
commandName = Discommand.Aliases[strings.Join(*args, " ")]
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
optsMap := map[string]*discordgo.ApplicationCommandInteractionDataOption{}
|
if opt, ok := m.Options["도움말"]; ok {
|
||||||
for _, opt := range m.ApplicationCommandData().Options {
|
|
||||||
optsMap[opt.Name] = opt
|
|
||||||
}
|
|
||||||
if opt, ok := optsMap["명령어"]; ok {
|
|
||||||
commandName = opt.StringValue()
|
commandName = opt.StringValue()
|
||||||
|
} else {
|
||||||
|
commandName = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,12 +92,9 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.Reply(&discordgo.InteractionResponseData{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Embeds: []*discordgo.MessageEmbed{embed},
|
Embeds: []*discordgo.MessageEmbed{embed},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -148,12 +143,9 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.Reply(&discordgo.InteractionResponseData{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Embeds: []*discordgo.MessageEmbed{embed},
|
Embeds: []*discordgo.MessageEmbed{embed},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,12 +63,9 @@ func informationRun(s *discordgo.Session, m any) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.Reply(&discordgo.InteractionResponseData{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Embeds: []*discordgo.MessageEmbed{embed},
|
Embeds: []*discordgo.MessageEmbed{embed},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,26 +107,16 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
command = strings.ReplaceAll((*args)[0], "_", " ")
|
command = strings.ReplaceAll((*args)[0], "_", " ")
|
||||||
result = strings.ReplaceAll((*args)[1], "_", " ")
|
result = strings.ReplaceAll((*args)[1], "_", " ")
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.DeferReply(true)
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
userId = m.Member.User.ID
|
userId = m.Member.User.ID
|
||||||
|
|
||||||
optsMap := map[string]*discordgo.ApplicationCommandInteractionDataOption{}
|
if opt, ok := m.Options["단어"]; ok {
|
||||||
for _, opt := range m.ApplicationCommandData().Options {
|
|
||||||
optsMap[opt.Name] = opt
|
|
||||||
}
|
|
||||||
|
|
||||||
if opt, ok := optsMap["단어"]; ok {
|
|
||||||
command = opt.StringValue()
|
command = opt.StringValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt, ok := optsMap["대답"]; ok {
|
if opt, ok := m.Options["대답"]; ok {
|
||||||
result = opt.StringValue()
|
result = opt.StringValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,8 +146,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -176,8 +166,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -201,8 +191,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -218,8 +208,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,13 +47,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
userId = m.Author.ID
|
userId = m.Author.ID
|
||||||
globalName = m.Author.GlobalName
|
globalName = m.Author.GlobalName
|
||||||
avatarUrl = m.Author.AvatarURL("512")
|
avatarUrl = m.Author.AvatarURL("512")
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionRespond(m.Interaction, &discordgo.InteractionResponse{
|
m.DeferReply(true)
|
||||||
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
userId = m.Member.User.ID
|
userId = m.Member.User.ID
|
||||||
globalName = m.Member.User.GlobalName
|
globalName = m.Member.User.GlobalName
|
||||||
|
@ -72,8 +67,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -90,8 +85,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -114,8 +109,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
case *discordgo.MessageCreate:
|
case *discordgo.MessageCreate:
|
||||||
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
s.ChannelMessageSendEmbedReply(m.ChannelID, embed, m.Reference())
|
||||||
case *discordgo.InteractionCreate:
|
case *utils.InteractionCreate:
|
||||||
s.InteractionResponseEdit(m.Interaction, &discordgo.WebhookEdit{
|
m.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{embed},
|
Embeds: &[]*discordgo.MessageEmbed{embed},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
Parse: func(ctx *commands.ComponentContext) bool {
|
Parse: func(ctx *commands.ComponentContext) bool {
|
||||||
var userId string
|
var userId string
|
||||||
i := ctx.Inter
|
i := ctx.Inter
|
||||||
s := ctx.Session
|
|
||||||
customId := i.MessageComponentData().CustomID
|
customId := i.MessageComponentData().CustomID
|
||||||
|
|
||||||
if i.MessageComponentData().ComponentType == discordgo.ButtonComponent {
|
if i.MessageComponentData().ComponentType == discordgo.ButtonComponent {
|
||||||
|
@ -34,9 +33,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.Member.User.ID != userId {
|
if i.Member.User.ID != userId {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
i.Reply(&discordgo.InteractionResponseData{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Embeds: []*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
|
@ -47,25 +44,22 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
},
|
},
|
||||||
Components: []discordgo.MessageComponent{},
|
Components: []discordgo.MessageComponent{},
|
||||||
},
|
},
|
||||||
})
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
Run: func(ctx *commands.ComponentContext) {
|
Run: func(ctx *commands.ComponentContext) {
|
||||||
i := ctx.Inter
|
i := ctx.Inter
|
||||||
s := ctx.Session
|
|
||||||
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
i.DeferUpdate()
|
||||||
Type: discordgo.InteractionResponseDeferredMessageUpdate,
|
|
||||||
})
|
|
||||||
|
|
||||||
id, _ := bson.ObjectIDFromHex(strings.ReplaceAll(utils.ItemIdRegexp.ReplaceAllString(i.MessageComponentData().Values[0][len(utils.DeleteLearnedData):], ""), "&", ""))
|
id, _ := bson.ObjectIDFromHex(strings.ReplaceAll(utils.ItemIdRegexp.ReplaceAllString(i.MessageComponentData().Values[0][len(utils.DeleteLearnedData):], ""), "&", ""))
|
||||||
itemId := strings.ReplaceAll(utils.ItemIdRegexp.FindAllString(i.MessageComponentData().Values[0], 1)[0], "No.", "")
|
itemId := strings.ReplaceAll(utils.ItemIdRegexp.FindAllString(i.MessageComponentData().Values[0], 1)[0], "No.", "")
|
||||||
|
|
||||||
databases.Learns.DeleteOne(context.TODO(), bson.D{{Key: "_id", Value: id}})
|
databases.Learns.DeleteOne(context.TODO(), bson.D{{Key: "_id", Value: id}})
|
||||||
|
|
||||||
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
i.EditReply(&discordgo.WebhookEdit{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{
|
Embeds: &[]*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
Title: "✅ 삭제 완료",
|
Title: "✅ 삭제 완료",
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MUFFIN_VERSION = "5.0.0-gopher_dev.250404a"
|
const MUFFIN_VERSION = "5.0.0-gopher_preview.250405a"
|
||||||
|
|
||||||
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
var updatedString string = utils.Decimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
||||||
|
|
||||||
|
|
56
utils/interactions.go
Normal file
56
utils/interactions.go
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import "github.com/bwmarrin/discordgo"
|
||||||
|
|
||||||
|
// InteractionCreate custom data of discordgo.InteractionCreate
|
||||||
|
type InteractionCreate struct {
|
||||||
|
*discordgo.InteractionCreate
|
||||||
|
Session *discordgo.Session
|
||||||
|
// NOTE: It's only can ApplicationCommand
|
||||||
|
Options map[string]*discordgo.ApplicationCommandInteractionDataOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reply to this interaction.
|
||||||
|
func (i *InteractionCreate) Reply(data *discordgo.InteractionResponseData) {
|
||||||
|
i.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInteractionOptions to this interaction.
|
||||||
|
// NOTE: It's only can ApplicationCommand
|
||||||
|
func GetInteractionOptions(i *discordgo.InteractionCreate) map[string]*discordgo.ApplicationCommandInteractionDataOption {
|
||||||
|
optsMap := map[string]*discordgo.ApplicationCommandInteractionDataOption{}
|
||||||
|
for _, opt := range i.ApplicationCommandData().Options {
|
||||||
|
optsMap[opt.Name] = opt
|
||||||
|
}
|
||||||
|
return optsMap
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeferReply to this interaction.
|
||||||
|
func (i *InteractionCreate) DeferReply(ephemeral bool) {
|
||||||
|
var flags discordgo.MessageFlags
|
||||||
|
if ephemeral {
|
||||||
|
flags = discordgo.MessageFlagsEphemeral
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Flags: flags,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeferUpdate to this interaction.
|
||||||
|
func (i *InteractionCreate) DeferUpdate() {
|
||||||
|
i.Session.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseDeferredMessageUpdate,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditReply to this interaction.
|
||||||
|
func (i *InteractionCreate) EditReply(data *discordgo.WebhookEdit) {
|
||||||
|
i.Session.InteractionResponseEdit(i.Interaction, data)
|
||||||
|
}
|
Loading…
Reference in a new issue