Compare commits
7 Commits
8b001e499a
...
v1.0.0
Author | SHA1 | Date | |
---|---|---|---|
88ba1cea73 | |||
92f1e3c6ee
|
|||
2e4a30ea01 | |||
3a7e8ae721
|
|||
9f4be9e986 | |||
fa254c60f7
|
|||
00db797d65
|
188
main.go
188
main.go
@ -1,19 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"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 (
|
||||
config Config
|
||||
client *discordgo.Session
|
||||
@ -130,6 +147,39 @@ var (
|
||||
}
|
||||
commandsHandlers = map[string]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)
|
||||
_, err := client.ChannelMessageSendComplex(channelOption.ID, &discordgo.MessageSend{
|
||||
Content: "Click the button below to request a HWID reset:",
|
||||
@ -160,6 +210,7 @@ var (
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
componentsHandlers = map[string]func(client *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"create_ticket": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
err := client.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
@ -223,6 +274,22 @@ var (
|
||||
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{
|
||||
Name: fmt.Sprintf("reset-%s-%s", softwareType, userName),
|
||||
Type: discordgo.ChannelTypeGuildText,
|
||||
@ -241,10 +308,13 @@ var (
|
||||
}
|
||||
|
||||
for _, roleID := range config.Discord.AdminRoles {
|
||||
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)
|
||||
if roleID != "" {
|
||||
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{
|
||||
@ -260,19 +330,19 @@ var (
|
||||
}
|
||||
|
||||
_, 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{
|
||||
discordgo.ActionsRow{
|
||||
Components: []discordgo.MessageComponent{
|
||||
discordgo.Button{
|
||||
Label: "Accept",
|
||||
Style: discordgo.PrimaryButton,
|
||||
CustomID: fmt.Sprintf("accept_%s_%s", userID, softwareType),
|
||||
CustomID: fmt.Sprintf("accept_%s_%s_%d", userID, softwareType, userUID),
|
||||
},
|
||||
discordgo.Button{
|
||||
Label: "Decline",
|
||||
Style: discordgo.DangerButton,
|
||||
CustomID: fmt.Sprintf("decline_%s_%s", userID, softwareType),
|
||||
CustomID: fmt.Sprintf("decline_%s_%s_%d", userID, softwareType, userUID),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -286,12 +356,13 @@ var (
|
||||
"accept": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
data := i.MessageComponentData().CustomID
|
||||
parts := strings.Split(data, "_")
|
||||
if len(parts) != 3 {
|
||||
if len(parts) != 4 {
|
||||
log.Println("Invalid accept button custom ID")
|
||||
return
|
||||
}
|
||||
userID := parts[1]
|
||||
softwareType := parts[2]
|
||||
userUID, _ := strconv.Atoi(parts[3])
|
||||
|
||||
member, err := client.GuildMember(i.GuildID, userID)
|
||||
if err != nil {
|
||||
@ -301,6 +372,13 @@ var (
|
||||
userName := getUsernameFromMember(member)
|
||||
|
||||
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{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
@ -333,7 +411,7 @@ var (
|
||||
"decline": func(client *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
data := i.MessageComponentData().CustomID
|
||||
parts := strings.Split(data, "_")
|
||||
if len(parts) != 3 {
|
||||
if len(parts) != 4 {
|
||||
log.Println("Invalid decline button custom ID")
|
||||
return
|
||||
}
|
||||
@ -388,6 +466,98 @@ func canCreateTicket(userName, softwareType string) bool {
|
||||
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 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() {
|
||||
if client == nil {
|
||||
log.Println("Bot client is not initialized")
|
||||
|
Reference in New Issue
Block a user