differentiate formatting of messages between channels

This commit is contained in:
vincent 2025-02-19 21:08:46 +01:00
parent 8b60c229a3
commit 44c1d6690d
3 changed files with 25 additions and 17 deletions

View file

@ -37,16 +37,10 @@ class Bridge {
this.log("Broadcasting", msg);
for (const client of this.clients) {
client.broadcast(this.fromatMessageForForward(msg));
client.broadcast(msg);
}
}
fromatMessageForForward(msg) {
const res_msg = { ...msg };
res_msg.text = "<" + msg.author + ">: " + msg.text;
return res_msg;
}
log(...args) {
return console.log("[BRIDGE]", ...args);
}

View file

@ -36,7 +36,8 @@ class DiscordClient extends Client {
if (this.verbose) console.log("[Discord]", ...args);
}
broadcast(msg) {
broadcast(message) {
const msg = this.fromatMessageForForward(message);
for (const chan of this.trackedChannels) {
if (chan != msg.channel) { // do not send in the channel the message is comming from
this.sendTextInChannel(msg.text, chan);
@ -44,6 +45,12 @@ class DiscordClient extends Client {
}
}
fromatMessageForForward(msg) {
const res_msg = { ...msg };
res_msg.text = "[**" + msg.author + "**]: " + msg.text;
return res_msg;
}
sendTextInChannel(text, chan) {
this.channels.cache
.get(chan)

View file

@ -30,21 +30,28 @@ class IRCClient extends Client {
if (this.verbose) console.log("[IRC]", ...args);
}
broadcast(msg) {
broadcast(message) {
const msg = this.fromatMessageForForward(message);
for (const chan of this.channels) {
// do not send in the channel the message is comming from
if (chan != msg.channel) {
// do not send in the channel the message
try {
this.sendTextInChannel(msg.text, chan);
} catch (error) {
this.log("when tryin to send message in ", chan, " got ", error);
}
this.sendTextInChannel(msg.text, chan);
}
}
}
fromatMessageForForward(msg) {
const res_msg = { ...msg };
res_msg.text = "[" + msg.author + "]: " + msg.text;
return res_msg;
}
sendTextInChannel(text, chan) {
this.channel(chan).say(text);
try {
this.channel(chan).say(text);
} catch (error) {
this.log("when tryin to send message in ", chan, " got ", error);
}
}
start() {