From a6bd561c7c6ccd28e271748e5bfd943b917e4083 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 27 Nov 2017 18:42:00 +0200 Subject: [PATCH] Allow disabling (prefixed) commands in non-management rooms --- example-config.yaml | 1 + src/app.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/example-config.yaml b/example-config.yaml index 75cff798..44b3a9c2 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -29,6 +29,7 @@ bridge: # Bridge management command configuration commands: # The prefix for all management commands. + # Can be removed to disable management commands in rooms with more than two users. prefix: "!tg" # Enables the !tg api ... commands for debugging. diff --git a/src/app.js b/src/app.js index be9f0617..30b4e3ee 100644 --- a/src/app.js +++ b/src/app.js @@ -501,15 +501,15 @@ class MautrixTelegram { } } const cmdprefix = this.config.bridge.commands.prefix - if (isManagement || evt.content.body.startsWith(`${cmdprefix} `)) { + if (isManagement || (cmdprefix && evt.content.body.startsWith(`${cmdprefix} `))) { const prefixLength = cmdprefix.length + 1 - if (evt.content.body.startsWith(`${cmdprefix} `)) { + if (cmdprefix && evt.content.body.startsWith(`${cmdprefix} `)) { evt.content.body = evt.content.body.substr(prefixLength) } const args = evt.content.body.split(" ") const command = args.shift() const replyFunc = (reply, { allowHTML = false, markdown = true } = {}) => { - reply = reply.replace("$cmdprefix", cmdprefix) + reply = reply.replace("$cmdprefix", cmdprefix || "") if (!markdown && !allowHTML) { reply = escapeHTML(reply) }