Compare commits
	
		
			4 Commits
		
	
	
		
			fa254c60f7
			...
			refactorin
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						92f1e3c6ee
	
				 | 
					
					
						|||
| 2e4a30ea01 | |||
| 
						
						
							
						
						3a7e8ae721
	
				 | 
					
					
						|||
| 9f4be9e986 | 
							
								
								
									
										63
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								main.go
									
									
									
									
									
								
							@@ -147,6 +147,39 @@ var (
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	commandsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
 | 
						commandsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
 | 
				
			||||||
		"setup": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
 | 
							"setup": 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
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			channelOption := i.ApplicationCommandData().Options[0].ChannelValue(client)
 | 
								channelOption := i.ApplicationCommandData().Options[0].ChannelValue(client)
 | 
				
			||||||
			_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
 | 
								_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
 | 
				
			||||||
				Content: "Click the button below to request a HWID reset:",
 | 
									Content: "Click the button below to request a HWID reset:",
 | 
				
			||||||
@@ -177,6 +210,7 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
 | 
						componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
 | 
				
			||||||
		"create_ticket": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
 | 
							"create_ticket": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
 | 
				
			||||||
			err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
								err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
 | 
				
			||||||
@@ -296,7 +330,7 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			_, err = client.ChannelMessageSendComplex(channel.ID, &discordgo.MessageSend{
 | 
								_, err = client.ChannelMessageSendComplex(channel.ID, &discordgo.MessageSend{
 | 
				
			||||||
				Content: fmt.Sprintf("Reset request by %s for %s", userName, softwareType),
 | 
									Content: fmt.Sprintf("Reset request by <@%s> for %s", userID, softwareType),
 | 
				
			||||||
				Components: []discordgo.MessageComponent{
 | 
									Components: []discordgo.MessageComponent{
 | 
				
			||||||
					discordgo.ActionsRow{
 | 
										discordgo.ActionsRow{
 | 
				
			||||||
						Components: []discordgo.MessageComponent{
 | 
											Components: []discordgo.MessageComponent{
 | 
				
			||||||
@@ -494,33 +528,6 @@ func resetHWID(tableName string, uids []int) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func getIdentifiers(tableName string, uid int) {
 | 
					 | 
				
			||||||
	query := fmt.Sprintf(`SELECT "StorageIdentifier", "BootIdentifier"
 | 
					 | 
				
			||||||
		FROM public.%q
 | 
					 | 
				
			||||||
		WHERE "UID" = $1`, tableName)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var storageIdentifier, bootIdentifier sql.NullString
 | 
					 | 
				
			||||||
	err := db.QueryRow(query, uid).Scan(&storageIdentifier, &bootIdentifier)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		if err == sql.ErrNoRows {
 | 
					 | 
				
			||||||
			fmt.Println("HWID not set")
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		fmt.Println("Error querying the database:", err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !storageIdentifier.Valid {
 | 
					 | 
				
			||||||
		storageIdentifier = sql.NullString{String: "NULL", Valid: false}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !bootIdentifier.Valid {
 | 
					 | 
				
			||||||
		bootIdentifier = sql.NullString{String: "NULL", Valid: false}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Printf("UID: %d, S: %s, B: %s\n", uid, storageIdentifier.String, bootIdentifier.String)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func resetAndVerify(tableName string, uid int) (bool, error) {
 | 
					func resetAndVerify(tableName string, uid int) (bool, error) {
 | 
				
			||||||
	var beforeHash string
 | 
						var beforeHash string
 | 
				
			||||||
	err := db.QueryRow(
 | 
						err := db.QueryRow(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user