Review my shitty code for discord
by jahy - Saturday July 1, 2023 at 09:11 PM
#1
Shitty code I made in 20 minutes to send discord voice messages on PC w/ your own audio files, nothing special
Please review my code and tell me how bad it is

package main import ( "encoding/base64" "encoding/json" "errors" "fmt" "github.com/go-resty/resty/v2" "os" "path/filepath" ) type CreateAttachmentResponse struct { Attachments []AttachmentResponseAttachment `json:"attachments"` } type AttachmentResponseAttachment struct { Id            int    `json:"id"` UploadUrl      string `json:"upload_url"` UploadFilename string `json:"upload_filename"` } type CreateAttachmentPayload struct { Files []CreateAttachmentFile `json:"files"` } type CreateAttachmentFile struct { FileName string `json:"filename"` FileSize int    `json:"file_size"` Id      string `json:"id"` } type VoiceMessagePayload struct { Content    string                  `json:"content"` ChannelId  string                  `json:"channel_id"` Type        int                      `json:"type"` Flags      int                      `json:"flags"` Attachments []VoiceMessageAttachment `json:"attachments"` Nonce      string                  `json:"nonce"` } type VoiceMessageAttachment struct { Id              string  `json:"id"` Filename        string  `json:"filename"` UploadedFilename string  `json:"uploaded_filename"` DurationSecs    float64 `json:"duration_secs"` Waveform        string  `json:"waveform"` } var audioFileExtensions = []string{".mp3", ".wav", ".ogg", ".aac", ".flac"} var mimeDict = map[string]string{ ".mp3":  "audio/mpeg", ".wav":  "audio/wav", ".ogg":  "audio/ogg", ".aac":  "audio/aac", ".flac": "audio/flac", } type File struct { FileName  string FileType  string FileSize  int FileData  string UploadUrl  string UploadName string } // NewFile creates a new file object, takes a path as an argument // automatically detects the file type and filename, calculates filesize, // then reads and stores the file data // returns a pointer to the new file object func NewFile(path string) (*File, error) { var file File // First get the file name fileName := filepath.Base(path) file.FileName = fileName // Then get the file type and check if it's a valid audio file fileType := filepath.Ext(fileName) if !isStringInSlice(fileType, audioFileExtensions) { return nil, fmt.Errorf("invalid file type: %s", fileType) } file.FileType = fileType // Then get the file size fileInfo, err := os.Stat(path) if err != nil { return nil, err } fileSize := fileInfo.Size() file.FileSize = int(fileSize) // Then read the file data fileData, err := os.ReadFile(path) if err != nil { return nil, err } file.FileData = string(fileData) return &file, nil } // CreateFile creates a new attachment in the specified channel, this is a blank attachment with no data // Use PutFileData to upload the file data to the attachment func (f *File) CreateFile(token, channel string) (CreateAttachmentResponse, error) { url := "https://discord.com/api/v9/channels/" + channel + "/attachments" // Create the payload payload := CreateAttachmentPayload{ Files: []CreateAttachmentFile{ { FileName: f.FileName, FileSize: f.FileSize, Id:      "0", }, }, } jsonPayload, err := json.Marshal(payload) if err != nil { return CreateAttachmentResponse{}, errors.New("error marshalling json payload for create attachment request") } fmt.Println(string(jsonPayload)) headers := returnDiscordMobileCommonHeaders(token) client := resty.New() resp, err := client.R(). SetHeaders(headers). SetBody(jsonPayload). Post(url) if err != nil { return CreateAttachmentResponse{}, errors.New("error sending create attachment request to discord api") } var createAttachmentResponse CreateAttachmentResponse err = json.Unmarshal(resp.Body(), &createAttachmentResponse) if err != nil { return CreateAttachmentResponse{}, errors.New("error unmarshalling create attachment response") } f.UploadUrl = createAttachmentResponse.Attachments[0].UploadUrl f.UploadName = createAttachmentResponse.Attachments[0].UploadFilename return createAttachmentResponse, nil } // PutFileData uploads the file data to the attachment // Use SendFile to send the attachment to the channel func (f *File) PutFileData() error { url := f.UploadUrl headers := map[string]string{ "accept-encoding": "gzip", "connection":      "Keep-Alive", "content-type":    mimeDict[f.FileType], "host":            "discord-attachments-uploads-prd.storage.googleapis.com", "user-agent":      "Discord-Android/175016;RNA", } client := resty.New() _, err := client.R(). SetHeaders(headers). SetBody(f.FileData). Put(url) if err != nil { return errors.New("error sending put attachment request to discord api") } return nil } // SendFile sends a voice message file to a Discord channel using the Discord API // It takes a Discord authentication token and a channel ID as input, encodes a byte array to base64 and creates a JSON payload to send a POST request to the Discord API with the voice message attachment. // Returns an error if there is an issue with the request or JSON encoding. func (f *File) SendFile(token, channel string) error { url := "https://discord.com/api/v9/channels/" + channel + "/messages" // make a byte array of 100 max value bytes var waveformBytes [100]byte // FUNNY PENIS BYTES HAHA // for i := 0; i < 15; i++ { // waveformBytes[i] = 255 // } // // for i := 15; i < 50; i++ { // waveformBytes[i] = 126 // } // // for i := 50; i < 55; i++ { // waveformBytes[i] = 255 // } // // for i := 55; i < 60; i++ { // waveformBytes[i] = 200 // } // // waveformBytes[60] = 100 // waveformBytes[61] = 100 for i := 0; i < 100; i++ { waveformBytes[i] = 255 } // encode the byte array to base64 waveform := base64.StdEncoding.EncodeToString(waveformBytes[:]) // Create the payload payload := VoiceMessagePayload{ Content:  "", ChannelId: channel, Type:      0, Flags:    8192, Attachments: []VoiceMessageAttachment{ { Id:              "0", Filename:        f.FileName, UploadedFilename: f.UploadName, DurationSecs:    100000.00, Waveform:        waveform, }, }, } jsonPayload, err := json.Marshal(payload) if err != nil { return errors.New("error marshalling json payload for send file request") } //fmt.Println(string(jsonPayload)) headers := returnDiscordMobileCommonHeaders(token) client := resty.New() _, err = client.R(). SetHeaders(headers). SetBody(jsonPayload). Post(url) //fmt.Println(string(resp.Body())) if err != nil { return errors.New("error sending send file request to discord api") } return nil } func returnDiscordMobileCommonHeaders(token string) map[string]string { return map[string]string{ "accept-encoding":    "gzip", "authorization":      token, "accept-language":    "en-US", "connection":        "Keep-Alive", "content-type":      "application/json", "host":              "discord.com", "user-agent":        "Discord-Android/175016;RNA", "x-debug-options":    "bugReporterEnabled", "x-discord-locale":  "en-US", "x-super-properties": "eyJvcyI6IkFuZHJvaWQiLCJicm93c2VyIjoiRGlzY29yZCBBbmRyb2lkIiwiZGV2aWNlIjoidmJveDg2cCIsInN5c3RlbV9sb2NhbGUiOiJlbi1VUyIsImNsaWVudF92ZXJzaW9uIjoiMTc1LjE2IC0gcm4iLCJyZWxlYXNlX2NoYW5uZWwiOiJnb29nbGVSZWxlYXNlIiwiZGV2aWNlX3ZlbmRvcl9pZCI6IjlhMDg5ZmRlLWFlYmUtNDIxZC05MjJlLWRlNDAyOGI1OTM5ZSIsImJyb3dzZXJfdXNlcl9hZ2VudCI6IiIsImJyb3dzZXJfdmVyc2lvbiI6IiIsIm9zX3ZlcnNpb24iOiIzMCIsImNsaWVudF9idWlsZF9udW1iZXIiOjE3NTAxNjAwODQ2MTIsImNsaWVudF9ldmVudF9zb3VyY2UiOm51bGwsImRlc2lnbl9pZCI6MH0=", } } func isStringInSlice(str string, slice []string) bool { for _, element := range slice { if element == str { return true } } return false }
SERVICES NOT HQ  Heart
Reply
#2
Discord/10

