Allow management command replies to contain markdown/HTML

Fixes #2
This commit is contained in:
Tulir Asokan
2017-11-25 14:45:21 +02:00
parent ae71433743
commit 03c9eb44f9
4 changed files with 225 additions and 20 deletions
+19 -3
View File
@@ -14,6 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
const { Bridge } = require("matrix-appservice-bridge")
const escapeHTML = require("escape-html")
const sanitizeHTML = require("sanitize-html")
const marked = require("marked")
const commands = require("./commands")
const MatrixUser = require("./matrix-user")
const TelegramUser = require("./telegram-user")
@@ -335,9 +338,22 @@ class MautrixTelegram {
.split(" ")
const command = args.shift()
commands.run(user, command, args,
reply => this.botIntent.sendText(
evt.room_id,
reply.replace("$cmdprefix", cmdprefix)),
(reply, { allowHTML = false, markdown = true } = {}) => {
reply = reply.replace("$cmdprefix", cmdprefix)
if (!allowHTML) {
reply = escapeHTML(reply)
}
if (markdown) {
reply = marked(reply)
}
this.botIntent.sendMessage(
evt.room_id, {
body: sanitizeHTML(reply),
formatted_body: reply,
msgtype: "m.notice",
format: "org.matrix.custom.html",
})
},
this)
return
}
+9 -6
View File
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
const makePasswordHash = require("telegram-mtproto").plugins.makePasswordHash
const escapeHTML = require("escape-html")
const commands = {}
@@ -46,14 +47,16 @@ function run(sender, command, args, reply, app) {
commands.cancel = () => "Nothing to cancel."
commands.help = (sender, args, reply) => {
reply(`All commands are prefixed with $cmdprefix.
reply(`All commands are prefixed with **$cmdprefix**.
help - Show this help message.
cancel - Cancel an ongoing action (such as login).
login <phone> - Request an authentication code.
logout - Log out from Telegram.
**help** - Show this help message.<br/>
**cancel** - Cancel an ongoing action (such as login).
api <method> <args> - Call a Telegram API method. Args is always a JSON object. Disabled by default.`)
**login** <_phone_> - Request an authentication code.<br/>
**logout** - Log out from Telegram. Currently broken.
**api** <_method_> <_args_> - Call a Telegram API method. Args is always a JSON object. Disabled by default.
`, {allowHTML: true})
}