add support for different page types one can now run telebonk without creating additional accounts!
la-ninpre leobrekalini@gmail.com
Fri, 11 Nov 2022 00:21:55 +0300
2 files changed,
12 insertions(+),
3 deletions(-)
M
changelog.txt
→
changelog.txt
@@ -2,6 +2,7 @@ changelog
=== next ++ added support for different page types (see honk api docs) + added truncation to long honks and donk descriptions + removed TelegramResponse from the honkMap + made gethonks retry 5 times before giving up
M
main.go
→
main.go
@@ -23,6 +23,7 @@ TgBotToken string
TgChatID string TgApiURL string HonkAuthToken string + HonkPage string HonkURL string }@@ -43,6 +44,11 @@ what = "honk_token"
} if c.HonkURL == "" { what = "honk_url" + } + switch c.HonkPage { + case "atme", "longago", "home", "myhonks": + default: + return fmt.Errorf("bad page type: %s", c.HonkPage) } if what != "" { return fmt.Errorf("'%s' shouldn't be empty", what)@@ -335,11 +341,11 @@ tgSendDocument = "sendDocument"
) // getHonks receives and unmarshals some honks from a Honk instance. -func getHonks(after int) ([]*Honk, error) { +func getHonks(page string, after int) ([]*Honk, error) { query := url.Values{} query.Set("token", config.HonkAuthToken) query.Set("action", "gethonks") - query.Set("page", "home") + query.Set("page", page) query.Set("after", strconv.Itoa(after)) resp, err := client.Get(fmt.Sprint(config.HonkURL, "/api?", query.Encode()))@@ -352,6 +358,7 @@ // honk outputs junk like `{ "honks": [ ... ] }`, need to get into the list
var honkJunk map[string][]*Honk err = json.NewDecoder(resp.Body).Decode(&honkJunk) if err != nil { + // FIXME: honk tokens last for a week or so. when one expires, shouldn't this say something meaningful instead of `unexpected v in blah-blah'? log.Print("gethonks: ", resp.Status) return nil, err }@@ -424,6 +431,7 @@ flag.StringVar(&config.TgBotToken, "bot_token", "", "Telegram bot token")
flag.StringVar(&config.TgChatID, "chat_id", "", "Telegram chat_id") flag.StringVar(&config.TgApiURL, "tgapi_url", "https://api.telegram.org", "Telegram API URL") flag.StringVar(&config.HonkAuthToken, "honk_token", "", "Honk auth token") + flag.StringVar(&config.HonkPage, "honk_page", "myhonks", "Page to get honks from. Should be one of [atme, longago, home, myhonks]") flag.StringVar(&config.HonkURL, "honk_url", "", "URL of a Honk instance") flag.Parse()@@ -446,7 +454,7 @@ var retry = 5
log.Print("starting telebonk") // info for { - honks, err := getHonks(0) + honks, err := getHonks(config.HonkPage, 0) if err != nil { log.Print("gethonks:", err) // error retry--