diff --git a/app/handlers/functions.go b/app/handlers/functions.go index 6b7d61b..f093f04 100644 --- a/app/handlers/functions.go +++ b/app/handlers/functions.go @@ -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 { diff --git a/app/handlers/handlers.go b/app/handlers/handlers.go index aff1155..1c4ba16 100644 --- a/app/handlers/handlers.go +++ b/app/handlers/handlers.go @@ -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