Make sure users can't send multiple vetting requests
This commit is contained in:
parent
dd550b10cf
commit
a5933b2a97
@ -19,11 +19,11 @@
|
||||
package db
|
||||
|
||||
func AddVettingReq(guildID, userID, msgID string) error {
|
||||
_, err := db.Exec("INSERT OR ABORT INTO vetting_requests (guild_id, user_id, msg_id) VALUES (?, ?, ?)", guildID, userID, msgID)
|
||||
_, err := db.Exec("INSERT INTO vetting_requests (guild_id, user_id, msg_id) VALUES (?, ?, ?)", guildID, userID, msgID)
|
||||
return err
|
||||
}
|
||||
|
||||
func VettingReqID(guildID, userID string) (string, error) {
|
||||
func VettingReqMsgID(guildID, userID string) (string, error) {
|
||||
var out string
|
||||
row := db.QueryRowx("SELECT msg_id FROM vetting_requests WHERE user_id = ? AND guild_id = ?", userID, guildID)
|
||||
err := row.Scan(&out)
|
||||
@ -37,7 +37,7 @@ func VettingReqUserID(guildID, msgID string) (string, error) {
|
||||
return out, err
|
||||
}
|
||||
|
||||
func RemoveVettingReq(guildID, userID string) error {
|
||||
_, err := db.Exec("DELETE FROM vetting_requests WHERE user_id = ? AND guild_id = ?", userID, guildID)
|
||||
func RemoveVettingReq(guildID, msgID string) error {
|
||||
_, err := db.Exec("DELETE FROM vetting_requests WHERE msg_id = ? AND guild_id = ?", msgID, guildID)
|
||||
return err
|
||||
}
|
||||
|
@ -137,6 +137,11 @@ func onVettingRequest(s *discordgo.Session, i *discordgo.InteractionCreate) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := db.VettingReqMsgID(i.GuildID, i.Member.User.ID)
|
||||
if err == nil {
|
||||
return errors.New("you've already sent a vetting request")
|
||||
}
|
||||
|
||||
guild, err := db.GuildByID(i.GuildID)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -161,7 +166,7 @@ func onVettingRequest(s *discordgo.Session, i *discordgo.InteractionCreate) erro
|
||||
|
||||
eventlog.AddTimeToEmbed(guild.TimeFormat, embed)
|
||||
|
||||
_, err = s.ChannelMessageSendComplex(guild.VettingReqChanID, &discordgo.MessageSend{
|
||||
msg, err := s.ChannelMessageSendComplex(guild.VettingReqChanID, &discordgo.MessageSend{
|
||||
Embeds: []*discordgo.MessageEmbed{embed},
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.ActionsRow{Components: []discordgo.MessageComponent{
|
||||
@ -184,6 +189,11 @@ func onVettingRequest(s *discordgo.Session, i *discordgo.InteractionCreate) erro
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AddVettingReq(i.GuildID, i.Member.User.ID, msg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return util.RespondEphemeral(s, i.Interaction, "Successfully sent your vetting request!")
|
||||
}
|
||||
|
||||
@ -335,5 +345,6 @@ func onVettingResponse(s *discordgo.Session, i *discordgo.InteractionCreate) err
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return db.RemoveVettingReq(i.GuildID, i.Message.ID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user