allow setting the avatar via flag, exit after setting it
This commit is contained in:
parent
889a0c2ccb
commit
8601d4a0f9
23
main.go
23
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -32,11 +33,12 @@ func sendMessage(c *gomatrix.Client, roomID, message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var username, password, userID, accessToken, server, db string
|
var username, password, userID, accessToken, server, db, avatar string
|
||||||
var setup bool
|
var setup bool
|
||||||
|
|
||||||
flag.StringVar(&username, "user", "", "username to connect to matrix server with")
|
flag.StringVar(&username, "user", "", "username to connect to matrix server with")
|
||||||
flag.StringVar(&server, "server", "", "matrix server")
|
flag.StringVar(&server, "server", "", "matrix server")
|
||||||
|
flag.StringVar(&avatar, "avatar", "", "set the avatar of the bot to specified url")
|
||||||
flag.BoolVar(&setup, "s", false, "setup account")
|
flag.BoolVar(&setup, "s", false, "setup account")
|
||||||
flag.StringVar(&db, "db", "mcchunkie.db", "full path to database file")
|
flag.StringVar(&db, "db", "mcchunkie.db", "full path to database file")
|
||||||
|
|
||||||
@ -146,17 +148,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
avatar := "https://deftly.net/mcchunkie.png"
|
if avatar != "" {
|
||||||
aurl, err := cli.GetAvatarURL()
|
|
||||||
|
|
||||||
if aurl != avatar {
|
|
||||||
log.Printf("Setting avatar to: '%s'", avatar)
|
log.Printf("Setting avatar to: '%s'", avatar)
|
||||||
err = cli.SetAvatarURL(avatar)
|
rmu, err := cli.UploadLink(avatar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unable to set avatar: ", err)
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.Printf("avatar already set")
|
err = cli.SetAvatarURL(rmu.ContentURI)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user