-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsCkpt.go
More file actions
48 lines (45 loc) · 1.13 KB
/
lsCkpt.go
File metadata and controls
48 lines (45 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog/log"
)
func lsCkpt(s *discordgo.Session, m *discordgo.MessageCreate) {
log.Info().Str("user", m.Author.Username).Msg("lsCkpt")
reqUrl := k.String("api.url") + "/sdapi/v1/sd-models"
req, err := http.NewRequest("GET", reqUrl, nil)
if err != nil {
log.Error().Err(err).Msg("Error creating request")
return
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Error().Err(err).Msg("Error sending request")
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error().Err(err).Msg("Error reading response")
return
}
type respJsonStr struct {
Title string `json:"title"`
}
var respJson []respJsonStr
err = json.Unmarshal(body, &respJson)
if err != nil {
log.Error().Err(err).Msg("Error unmarshalling response")
return
}
outMsg := "```"
for _, model := range respJson {
outMsg += model.Title + "\n"
}
outMsg += "```"
s.ChannelMessageSendReply(m.ChannelID, outMsg, m.Reference())
}