aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe <me@christine.website>2022-04-28 14:52:26 +0000
committerXe <me@christine.website>2022-04-28 14:52:33 +0000
commit568a4096fe0b2f6d3608d445b1bb6076e66dc407 (patch)
tree14201f427edc47406dac8077c24b8b1be8d122af
parent13c2fac196e45288fb0fcac3b151310fb28aa444 (diff)
downloadx-568a4096fe0b2f6d3608d445b1bb6076e66dc407.tar.xz
x-568a4096fe0b2f6d3608d445b1bb6076e66dc407.zip
mastodon/robocadey: loop forever
Signed-off-by: Xe <me@christine.website>
-rw-r--r--mastodon/robocadey/main.go84
1 files changed, 46 insertions, 38 deletions
diff --git a/mastodon/robocadey/main.go b/mastodon/robocadey/main.go
index bd28a23..bef30c7 100644
--- a/mastodon/robocadey/main.go
+++ b/mastodon/robocadey/main.go
@@ -73,50 +73,58 @@ func main() {
ln.FatalErr(ctx, err)
}
- evChan := make(chan madon.StreamEvent, 10)
- stop := make(chan bool)
- done := make(chan bool)
t := time.Tick(4 * time.Hour)
- err = c.StreamListener("user", "", evChan, stop, done)
- if err != nil {
- ln.FatalErr(ctx, err)
- }
+ for {
+ evChan := make(chan madon.StreamEvent, 10)
+ stop := make(chan bool)
+ done := make(chan bool)
- ln.Log(ctx, ln.F{
- "action": "streaming.toots",
- })
+ err = c.StreamListener("user", "", evChan, stop, done)
+ if err != nil {
+ ln.FatalErr(ctx, err)
+ }
- for {
- select {
- case _, ok := <-done:
- if !ok {
- ln.Fatal(ctx, ln.F{"action": "stream.dead"})
- }
+ ln.Log(ctx, ln.F{
+ "action": "streaming.toots",
+ })
- case <-t:
- if _, err := c.PostStatus(madon.PostStatusParams{
- Text: getShitpost(ctx),
- }); err != nil {
- ln.FatalErr(ctx, err)
- }
+ outer:
+ for {
+ select {
+ case _, ok := <-done:
+ if !ok {
+ ln.Fatal(ctx, ln.F{"action": "stream.dead"})
+ }
+
+ case <-t:
+ if _, err := c.PostStatus(madon.PostStatusParams{
+ Text: getShitpost(ctx),
+ }); err != nil {
+ }
- case ev := <-evChan:
- switch ev.Event {
- case "error":
- ln.Fatal(ctx, ln.F{"err": ev.Error, "action": "processing.event"})
- case "notification":
- n := ev.Data.(madon.Notification)
-
- if n.Type == "mention" {
- ln.Log(ctx, ln.F{
- "target": n.Account.Acct,
- })
- if _, err := c.PostStatus(madon.PostStatusParams{
- Text: "@" + n.Account.Acct + " " + getShitpost(ctx),
- InReplyTo: n.Status.ID,
- }); err != nil {
- ln.FatalErr(ctx, err)
+ case ev := <-evChan:
+ switch ev.Event {
+ case "error":
+ ln.Log(ctx, ln.F{"err": ev.Error, "action": "processing.event"})
+ stop <- true
+ close(evChan)
+ close(stop)
+ close(done)
+ break outer
+ case "notification":
+ n := ev.Data.(madon.Notification)
+
+ if n.Type == "mention" {
+ ln.Log(ctx, ln.F{
+ "target": n.Account.Acct,
+ })
+ if _, err := c.PostStatus(madon.PostStatusParams{
+ Text: "@" + n.Account.Acct + " " + getShitpost(ctx),
+ InReplyTo: n.Status.ID,
+ }); err != nil {
+ ln.FatalErr(ctx, err)
+ }
}
}
}