forwarder: limit maximum IRC nickname length

This commit is contained in:
Peter Cai 2021-01-16 20:58:43 +08:00
parent 3817b190a6
commit a2179f888a

View file

@ -54,6 +54,14 @@ module.exports = class Forwarder {
this.clientMatrix.sendMessage(this.mappingI2M[event.target], content); this.clientMatrix.sendMessage(this.mappingI2M[event.target], content);
} }
stripMatrixName(name) {
if (name.length < 16) {
return name;
} else {
return name.slice(0, 16);
}
}
onMatrixMessage(event, room, toStartOfTimeline) { onMatrixMessage(event, room, toStartOfTimeline) {
if (toStartOfTimeline) { if (toStartOfTimeline) {
return; // Ignore pagniation return; // Ignore pagniation
@ -87,11 +95,12 @@ module.exports = class Forwarder {
} }
if (msgTxt != null) { if (msgTxt != null) {
let name = this.stripMatrixName(event.sender.name);
if (content.msgtype == "m.emote") { if (content.msgtype == "m.emote") {
// Special format for emote // Special format for emote
this.clientIRC.say(this.mappingM2I[room.roomId], `* ${event.sender.name} ${msgTxt}`); this.clientIRC.say(this.mappingM2I[room.roomId], `* ${name} ${msgTxt}`);
} else { } else {
this.clientIRC.say(this.mappingM2I[room.roomId], `[${event.sender.name}] ${msgTxt}`); this.clientIRC.say(this.mappingM2I[room.roomId], `[${name}] ${msgTxt}`);
} }
} }
} }