@@ -54,7 +54,6 @@ func Generate(prompt string) {
54
54
"attachments": []
55
55
}
56
56
}`
57
- fmt .Println (jsonStr )
58
57
req , err := http .NewRequest (http .MethodPost , url , strings .NewReader (jsonStr ))
59
58
if err != nil {
60
59
log .Fatal (err )
@@ -92,10 +91,9 @@ func Upscale(number int, messageid string, imageid string) {
92
91
"session_id": "937a1c8132cd7ce3940aa8f59dedf961",
93
92
"data": {
94
93
"component_type": 2,
95
- "custom_id": "MJ::JOB::upsample::" ` + numberString + `"::" ` + imageid + `"
94
+ "custom_id": "MJ::JOB::upsample::` + numberString + `:: ` + imageid + `"
96
95
}
97
96
}`
98
- fmt .Println (jsonStr )
99
97
req , err := http .NewRequest (http .MethodPost , url , strings .NewReader (jsonStr ))
100
98
if err != nil {
101
99
log .Fatal (err )
@@ -109,14 +107,9 @@ func Upscale(number int, messageid string, imageid string) {
109
107
panic (err )
110
108
}
111
109
defer resp .Body .Close ()
112
-
113
- fmt .Println ("response Status:" , resp .Status )
114
- fmt .Println ("response Headers:" , resp .Header )
115
- body , _ := io .ReadAll (resp .Body )
116
- fmt .Println ("response Body:" , string (body ))
117
110
}
118
111
119
- func UpscaleMax (number int , messageid string , imageid string ) {
112
+ func UpscaleMax (messageid string , imageid string ) {
120
113
url := "https://discord.com/api/v9/interactions"
121
114
server_id := os .Getenv ("SERVER_ID" )
122
115
user_token := os .Getenv ("USER_TOKEN" )
@@ -131,10 +124,9 @@ func UpscaleMax(number int, messageid string, imageid string) {
131
124
"session_id": "1f3dbdf09efdf93d81a3a6420882c92c",
132
125
"data": {
133
126
"component_type": 2,
134
- "custom_id": "MJ::JOB::upsample_max::1::" ` + imageid + `" ::SOLO"
127
+ "custom_id": "MJ::JOB::upsample_max::1::` + imageid + `::SOLO"
135
128
}
136
129
}`
137
- fmt .Println (jsonStr )
138
130
req , err := http .NewRequest (http .MethodPost , url , strings .NewReader (jsonStr ))
139
131
if err != nil {
140
132
log .Fatal (err )
@@ -148,11 +140,6 @@ func UpscaleMax(number int, messageid string, imageid string) {
148
140
panic (err )
149
141
}
150
142
defer resp .Body .Close ()
151
-
152
- fmt .Println ("response Status:" , resp .Status )
153
- fmt .Println ("response Headers:" , resp .Header )
154
- body , _ := io .ReadAll (resp .Body )
155
- fmt .Println ("response Body:" , string (body ))
156
143
}
157
144
158
145
func Variation (number int , messageid string , imageid string ) {
@@ -172,10 +159,9 @@ func Variation(number int, messageid string, imageid string) {
172
159
"session_id": "937a1c8132cd7ce3940aa8f59dedf961",
173
160
"data": {a
174
161
"component_type": 2,
175
- "custom_id": "MJ::JOB::variation::" ` + numberString + `"::" ` + imageid + `"
162
+ "custom_id": "MJ::JOB::variation::` + numberString + `:: ` + imageid + `"
176
163
}
177
164
}`
178
- fmt .Println (jsonStr )
179
165
req , err := http .NewRequest (http .MethodPost , url , strings .NewReader (jsonStr ))
180
166
if err != nil {
181
167
log .Fatal (err )
@@ -196,21 +182,43 @@ func Variation(number int, messageid string, imageid string) {
196
182
fmt .Println ("response Body:" , string (body ))
197
183
}
198
184
199
- func getImageURLByMessageID ( s * discordgo.Session , channelID , messageID string ) (string , error ) {
200
- message , err := s .ChannelMessage (channelID , messageID )
185
+ func getImageFromMessageID ( session * discordgo.Session , channelID , messageID string ) (string , string , error ) {
186
+ message , err := session .ChannelMessage (channelID , messageID )
201
187
if err != nil {
202
- return "" , err
188
+ return "" , "" , fmt . Errorf ( "error retrieving message: %s" , err )
203
189
}
204
190
205
- imageURL := ""
191
+ var imageURL string
192
+ var imageID string
206
193
194
+ // Check if there are any attachments in the message
207
195
if len (message .Attachments ) > 0 {
208
- imageURL = message .Attachments [0 ].URL
196
+ attachment := message .Attachments [0 ]
197
+ imageURL = attachment .URL
198
+ imageID = attachment .ID
199
+ } else {
200
+ // Check if there are any embeds in the message
201
+ if len (message .Embeds ) > 0 {
202
+ embed := message .Embeds [0 ]
203
+
204
+ // Check if the embed contains an image
205
+ if len (embed .Image .URL ) > 0 {
206
+ imageURL = embed .Image .URL
207
+ }
208
+
209
+ // Check if the embed contains an image ID
210
+ if len (embed .Image .ProxyURL ) > 0 {
211
+ imageID = embed .Image .ProxyURL
212
+ }
213
+ }
209
214
}
210
215
211
- if len (message .Embeds ) > 0 && len (message .Embeds [0 ].Image .URL ) > 0 {
212
- imageURL = message .Embeds [0 ].Image .URL
213
- }
216
+ return imageURL , imageID , nil
217
+ }
214
218
215
- return imageURL , nil
219
+ func getImageId (url string ) string {
220
+ arr := strings .Split (url , "_" )
221
+ png := arr [len (arr )- 1 ]
222
+ imageId := strings .Split (png , "." )[0 ]
223
+ return imageId
216
224
}
0 commit comments