From 64b50461b830f14d3c43ed8ebc271b22b1c121da Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 25 Jul 2021 14:39:53 +0200 Subject: [PATCH] Document presence module Signed-off-by: Knut Ahlers --- mod_presence.go | 15 ++++++++++++++- wiki/Home.md | 10 ++++++++++ wiki/Home.md.tpl | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mod_presence.go b/mod_presence.go index 17a81cd..503a216 100644 --- a/mod_presence.go +++ b/mod_presence.go @@ -12,6 +12,11 @@ import ( log "github.com/sirupsen/logrus" ) +/* + * @module presence + * @module_desc Updates the presence status of the bot to display the next stream + */ + func init() { RegisterModule("presence", func() module { return &modPresence{} }) } @@ -25,6 +30,13 @@ func (m *modPresence) Initialize(crontab *cron.Cron, discord *discordgo.Session, m.attrs = attrs m.discord = discord + if err := attrs.Expect( + "fallback_text", + ); err != nil { + return errors.Wrap(err, "validating attributes") + } + + // @attr cron optional string "* * * * *" When to execute the module if _, err := crontab.AddFunc(attrs.MustString("cron", ptrString("* * * * *")), m.cronUpdatePresence); err != nil { return errors.Wrap(err, "adding cron function") } @@ -37,7 +49,8 @@ func (m modPresence) cronUpdatePresence() { // FIXME: Get next stream status - status := "mit Seelen" + // @attr fallback_text required string "" What to set the text to when no stream is found (`playing `) + status := m.attrs.MustString("fallback_text", nil) if nextStream != nil { status = fmt.Sprintf("in: %s", m.durationToHumanReadable(time.Since(*nextStream))) } diff --git a/wiki/Home.md b/wiki/Home.md index c90f613..54c97c5 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -16,6 +16,15 @@ module_configs: # Modules +## Type: `presence` + +Updates the presence status of the bot to display the next stream + +| Attribute | Req. | Type | Default Value | Description | +| --------- | :--: | ---- | ------------- | ----------- | +| `fallback_text` | ✅ | string | | What to set the text to when no stream is found (`playing `) | +| `cron` | | string | `* * * * *` | When to execute the module | + ## Type: `schedule` Posts stream schedule derived from Twitch schedule as embed in Discord channel @@ -37,4 +46,5 @@ Posts stream schedule derived from Twitch schedule as embed in Discord channel | `schedule_past_time` | | duration | `15m` | How long in the past should the schedule contain an entry | + diff --git a/wiki/Home.md.tpl b/wiki/Home.md.tpl index bfd79e9..604f73a 100644 --- a/wiki/Home.md.tpl +++ b/wiki/Home.md.tpl @@ -26,6 +26,7 @@ module_configs: {%- for attr in module.attributes %} | `{{ attr.name }}` | {% if attr.required == 'required' %}✅{% endif %} | {{ attr.type }} | {% if attr.default != "" %}`{{ attr.default }}`{% endif %} | {{ attr.description }} | {%- endfor %} + {% endfor %}