37 lines
736 B
Go
37 lines
736 B
Go
package switchcounter
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"within.website/mi/pluralkit"
|
|
)
|
|
|
|
var (
|
|
pkToken = flag.String("pluralkit-token", "", "PluralKit API token")
|
|
pkSystem = flag.String("pluralkit-system-id", "", "PluralKit system ID")
|
|
pkMembers = flag.String("pluralkit-mappings", "", "JSON-encoded map of member -> pluralkit IDs")
|
|
|
|
mappings = map[string]string{}
|
|
)
|
|
|
|
func initMappings() {
|
|
err := json.Unmarshal([]byte(*pkMembers), &mappings)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func replicateToPluralKit(member string) error {
|
|
c := pluralkit.New(*pkToken, http.DefaultClient)
|
|
|
|
id, ok := mappings[member]
|
|
if !ok {
|
|
return fmt.Errorf("unexpected member %s", member)
|
|
}
|
|
|
|
return c.Switch([]string{id})
|
|
}
|