From 1e3891bb672069376dc720ac698ceafa9180c865 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 25 Jul 2021 14:26:45 +0200 Subject: [PATCH] Add docs generator Signed-off-by: Knut Ahlers --- Makefile | 16 +++++++++++++++ ci/gendoc.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ ci/requirements.txt | 1 + wiki/Home.md | 27 +++++++++++++++++++++++- wiki/Home.md.tpl | 17 +++++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 ci/gendoc.py create mode 100644 ci/requirements.txt create mode 100644 wiki/Home.md.tpl diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7346dab --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +default: + +gendoc: .venv + .venv/bin/python3 ci/gendoc.py $(shell grep -l '@module ' *.go) >wiki/Home.md + +.venv: + python -m venv .venv + .venv/bin/pip install -r ci/requirements.txt + +# --- Wiki Updates + +pull_wiki: + git subtree pull --prefix=wiki https://github.com/Luzifer/discord-community.wiki.git master --squash + +push_wiki: + git subtree push --prefix=wiki https://github.com/Luzifer/discord-community.wiki.git master diff --git a/ci/gendoc.py b/ci/gendoc.py new file mode 100644 index 0000000..c27d9cc --- /dev/null +++ b/ci/gendoc.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import jinja2 +import sys +import re + + +def main(args): + modules = [] + + for filename in args: + with open(filename, 'r') as codefile: + mod = { + 'attributes': [], + } + + for line in codefile: + match = re.search(r'@module (.*)', line) + if match is not None: + mod['type'] = match[1] + + match = re.search(r'@module_desc (.*)', line) + if match is not None: + mod['description'] = match[1] + + match = re.search( + r'@attr ([^\s]+) ([^\s]+) ([^\s]+) "([^"]*)" (.*)', line) + if match is not None: + mod['attributes'].append({ + 'name': match[1], + 'required': match[2], + 'type': match[3], + 'default': match[4], + 'description': match[5], + }) + + mod['attributes'] = sorted( + mod['attributes'], key=lambda a: ('0' if a['required'] == 'required' else '1') + ':' + a['name']) + + modules.append(mod) + + with open('docs/Home.md.tpl', 'r') as f: + tpl = jinja2.Template(f.read()) + print(tpl.render(modules=modules)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/ci/requirements.txt b/ci/requirements.txt new file mode 100644 index 0000000..7f7afbf --- /dev/null +++ b/ci/requirements.txt @@ -0,0 +1 @@ +jinja2 diff --git a/wiki/Home.md b/wiki/Home.md index 59425a9..e2e4027 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -1 +1,26 @@ -Welcome to the discord-community wiki! +# Discord-Community + +## Modules + +### schedule + +Posts stream schedule derived from Twitch schedule as embed in Discord channel + +| Attribute | Required | Type | Default Value | Description | +| --------- | -------- | ---- | ------------- | ----------- | +| `discord_channel_id` | ✅ | string | | ID of the Discord channel to post the message to | +| `embed_title` | ✅ | string | | Title of the embed (used to find the managed post, must be unique for that channel) | +| `twitch_channel_id` | ✅ | string | | ID (not name) of the channel to fetch the schedule from | +| `twitch_client_id` | ✅ | string | | Twitch client ID the token was issued for | +| `twitch_token` | ✅ | string | | Token for the user the `twitch_channel_id` belongs to | +| `cron` | | string | `*/10 * * * *` | When to execute the schedule transfer | +| `embed_color` | | int64 | `3066993` | Integer representation of the hex color for the embed (default is #2ECC71) | +| `embed_description` | | string | | Description for the embed block | +| `embed_thumbnail_height` | | int64 | | Height of the thumbnail | +| `embed_thumbnail_url` | | string | | Publically hosted image URL to use as thumbnail | +| `embed_thumbnail_width` | | int64 | | Width of the thumbnail | +| `schedule_entries` | | int64 | `5` | How many schedule entries to add to the embed as fields | +| `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 new file mode 100644 index 0000000..3cf28d1 --- /dev/null +++ b/wiki/Home.md.tpl @@ -0,0 +1,17 @@ +# Discord-Community + +## Modules + +{% for module in modules -%} +### {{ module.type }} + +{{ module.description }} + +| Attribute | Required | Type | Default Value | Description | +| --------- | -------- | ---- | ------------- | ----------- | +{%- for attr in module.attributes %} +| `{{ attr.name }}` | {% if attr.required == 'required' %}✅{% endif %} | {{ attr.type }} | {% if attr.default != "" %}`{{ attr.default }}`{% endif %} | {{ attr.description }} | +{%- endfor %} +{% endfor %} + +