This commit is contained in:
Flummi 2019-11-16 08:30:10 +01:00
parent 5b87f555fa
commit f48e458f55

View File

@ -66,7 +66,7 @@ export default class slack extends EventEmitter {
return this.server.wss.socket.send(JSON.stringify({
type: "message",
channel: channel,
text: text
text: this.format(text)
}));
}
@ -92,4 +92,16 @@ export default class slack extends EventEmitter {
};
}
format(msg) {
return msg.toString()
.split("<").join("&lt;")
.split(">").join("&gt;")
.split("&").join("&amp;")
.replace(/\[b\](.*?)\[\/b\]/g, "*$1*") // bold
.replace(/\[s\](.*?)\[\/s\]/g, "~$1~") // strike
.replace(/\[i\](.*?)\[\/i\]/g, "_$1_") // italic
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2")
;
}
}