fixed form button IDs not getting read
This commit is contained in:
14
cmd_form.go
14
cmd_form.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -146,7 +147,7 @@ var form_command Command = Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var exists bool = true
|
var exists bool = true
|
||||||
formManageID := uuid.New()
|
var formManageID uuid.UUID = uuid.New()
|
||||||
for exists {
|
for exists {
|
||||||
formManageID = uuid.New()
|
formManageID = uuid.New()
|
||||||
exists = getFormManageIdExists(i.GuildID, formManageID)
|
exists = getFormManageIdExists(i.GuildID, formManageID)
|
||||||
@@ -162,7 +163,6 @@ var form_command Command = Command{
|
|||||||
if !(len(options.Options) <= 4) {
|
if !(len(options.Options) <= 4) {
|
||||||
modsCanComment = options.Options[4].BoolValue()
|
modsCanComment = options.Options[4].BoolValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
message, _ := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
|
message, _ := s.ChannelMessageSendComplex(i.ChannelID, &discordgo.MessageSend{
|
||||||
Embed: &discordgo.MessageEmbed{
|
Embed: &discordgo.MessageEmbed{
|
||||||
Color: hexToDecimal(color["primary"]),
|
Color: hexToDecimal(color["primary"]),
|
||||||
@@ -194,8 +194,16 @@ var form_command Command = Command{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ComponentIDs: getFormButtonIDs(),
|
|
||||||
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: i.Interaction.MessageComponentData().CustomID,
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseModal,
|
Type: discordgo.InteractionResponseModal,
|
||||||
|
13
main.go
13
main.go
@@ -25,7 +25,12 @@ func main() {
|
|||||||
godotenv.Load()
|
godotenv.Load()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
connStr := "postgresql://" + os.Getenv("DB_USER") + ":" + url.QueryEscape(os.Getenv("DB_PASSWORD")) + "@" + os.Getenv("DB_SERVER") + ":" + string(os.Getenv("DB_PORT")) + "/" + os.Getenv("DB_NAME") + "?sslmode=disable&application_name=Discord Bot"
|
||||||
|
db, err = sql.Open("postgres", connStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
initTables()
|
||||||
discord, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN"))
|
discord, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error creating Discord session,", err)
|
fmt.Println("error creating Discord session,", err)
|
||||||
@@ -42,12 +47,6 @@ func main() {
|
|||||||
fmt.Println("error opening connection,", err)
|
fmt.Println("error opening connection,", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
connStr := "postgresql://" + os.Getenv("DB_USER") + ":" + url.QueryEscape(os.Getenv("DB_PASSWORD")) + "@" + os.Getenv("DB_SERVER") + ":" + string(os.Getenv("DB_PORT")) + "/" + os.Getenv("DB_NAME") + "?sslmode=disable&application_name=" + discord.State.User.Username
|
|
||||||
db, err = sql.Open("postgres", connStr)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
initTables()
|
|
||||||
fmt.Printf("\nBot is now running as \"%s\"!", discord.State.User.Username)
|
fmt.Printf("\nBot is now running as \"%s\"!", discord.State.User.Username)
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
|
@@ -179,7 +179,7 @@ func removeSticky(guildID string, channelID string) {
|
|||||||
|
|
||||||
func getFormManageIdExists(guildID string, id uuid.UUID) bool {
|
func getFormManageIdExists(guildID string, id uuid.UUID) bool {
|
||||||
var exists bool
|
var exists bool
|
||||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM form_buttons WHERE guild_id = $1 AND form_manage_id = $2)", guildID, id).Scan(&exists)
|
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM form_buttons WHERE form_manage_id = $1)", id).Scan(&exists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ type Command struct {
|
|||||||
ModalIDs []string
|
ModalIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var commands []Command = []Command{tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command, form_command}
|
var commands []Command = []Command{form_command, tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command}
|
||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
fmt.Print("\nStarting up... (May take longer when Discord rate limits the bot)")
|
fmt.Print("\nStarting up... (May take longer when Discord rate limits the bot)")
|
||||||
@@ -72,11 +72,16 @@ func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case discordgo.InteractionMessageComponent:
|
case discordgo.InteractionMessageComponent:
|
||||||
if command.ComponentInteract != nil && slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) {
|
if command.ComponentInteract != nil {
|
||||||
|
if command.Definition.Name == "form" {
|
||||||
|
command.ComponentIDs = getFormButtonIDs()
|
||||||
|
} // FIXME: Makes it dynamic i don't know why it isn't otherwise
|
||||||
|
if slices.Contains(command.ComponentIDs, i.MessageComponentData().CustomID) {
|
||||||
command.ComponentInteract(s, i)
|
command.ComponentInteract(s, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeOldCommandFromAllGuilds(s *discordgo.Session) {
|
func removeOldCommandFromAllGuilds(s *discordgo.Session) {
|
||||||
|
Reference in New Issue
Block a user