Impl individual reset
This commit is contained in:
parent
bc6dc28b0a
commit
afca685481
119
main.go
119
main.go
@ -144,6 +144,28 @@ var (
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "reset",
|
||||
Description: "Reset a user's HWID by username or UID",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "identifier",
|
||||
Description: "Username or UID",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "cheat_type",
|
||||
Description: "Type of cheat (mesa or vanity)",
|
||||
Required: true,
|
||||
Choices: []*discordgo.ApplicationCommandOptionChoice{
|
||||
{Name: "mesa", Value: "mesa"},
|
||||
{Name: "vanity", Value: "vanity"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
commandsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"setup": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
@ -209,6 +231,101 @@ var (
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
},
|
||||
"reset": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
hasAdminPermission := false
|
||||
for _, roleID := range config.Discord.AdminRoles {
|
||||
member, err := client.GuildMember(i.GuildID, i.Member.User.ID)
|
||||
if err != nil {
|
||||
log.Println("Error fetching member info:", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, role := range member.Roles {
|
||||
if role == roleID {
|
||||
hasAdminPermission = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if hasAdminPermission {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !hasAdminPermission {
|
||||
err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "You do not have permission to run this command.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
identifier := i.ApplicationCommandData().Options[0].StringValue()
|
||||
cheatType := i.ApplicationCommandData().Options[1].StringValue()
|
||||
var userName string
|
||||
var userUID int
|
||||
|
||||
if uid, err := strconv.Atoi(identifier); err == nil {
|
||||
userUID = uid
|
||||
} else {
|
||||
userName = identifier
|
||||
}
|
||||
|
||||
var tableName string
|
||||
var baseURL string
|
||||
var err error
|
||||
|
||||
if userName != "" {
|
||||
_, baseURL = getTableNameAndBaseURL(cheatType)
|
||||
userUID, err = fetchUserID(userName, baseURL)
|
||||
if err != nil {
|
||||
log.Println("Error fetching user ID:", err)
|
||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Error fetching user ID.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tableName, _ = getTableNameAndBaseURL(cheatType)
|
||||
success, err := resetAndVerify(tableName, userUID)
|
||||
if err != nil || !success {
|
||||
log.Println("Error resetting user:", err)
|
||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Error resetting user.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: fmt.Sprintf("Successfully reset %s's HWID.", identifier),
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error sending interaction response:", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
@ -555,7 +672,7 @@ func resetAndVerify(tableName string, uid int) (bool, error) {
|
||||
return false, fmt.Errorf("error querying database after reset: %v", err)
|
||||
}
|
||||
|
||||
return beforeHash != afterHash, nil
|
||||
return beforeHash != afterHash || afterHash == "d41d8cd98f00b204e9800998ecf8427e", nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user