feat: add AllowedMentions
This commit is contained in:
parent
20c0debf4a
commit
7390cc31ed
3 changed files with 44 additions and 38 deletions
|
@ -14,7 +14,6 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func argParser(content string) (args []string) {
|
func argParser(content string) (args []string) {
|
||||||
|
@ -109,9 +108,6 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
go func() {
|
go func() {
|
||||||
cur, err := databases.Database.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: content}})
|
cur, err := databases.Database.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: content}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == mongo.ErrNilDocument {
|
|
||||||
learnData = []databases.Learn{}
|
|
||||||
}
|
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,27 +127,27 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
user, _ := s.User(data.UserId)
|
user, _ := s.User(data.UserId)
|
||||||
result := resultParser(data.Result, s, m)
|
result := resultParser(data.Result, s, m)
|
||||||
|
|
||||||
s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
|
utils.NewMessageSender(m).
|
||||||
Reference: m.Reference(),
|
SetContent(fmt.Sprintf("%s\n%s", result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username)))).
|
||||||
Content: fmt.Sprintf("%s\n%s", result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username))),
|
SetAllowedMentions(discordgo.MessageAllowedMentions{
|
||||||
AllowedMentions: &discordgo.MessageAllowedMentions{
|
|
||||||
Roles: []string{},
|
Roles: []string{},
|
||||||
Parse: []discordgo.AllowedMentionType{},
|
Parse: []discordgo.AllowedMentionType{},
|
||||||
Users: []string{},
|
Users: []string{},
|
||||||
},
|
}).
|
||||||
})
|
SetReply(true).
|
||||||
|
Send()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
|
utils.NewMessageSender(m).
|
||||||
Reference: m.Reference(),
|
SetContent(data[rand.Intn(len(data))].Text).
|
||||||
Content: data[rand.Intn(len(data))].Text,
|
SetAllowedMentions(discordgo.MessageAllowedMentions{
|
||||||
AllowedMentions: &discordgo.MessageAllowedMentions{
|
|
||||||
Roles: []string{},
|
Roles: []string{},
|
||||||
Parse: []discordgo.AllowedMentionType{},
|
Parse: []discordgo.AllowedMentionType{},
|
||||||
Users: []string{},
|
Users: []string{},
|
||||||
},
|
}).
|
||||||
})
|
SetReply(true).
|
||||||
|
Send()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
main.go
26
main.go
|
@ -21,6 +21,20 @@ import (
|
||||||
"github.com/devproje/commando/types"
|
"github.com/devproje/commando/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
go commands.Discommand.LoadCommand(commands.HelpCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.DataLengthCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.LearnCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.LearnedDataListCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.InformationCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand)
|
||||||
|
|
||||||
|
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
||||||
|
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
||||||
|
|
||||||
|
go commands.Discommand.LoadModal(modals.PaginationEmbedModal)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
command := commando.NewCommando(os.Args[1:])
|
command := commando.NewCommando(os.Args[1:])
|
||||||
config := configs.Config
|
config := configs.Config
|
||||||
|
@ -68,18 +82,6 @@ func main() {
|
||||||
|
|
||||||
dg, _ := discordgo.New("Bot " + config.Bot.Token)
|
dg, _ := discordgo.New("Bot " + config.Bot.Token)
|
||||||
|
|
||||||
go commands.Discommand.LoadCommand(commands.HelpCommand)
|
|
||||||
go commands.Discommand.LoadCommand(commands.DataLengthCommand)
|
|
||||||
go commands.Discommand.LoadCommand(commands.LearnCommand)
|
|
||||||
go commands.Discommand.LoadCommand(commands.LearnedDataListCommand)
|
|
||||||
go commands.Discommand.LoadCommand(commands.InformationCommand)
|
|
||||||
go commands.Discommand.LoadCommand(commands.DeleteLearnedDataCommand)
|
|
||||||
|
|
||||||
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
|
||||||
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
|
||||||
|
|
||||||
go commands.Discommand.LoadModal(modals.PaginationEmbedModal)
|
|
||||||
|
|
||||||
go dg.AddHandler(handler.MessageCreate)
|
go dg.AddHandler(handler.MessageCreate)
|
||||||
go dg.AddHandler(handler.InteractionCreate)
|
go dg.AddHandler(handler.InteractionCreate)
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,13 @@ type MessageCreate struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageSender struct {
|
type MessageSender struct {
|
||||||
Embeds []*discordgo.MessageEmbed
|
Embeds []*discordgo.MessageEmbed
|
||||||
Content string
|
Content string
|
||||||
Components []discordgo.MessageComponent
|
Components []discordgo.MessageComponent
|
||||||
Ephemeral bool
|
Ephemeral bool
|
||||||
Reply bool
|
Reply bool
|
||||||
m any
|
AllowedMentions *discordgo.MessageAllowedMentions
|
||||||
|
m any
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessageSender(m any) *MessageSender {
|
func NewMessageSender(m any) *MessageSender {
|
||||||
|
@ -45,6 +46,11 @@ func (s *MessageSender) SetReply(reply bool) *MessageSender {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MessageSender) SetAllowedMentions(allowedMentions discordgo.MessageAllowedMentions) *MessageSender {
|
||||||
|
s.AllowedMentions = &allowedMentions
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MessageSender) Send() {
|
func (s *MessageSender) Send() {
|
||||||
switch m := s.m.(type) {
|
switch m := s.m.(type) {
|
||||||
case *MessageCreate:
|
case *MessageCreate:
|
||||||
|
@ -55,10 +61,11 @@ func (s *MessageSender) Send() {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Session.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
|
m.Session.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
|
||||||
Content: s.Content,
|
Content: s.Content,
|
||||||
Embeds: s.Embeds,
|
Embeds: s.Embeds,
|
||||||
Components: s.Components,
|
Components: s.Components,
|
||||||
Reference: reference,
|
AllowedMentions: s.AllowedMentions,
|
||||||
|
Reference: reference,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
case *InteractionCreate:
|
case *InteractionCreate:
|
||||||
|
@ -83,5 +90,6 @@ func (s *MessageSender) Send() {
|
||||||
Components: s.Components,
|
Components: s.Components,
|
||||||
Flags: flags,
|
Flags: flags,
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue