Document presence module

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-07-25 14:39:53 +02:00
parent 644eb07404
commit 64b50461b8
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 25 additions and 1 deletions

View file

@ -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 <text>`)
status := m.attrs.MustString("fallback_text", nil)
if nextStream != nil {
status = fmt.Sprintf("in: %s", m.durationToHumanReadable(time.Since(*nextStream)))
}

View file

@ -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 <text>`) |
| `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 |
<!-- vim: set ft=markdown : -->

View file

@ -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 %}
<!-- vim: set ft=markdown : -->