Skip to content

Commit

Permalink
Vary options
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Jan 7, 2024
1 parent 6c96b7e commit 239ef69
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
125 changes: 125 additions & 0 deletions app/handlers/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,131 @@ func Variation(number int, messageid string, imageid string, sess_id string, non
fmt.Println("response Body:", string(body))
}

func VarySubtle(number int, messageid string, imageid string, sess_id string, nonce string) {
numberString := strconv.Itoa(number)
url := "https://discord.com/api/v9/interactions"
server_id := os.Getenv("SERVER_ID")
user_token := os.Getenv("USER_TOKEN")
channel_id := os.Getenv("CHANNEL_ID")
jsonStr := `{
"type": 3,
"nonce": "` + nonce + `",
"guild_id": "` + server_id + `",
"channel_id": "` + channel_id + `",
"message_flags": 0,
"message_id": "` + messageid + `",
"application_id": "936929561302675456",
"session_id": "` + sess_id + `",
"data": {
"component_type": 2,
"custom_id": "MJ::JOB::low_variation::` + numberString + `::` + imageid + `::SOLO"
}
}`
fmt.Println("request json:", jsonStr)
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(jsonStr))
if err != nil {
log.Fatal(err)
}
req.Header.Set("authorization", user_token)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()

fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := io.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))

}

func VaryStrong(number int, messageid string, imageid string, sess_id string, nonce string) {
numberString := strconv.Itoa(number)
url := "https://discord.com/api/v9/interactions"
server_id := os.Getenv("SERVER_ID")
user_token := os.Getenv("USER_TOKEN")
channel_id := os.Getenv("CHANNEL_ID")
jsonStr := `{
"type": 3,
"nonce": "` + nonce + `",
"guild_id": "` + server_id + `",
"channel_id": "` + channel_id + `",
"message_flags": 0,
"message_id": "` + messageid + `",
"application_id": "936929561302675456",
"session_id": "` + sess_id + `",
"data": {
"component_type": 2,
"custom_id": "MJ::JOB::high_variation::` + numberString + `::` + imageid + `::SOLO"
}
}`
fmt.Println("request json:", jsonStr)
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(jsonStr))
if err != nil {
log.Fatal(err)
}
req.Header.Set("authorization", user_token)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()

fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := io.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))

}
func VaryRegion(number int, messageid string, imageid string, sess_id string, nonce string) {
numberString := strconv.Itoa(number)
url := "https://discord.com/api/v9/interactions"
server_id := os.Getenv("SERVER_ID")
user_token := os.Getenv("USER_TOKEN")
channel_id := os.Getenv("CHANNEL_ID")
jsonStr := `{
"type": 3,
"nonce": "` + nonce + `",
"guild_id": "` + server_id + `",
"channel_id": "` + channel_id + `",
"message_flags": 0,
"message_id": "` + messageid + `",
"application_id": "936929561302675456",
"session_id": "` + sess_id + `",
"data": {
"component_type": 2,
"custom_id": "MJ::Inpaint::` + numberString + `::` + imageid + `::SOLO"
}
}`
fmt.Println("request json:", jsonStr)
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(jsonStr))
if err != nil {
log.Fatal(err)
}
req.Header.Set("authorization", user_token)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()

fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := io.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))

}

func getImageFromMessageID(session *discordgo.Session, channelID, messageID string) (string, string, error) {
message, err := session.ChannelMessage(channelID, messageID)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions app/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,53 @@ func AddHandlers(sess *discordgo.Session) {
Variation(number, repliedMessageID, imageID, sess_id, nonce)
}
}
if args[1] == "subtle" {
if m.MessageReference != nil {
repliedMessageID := m.MessageReference.MessageID
imageURL, _, err := getImageFromMessageID(s, os.Getenv("CHANNEL_ID"), repliedMessageID)
imageID := getImageId(imageURL)
if err != nil {
fmt.Println("error", err)
return
}
number, _ := strconv.Atoi(args[2])
sess_id := s.State.SessionID
nonce := fmt.Sprint(rand.Int())
VarySubtle(number, repliedMessageID, imageID, sess_id, nonce)
}
}
if args[1] == "region" {
if m.MessageReference != nil {
repliedMessageID := m.MessageReference.MessageID
imageURL, _, err := getImageFromMessageID(s, os.Getenv("CHANNEL_ID"), repliedMessageID)
imageID := getImageId(imageURL)
if err != nil {
fmt.Println("error", err)
return
}
number, _ := strconv.Atoi(args[2])
sess_id := s.State.SessionID
nonce := fmt.Sprint(rand.Int())
VaryRegion(number, repliedMessageID, imageID, sess_id, nonce)
}
}

if args[1] == "strong" {
if m.MessageReference != nil {
repliedMessageID := m.MessageReference.MessageID
imageURL, _, err := getImageFromMessageID(s, os.Getenv("CHANNEL_ID"), repliedMessageID)
imageID := getImageId(imageURL)
if err != nil {
fmt.Println("error", err)
return
}
number, _ := strconv.Atoi(args[2])
sess_id := s.State.SessionID
nonce := fmt.Sprint(rand.Int())
VaryStrong(number, repliedMessageID, imageID, sess_id, nonce)
}
}

if args[1] == "maxupscale" {
if m.MessageReference != nil {
repliedMessageID := m.MessageReference.MessageID
Expand Down

0 comments on commit 239ef69

Please sign in to comment.