diff --git a/Bridge/class/Bridge.js b/Bridge/class/Bridge.js index cffdad0..d2f8df2 100644 --- a/Bridge/class/Bridge.js +++ b/Bridge/class/Bridge.js @@ -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)) { diff --git a/IRCBot/class/Client.js b/IRCBot/class/Client.js index fbbd671..0ee560c 100644 --- a/IRCBot/class/Client.js +++ b/IRCBot/class/Client.js @@ -1,80 +1,88 @@ const { Client } = require("irc-framework"); class IRCClient extends Client { - constructor(bridge, verbose = false, channels) { - super() - this.bridge = bridge - this.channels = channels - 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}) - }) - } -nick - log(...args) { - if (this.verbose) console.log("[IRC]", ...args) - } + constructor(bridge, verbose = false, channels) { + super(); + this.bridge = bridge; + this.channels = channels.map((chan) => chan.toLowerCase()); + this.verbose = verbose; - start() { - return new Promise((resolve, reject) => { - const timeOutMsg = setTimeout(() => { - this.log("Trying to connect . . . ") - }, 10000) - this.on("connected", () => { - clearTimeout(timeOutMsg) - this.log("Client connected") - for (const channel of this.channels) { - this.join(channel) - } - resolve() - }) + this.on("message", (msg) => { + if (!msg.target) { + return; + } + msg.target = msg.target.toLowerCase(); + if (!channels.includes(msg.target) && msg.nick != this.user.nick) { + return; + } - this.on("join", (channel) => { - this.log(`Joined ${channel.channel}`) - }) + 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); + } - this.on("socket close", () => { - clearTimeout(timeOutMsg) - this.log("Socket closed") - }) + start() { + return new Promise((resolve, reject) => { + const timeOutMsg = setTimeout(() => { + this.log("Trying to connect . . . "); + }, 10000); + this.on("connected", () => { + clearTimeout(timeOutMsg); + this.log("Client connected"); + for (const channel of this.channels) { + this.join(channel); + } + resolve(); + }); - this.on("socket error", (error) => { - clearTimeout(timeOutMsg) - this.log("Socket error: ", error) - }) + this.on("join", (channel) => { + this.log(`Joined ${channel.channel}`); + }); - this.on("irc error", (error) => { - clearTimeout(timeOutMsg) - this.log("IRC error: ", error) - }) + this.on("socket close", () => { + clearTimeout(timeOutMsg); + this.log("Socket closed"); + }); - this.on("error", (error) => { - clearTimeout(timeOutMsg) - this.log("Error: ", error) - }) + this.on("socket error", (error) => { + clearTimeout(timeOutMsg); + this.log("Socket error: ", error); + }); - this.on("close", () => { - clearTimeout(timeOutMsg) - this.log(`Can't connect to ${process.env.IRC_HOST}:${process.env.IRC_PORT}`) - }) + this.on("irc error", (error) => { + clearTimeout(timeOutMsg); + this.log("IRC error: ", error); + }); - try { - this.connect({ - host: process.env.IRC_HOST, - port: process.env.IRC_PORT, - nick: process.env.NICKNAME, - username: process.env.NICKNAME, - tls: true - }) - } catch (error) { - reject(error) - } - }) - } + this.on("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}` + ); + }); + + try { + this.connect({ + host: process.env.IRC_HOST, + port: process.env.IRC_PORT, + nick: process.env.NICKNAME, + username: process.env.NICKNAME, + tls: true, + }); + } catch (error) { + reject(error); + } + }); + } } -module.exports = IRCClient \ No newline at end of file +module.exports = IRCClient; diff --git a/README.md b/README.md index 61d1880..b99d41c 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/config.json b/config.json index 3a266f3..535ee35 100644 --- a/config.json +++ b/config.json @@ -1,9 +1,9 @@ { "verbose": true, "discordChannels": [ - "1161739009614151751", + "1335942797726846989", "727212463988146206", "1207060538341720104" ], - "ircChannels": ["#f2ville.dev"] + "ircChannels": ["#UrLab"] }