not so shitty fr
Reply
#3
(07-01-2023, 09:13 PM)xzin0vich Wrote: Discord/10

Real. discord is soooo goood, so secure and private
SERVICES NOT HQ  Heart
Reply
#4
i dont want to learn go but im being forced to learn go. god i fucking hate functional programming
Reply
#5
I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]
Ban reason: Self-Ban | http://raiddfzn73ir6iyxlf7nwytnujiflddog...an-Appeals if you wish to be unbanned in the future. (Permanent)
Reply
#6
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

GRRRRRR
SERVICES NOT HQ  Heart
Reply
#7
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

Ask chat gpt to rate his own code lol (use a good programmation prompt for a complex code and open new chat and ask rate)
Reply
#8
(07-01-2023, 09:24 PM)jahy Wrote:
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

GRRRRRR
Don't worry about it, my friend. ChatGPT can sometimes come up with unexpected responses xD .

(07-01-2023, 09:24 PM)xzin0vich Wrote:
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

Ask chat gpt to rate his own code lol (use a good programmation prompt for a complex code and open new chat and ask rate)

yes ,crazy AI xD
Ban reason: Self-Ban | http://raiddfzn73ir6iyxlf7nwytnujiflddog...an-Appeals if you wish to be unbanned in the future. (Permanent)
Reply
#9
(07-01-2023, 09:28 PM)SuperIdolDeXiaoRong Wrote:
(07-01-2023, 09:24 PM)jahy Wrote:
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

GRRRRRR
Don't worry about it, my friend. ChatGPT can sometimes come up with unexpected responses xD .

(07-01-2023, 09:24 PM)xzin0vich Wrote:
(07-01-2023, 09:18 PM)SuperIdolDeXiaoRong Wrote: I asked ChatGPT to review and rate your code, and it gave it a 3 out of 10. xD
[Image: 3ya8UBT.png]

Ask chat gpt to rate his own code lol (use a good programmation prompt for a complex code and open new chat and ask rate)

yes ,crazy AI xD

I've been flamed by chatgpt
SERVICES NOT HQ  Heart
Reply
#10
Not too bad
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [DISCORD] DM All member bot script iCrayTest 0 89 12-24-2025, 05:59 PM
Last Post: iCrayTest
  Discord Spam Tool itxchiakar 18 2,053 04-09-2025, 09:56 PM
Last Post: douche0982
  discord what ValentinaFAs 1 252 04-09-2025, 09:23 AM
Last Post: 302
  Solaris DNM Source Code King 17 5,038 04-08-2025, 04:14 PM
Last Post: Wok
  Python tip - how to use proxy in exploit code Alegron125 0 216 04-01-2025, 12:55 AM
Last Post: Alegron125



 Users browsing this thread: 1 Guest(s)