Compare commits
No commits in common. "9f4be9e986e096e72da4ede4bbf85e833160870a" and "2a42301c25e4a928a73bd2cfc9cab3e858fd14be" have entirely different histories.
9f4be9e986
...
2a42301c25
@ -3,7 +3,6 @@ token = ""
|
|||||||
appid = ""
|
appid = ""
|
||||||
guildid = ""
|
guildid = ""
|
||||||
category_id = ""
|
category_id = ""
|
||||||
admin_roles = [""]
|
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
host = ""
|
host = ""
|
||||||
@ -12,4 +11,4 @@ name = ""
|
|||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
|
|
||||||
|
admin_roles = [""]
|
||||||
|
182
main.go
182
main.go
@ -1,36 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Username string `json:"username"`
|
|
||||||
Subscription bool `json:"subscription"`
|
|
||||||
Group string `json:"group"`
|
|
||||||
Expiration string `json:"expiration"`
|
|
||||||
Versions []string `json:"versions"`
|
|
||||||
PFP string `json:"pfp"`
|
|
||||||
Message int `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
config Config
|
config Config
|
||||||
client *discordgo.Session
|
client *discordgo.Session
|
||||||
@ -40,6 +23,7 @@ var (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Discord Discord `toml:"discord"`
|
Discord Discord `toml:"discord"`
|
||||||
Database Database `toml:"database"`
|
Database Database `toml:"database"`
|
||||||
|
AdminRoles []string `toml:"admin_roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Discord struct {
|
type Discord struct {
|
||||||
@ -47,7 +31,6 @@ type Discord struct {
|
|||||||
AppID string `toml:"appid"`
|
AppID string `toml:"appid"`
|
||||||
GuildID string `toml:"guildid"`
|
GuildID string `toml:"guildid"`
|
||||||
CategoryID string `toml:"category_id"`
|
CategoryID string `toml:"category_id"`
|
||||||
AdminRoles []string `toml:"admin_roles"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Database struct {
|
type Database struct {
|
||||||
@ -240,22 +223,6 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, baseUrl := getTableNameAndBaseURL(selectedOption)
|
|
||||||
userUID, _ := fetchUserID(userName, baseUrl)
|
|
||||||
if userUID == 0 {
|
|
||||||
err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Content: fmt.Sprintf("Account not found for %s", softwareType),
|
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error sending interaction response:", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, err := client.GuildChannelCreateComplex(guildID, discordgo.GuildChannelCreateData{
|
channel, err := client.GuildChannelCreateComplex(guildID, discordgo.GuildChannelCreateData{
|
||||||
Name: fmt.Sprintf("reset-%s-%s", softwareType, userName),
|
Name: fmt.Sprintf("reset-%s-%s", softwareType, userName),
|
||||||
Type: discordgo.ChannelTypeGuildText,
|
Type: discordgo.ChannelTypeGuildText,
|
||||||
@ -273,14 +240,8 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, roleID := range config.Discord.AdminRoles {
|
for _, roleID := range config.AdminRoles {
|
||||||
if roleID != "" {
|
client.ChannelPermissionSet(channel.ID, roleID, discordgo.PermissionOverwriteTypeRole, discordgo.PermissionViewChannel, 0)
|
||||||
err := client.ChannelPermissionSet(channel.ID, roleID, discordgo.PermissionOverwriteTypeRole, discordgo.PermissionViewChannel|discordgo.PermissionSendMessages, 0)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error setting permissions for role %s: %v", roleID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
@ -303,12 +264,12 @@ var (
|
|||||||
discordgo.Button{
|
discordgo.Button{
|
||||||
Label: "Accept",
|
Label: "Accept",
|
||||||
Style: discordgo.PrimaryButton,
|
Style: discordgo.PrimaryButton,
|
||||||
CustomID: fmt.Sprintf("accept_%s_%s_%d", userID, softwareType, userUID),
|
CustomID: fmt.Sprintf("accept_%s_%s", userID, softwareType),
|
||||||
},
|
},
|
||||||
discordgo.Button{
|
discordgo.Button{
|
||||||
Label: "Decline",
|
Label: "Decline",
|
||||||
Style: discordgo.DangerButton,
|
Style: discordgo.DangerButton,
|
||||||
CustomID: fmt.Sprintf("decline_%s_%s_%d", userID, softwareType, userUID),
|
CustomID: fmt.Sprintf("decline_%s_%s", userID, softwareType),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -322,13 +283,12 @@ var (
|
|||||||
"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
data := i.MessageComponentData().CustomID
|
data := i.MessageComponentData().CustomID
|
||||||
parts := strings.Split(data, "_")
|
parts := strings.Split(data, "_")
|
||||||
if len(parts) != 4 {
|
if len(parts) != 3 {
|
||||||
log.Println("Invalid accept button custom ID")
|
log.Println("Invalid accept button custom ID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userID := parts[1]
|
userID := parts[1]
|
||||||
softwareType := parts[2]
|
softwareType := parts[2]
|
||||||
userUID, _ := strconv.Atoi(parts[3])
|
|
||||||
|
|
||||||
member, err := client.GuildMember(i.GuildID, userID)
|
member, err := client.GuildMember(i.GuildID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -338,13 +298,6 @@ var (
|
|||||||
userName := getUsernameFromMember(member)
|
userName := getUsernameFromMember(member)
|
||||||
|
|
||||||
reset(userName, softwareType)
|
reset(userName, softwareType)
|
||||||
tableName, _ := getTableNameAndBaseURL(strings.ToLower(softwareType))
|
|
||||||
|
|
||||||
_, err = resetAndVerify(tableName, int(userUID))
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Error resetting hwid:", err)
|
|
||||||
}
|
|
||||||
log.Printf("Reset the HWID of user %s with UID %d for %s", userName, userUID, softwareType)
|
|
||||||
|
|
||||||
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
err = client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
@ -377,7 +330,7 @@ var (
|
|||||||
"decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
"decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
data := i.MessageComponentData().CustomID
|
data := i.MessageComponentData().CustomID
|
||||||
parts := strings.Split(data, "_")
|
parts := strings.Split(data, "_")
|
||||||
if len(parts) != 4 {
|
if len(parts) != 3 {
|
||||||
log.Println("Invalid decline button custom ID")
|
log.Println("Invalid decline button custom ID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -432,125 +385,6 @@ func canCreateTicket(userName, softwareType string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTableNameAndBaseURL(choice string) (string, string) {
|
|
||||||
var tableName, baseURL string
|
|
||||||
|
|
||||||
switch choice {
|
|
||||||
case "vanity":
|
|
||||||
tableName = "AuthUserData"
|
|
||||||
baseURL = "http://vanitycheats.xyz/UserAuthentication.php"
|
|
||||||
case "mesa":
|
|
||||||
tableName = "AuthUserData-Mesachanger.com"
|
|
||||||
baseURL = "http://mesachanger.com/UserAuthentication.php"
|
|
||||||
default:
|
|
||||||
fmt.Println("Invalid choice. Please choose 'vanity' or 'mesa'.")
|
|
||||||
}
|
|
||||||
|
|
||||||
return tableName, baseURL
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchUserID(username string, baseURL string) (int, error) {
|
|
||||||
requestBody := &bytes.Buffer{}
|
|
||||||
multiPartWriter := multipart.NewWriter(requestBody)
|
|
||||||
err := multiPartWriter.WriteField("username", username)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error adding username field: %w", err)
|
|
||||||
}
|
|
||||||
multiPartWriter.Close()
|
|
||||||
request, err := http.NewRequest("POST", baseURL, requestBody)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error creating request: %w", err)
|
|
||||||
}
|
|
||||||
request.Header.Set("Content-Type", multiPartWriter.FormDataContentType())
|
|
||||||
client := &http.Client{
|
|
||||||
Timeout: 10 * time.Second,
|
|
||||||
}
|
|
||||||
resp, err := client.Do(request)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error sending request: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
var userResp UserResponse
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&userResp)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error decoding JSON: %w", err)
|
|
||||||
}
|
|
||||||
uid, err := strconv.Atoi(userResp.ID)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error converting user ID: %w", err)
|
|
||||||
}
|
|
||||||
return uid, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func resetHWID(tableName string, uids []int) {
|
|
||||||
query := fmt.Sprintf(`UPDATE public.%q
|
|
||||||
SET "StorageIdentifier" = NULL, "BootIdentifier" = NULL
|
|
||||||
WHERE "UID" = ANY($1)`, tableName)
|
|
||||||
|
|
||||||
_, err := db.Exec(query, pq.Array(uids))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error resetting HWID: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
var beforeHash string
|
|
||||||
err := db.QueryRow(
|
|
||||||
fmt.Sprintf(`SELECT MD5(CONCAT("StorageIdentifier", "BootIdentifier")) FROM public.%q WHERE "UID" = $1`, tableName),
|
|
||||||
uid,
|
|
||||||
).Scan(&beforeHash)
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return false, fmt.Errorf("no rows found for UID %d", uid)
|
|
||||||
}
|
|
||||||
return false, fmt.Errorf("error querying database: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resetHWID(tableName, []int{uid})
|
|
||||||
|
|
||||||
var afterHash string
|
|
||||||
err = db.QueryRow(
|
|
||||||
fmt.Sprintf(`SELECT MD5(CONCAT("StorageIdentifier", "BootIdentifier")) FROM public.%q WHERE "UID" = $1`, tableName),
|
|
||||||
uid,
|
|
||||||
).Scan(&afterHash)
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return false, fmt.Errorf("no rows found for UID %d after reset", uid)
|
|
||||||
}
|
|
||||||
return false, fmt.Errorf("error querying database after reset: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return beforeHash != afterHash, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
log.Println("Bot client is not initialized")
|
log.Println("Bot client is not initialized")
|
||||||
|
Loading…
Reference in New Issue
Block a user