aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2022-11-11 00:21:55 +0300
committerla-ninpre <leobrekalini@gmail.com>2022-11-11 00:21:55 +0300
commit580c49d3ab4639f4ee2440ab71af15a8d91ac7b3 (patch)
tree628a187e20d06bd0d4722df29d70c2d93d74bfc6
parentf327676a42240686c81c8898e99f2bd2896a9207 (diff)
downloadtelebonk-580c49d3ab4639f4ee2440ab71af15a8d91ac7b3.tar.gz
telebonk-580c49d3ab4639f4ee2440ab71af15a8d91ac7b3.zip
add support for different page types
one can now run telebonk without creating additional accounts!
-rw-r--r--changelog.txt1
-rw-r--r--main.go14
2 files changed, 12 insertions, 3 deletions
diff --git a/changelog.txt b/changelog.txt
index e46a447..0a1de60 100644
--- a/changelog.txt
+++ b/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
diff --git a/main.go b/main.go
index a7c29a8..5837260 100644
--- a/main.go
+++ b/main.go
@@ -23,6 +23,7 @@ type Config struct {
TgChatID string
TgApiURL string
HonkAuthToken string
+ HonkPage string
HonkURL string
}
@@ -44,6 +45,11 @@ func (c *Config) Check() error {
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 @@ const (
)
// 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 @@ func getHonks(after int) ([]*Honk, error) {
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 @@ func init() {
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 @@ func main() {
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--