mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-03-18 21:50:33 +01:00
ombi: broken discord/telegram linking
doesn't work due to https://github.com/ombi-app/ombi/issues/3484 committing to save progress.
This commit is contained in:
33
ombi/ombi.go
33
ombi/ombi.go
@@ -13,6 +13,11 @@ import (
|
||||
"github.com/hrfee/jfa-go/common"
|
||||
)
|
||||
|
||||
const (
|
||||
NotifAgentDiscord = 1
|
||||
NotifAgentTelegram = 4
|
||||
)
|
||||
|
||||
// Ombi represents a running Ombi instance.
|
||||
type Ombi struct {
|
||||
server, key string
|
||||
@@ -81,7 +86,7 @@ func (ombi *Ombi) getJSON(url string, params map[string]string) (string, int, er
|
||||
}
|
||||
|
||||
// does a POST and optionally returns response as string. Returns a string instead of an io.reader bcs i couldn't get it working otherwise.
|
||||
func (ombi *Ombi) send(mode string, url string, data map[string]interface{}, response bool) (string, int, error) {
|
||||
func (ombi *Ombi) send(mode string, url string, data interface{}, response bool) (string, int, error) {
|
||||
responseText := ""
|
||||
params, _ := json.Marshal(data)
|
||||
req, _ := http.NewRequest(mode, url, bytes.NewBuffer(params))
|
||||
@@ -220,3 +225,29 @@ func (ombi *Ombi) NewUser(username, password, email string, template map[string]
|
||||
ombi.cacheExpiry = time.Now()
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
type NotificationPref struct {
|
||||
Agent int `json:"agent"`
|
||||
UserID string `json:"userId"`
|
||||
Value string `json:"value"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
func (ombi *Ombi) SetNotificationPrefs(user map[string]interface{}, discordID, telegramUser string) (result string, code int, err error) {
|
||||
fmt.Printf("%+v\n", user)
|
||||
url := fmt.Sprintf("%s/api/v1/Identity", ombi.server)
|
||||
id := user["id"].(string)
|
||||
var data []NotificationPref
|
||||
if discordID != "" {
|
||||
data = []NotificationPref{NotificationPref{NotifAgentDiscord, id, discordID, true}}
|
||||
}
|
||||
if telegramUser != "" {
|
||||
data = append(data, NotificationPref{NotifAgentTelegram, id, telegramUser, true})
|
||||
}
|
||||
if _, ok := user["user"]; !ok {
|
||||
user["user"] = map[string]interface{}{}
|
||||
}
|
||||
user["user"].(map[string]interface{})["userNotificationPreferences"] = data
|
||||
result, code, err = ombi.send("PUT", url, user, true)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user