Nachrichten-Header konfigurierbar gemacht
This commit is contained in:
14
README.md
14
README.md
@@ -35,12 +35,18 @@ command_prefix: ntfy
|
||||
# Benutzer, die den Bot immer steuern dürfen
|
||||
admins:
|
||||
- "@admin:example.com"
|
||||
|
||||
# Konfigurierbarer Nachrichten-Header
|
||||
message_prefix: "Ntfy message in topic"
|
||||
message_topic_display: "full"
|
||||
```
|
||||
|
||||
| Einstellung | Beschreibung |
|
||||
|------------------|------------------------------------------------------------------------------|
|
||||
| `command_prefix` | Präfix für alle Bot-Befehle (Standard: `ntfy`, Aufruf in Matrix: `!ntfy`) |
|
||||
| `admins` | Liste von Matrix-Benutzern, die den Bot unabhängig vom Power-Level steuern dürfen |
|
||||
| Einstellung | Beschreibung |
|
||||
|--------------------------|------------------------------------------------------------------------------|
|
||||
| `command_prefix` | Präfix für alle Bot-Befehle (Standard: `ntfy`, Aufruf in Matrix: `!ntfy`) |
|
||||
| `admins` | Liste von Matrix-Benutzern, die den Bot unabhängig vom Power-Level steuern dürfen |
|
||||
| `message_prefix` | Text vor der Topic-Info im Nachrichten-Header (Standard: `Ntfy message in topic`). Leer lassen (`""`) um keinen Prefix anzuzeigen. |
|
||||
| `message_topic_display` | Steuert die Anzeige der Topic-Info: `full` (Server/Topic), `topic_only` (nur Topic), `server_only` (nur Server), `none` (nichts) |
|
||||
|
||||
Benutzer, die nicht in der Admin-Liste stehen, benötigen ein Power-Level von mindestens **50** im jeweiligen Raum.
|
||||
|
||||
|
||||
@@ -4,3 +4,14 @@ command_prefix: ntfy
|
||||
# users who can always control this bot
|
||||
admins:
|
||||
- "@admin:example.com"
|
||||
|
||||
# Configurable message header for forwarded ntfy messages.
|
||||
# message_prefix: The text shown before the topic info (default: "Ntfy message in topic")
|
||||
# Set to empty string "" to show no prefix text.
|
||||
# message_topic_display: Controls what topic info is shown. Options:
|
||||
# "full" - server/topic (e.g. ntfy.sh/alerts)
|
||||
# "topic_only" - only the topic name (e.g. alerts)
|
||||
# "server_only" - only the server name (e.g. ntfy.sh)
|
||||
# "none" - no topic info at all
|
||||
message_prefix: "Ntfy message in topic"
|
||||
message_topic_display: "full"
|
||||
|
||||
26
ntfy/bot.py
26
ntfy/bot.py
@@ -227,9 +227,29 @@ class NtfyBot(Plugin):
|
||||
else:
|
||||
emoji = tags = ""
|
||||
|
||||
html_content = "<p><strong>Ntfy message in topic <code>{server}/{topic}</code></strong></p><hr />".format(
|
||||
server=html.escape(server), topic=html.escape(topic)
|
||||
)
|
||||
# Build configurable message header
|
||||
message_prefix = self.config.get("message_prefix", "Ntfy message in topic")
|
||||
topic_display = self.config.get("message_topic_display", "full")
|
||||
|
||||
if topic_display == "full":
|
||||
topic_info = f"<code>{html.escape(server)}/{html.escape(topic)}</code>"
|
||||
elif topic_display == "topic_only":
|
||||
topic_info = f"<code>{html.escape(topic)}</code>"
|
||||
elif topic_display == "server_only":
|
||||
topic_info = f"<code>{html.escape(server)}</code>"
|
||||
else:
|
||||
topic_info = ""
|
||||
|
||||
header_parts = []
|
||||
if message_prefix:
|
||||
header_parts.append(html.escape(message_prefix))
|
||||
if topic_info:
|
||||
header_parts.append(topic_info)
|
||||
|
||||
if header_parts:
|
||||
html_content = "<p><strong>{}</strong></p><hr />".format(" ".join(header_parts))
|
||||
else:
|
||||
html_content = ""
|
||||
# build title
|
||||
if title and click:
|
||||
html_content += (
|
||||
|
||||
@@ -5,3 +5,5 @@ class Config(BaseProxyConfig):
|
||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||
helper.copy("command_prefix")
|
||||
helper.copy("admins")
|
||||
helper.copy("message_prefix")
|
||||
helper.copy("message_topic_display")
|
||||
|
||||
Reference in New Issue
Block a user