make irc chan name case insensitive

This commit is contained in:
vincent 2025-02-11 20:32:04 +01:00
parent 1327bf6f88
commit 64014e73dc
4 changed files with 80 additions and 72 deletions

View file

@ -7,7 +7,7 @@ class Bridge extends EventEmitter {
super()
const verbose = (config.verbose ?? false)
const discordChannels = config.discordChannels
const ircChannels = config.ircChannels
const ircChannels = config.ircChannels.map(chan => chan.toLowerCase())
if (!discordChannels || !ircChannels) {
this.log("Missing channels");
throw new Error("Missing discordChannels or ircChannels")
@ -17,7 +17,7 @@ class Bridge extends EventEmitter {
this.ircClient = new IRCClient(this, verbose, ircChannels)
this.on("message", (msg, channel) => {
this.log("NEW MESSAGE !")
this.log("NEW MESSAGE !", channel)
this.messageListener(msg, channel)
})
}
@ -45,7 +45,7 @@ class Bridge extends EventEmitter {
}
this.log("IRC Channels", this.config)
for (const ichan of this.config.ircChannels) {
for (const ichan of this.ircClient.channels) {
this.log("ICHAN BROADCAST", ichan, msg, excludechan)
if (!(excludechan.type == "irc" && ichan == excludechan.name)) {

View file

@ -2,64 +2,73 @@ const { Client } = require("irc-framework");
class IRCClient extends Client {
constructor(bridge, verbose = false, channels) {
super()
this.bridge = bridge
this.channels = channels
this.verbose = verbose
super();
this.bridge = bridge;
this.channels = channels.map((chan) => chan.toLowerCase());
this.verbose = verbose;
this.on("message", (msg) => {
// this.log(msg)
if (!channels.includes(msg.target) && !channels.includes(msg.channel) && msg.nick != this.user.nick) return
// this.log("Message is okay")
this.bridge.emit("message", msg, {type: "irc", name: msg.target})
})
if (!msg.target) {
return;
}
nick
msg.target = msg.target.toLowerCase();
if (!channels.includes(msg.target) && msg.nick != this.user.nick) {
return;
}
this.log("Message is okay");
this.bridge.emit("message", msg, { type: "irc", name: msg.target });
});
}
nick;
log(...args) {
if (this.verbose) console.log("[IRC]", ...args)
if (this.verbose) console.log("[IRC]", ...args);
}
start() {
return new Promise((resolve, reject) => {
const timeOutMsg = setTimeout(() => {
this.log("Trying to connect . . . ")
}, 10000)
this.log("Trying to connect . . . ");
}, 10000);
this.on("connected", () => {
clearTimeout(timeOutMsg)
this.log("Client connected")
clearTimeout(timeOutMsg);
this.log("Client connected");
for (const channel of this.channels) {
this.join(channel)
this.join(channel);
}
resolve()
})
resolve();
});
this.on("join", (channel) => {
this.log(`Joined ${channel.channel}`)
})
this.log(`Joined ${channel.channel}`);
});
this.on("socket close", () => {
clearTimeout(timeOutMsg)
this.log("Socket closed")
})
clearTimeout(timeOutMsg);
this.log("Socket closed");
});
this.on("socket error", (error) => {
clearTimeout(timeOutMsg)
this.log("Socket error: ", error)
})
clearTimeout(timeOutMsg);
this.log("Socket error: ", error);
});
this.on("irc error", (error) => {
clearTimeout(timeOutMsg)
this.log("IRC error: ", error)
})
clearTimeout(timeOutMsg);
this.log("IRC error: ", error);
});
this.on("error", (error) => {
clearTimeout(timeOutMsg)
this.log("Error: ", error)
})
clearTimeout(timeOutMsg);
this.log("Error: ", error);
});
this.on("close", () => {
clearTimeout(timeOutMsg)
this.log(`Can't connect to ${process.env.IRC_HOST}:${process.env.IRC_PORT}`)
})
clearTimeout(timeOutMsg);
this.log(
`Can't connect to ${process.env.IRC_HOST}:${process.env.IRC_PORT}`
);
});
try {
this.connect({
@ -67,14 +76,13 @@ nick
port: process.env.IRC_PORT,
nick: process.env.NICKNAME,
username: process.env.NICKNAME,
tls: true
})
tls: true,
});
} catch (error) {
reject(error)
reject(error);
}
})
});
}
}
module.exports = IRCClient
module.exports = IRCClient;

View file

@ -15,7 +15,7 @@ docker build -t urbridge:latest .
run un container temporaire (pour l'instant le bot ne sauve aucune data, donc il n'y a pas d'inconvénient à le recréer à chaque démarrage et delete quand il est arêté):
```bash
docker run -t urlab_viaduk --rm --env-file .env urbridge:latest
docker run --name urlab_viaduk --rm --env-file .env urbridge:latest
```
il faut un fichier .env spécifiant les variables suivantes:

View file

@ -1,9 +1,9 @@
{
"verbose": true,
"discordChannels": [
"1161739009614151751",
"1335942797726846989",
"727212463988146206",
"1207060538341720104"
],
"ircChannels": ["#f2ville.dev"]
"ircChannels": ["#UrLab"]
}