make irc chan name case insensitive
This commit is contained in:
parent
1327bf6f88
commit
64014e73dc
4 changed files with 80 additions and 72 deletions
|
|
@ -7,7 +7,7 @@ class Bridge extends EventEmitter {
|
||||||
super()
|
super()
|
||||||
const verbose = (config.verbose ?? false)
|
const verbose = (config.verbose ?? false)
|
||||||
const discordChannels = config.discordChannels
|
const discordChannels = config.discordChannels
|
||||||
const ircChannels = config.ircChannels
|
const ircChannels = config.ircChannels.map(chan => chan.toLowerCase())
|
||||||
if (!discordChannels || !ircChannels) {
|
if (!discordChannels || !ircChannels) {
|
||||||
this.log("Missing channels");
|
this.log("Missing channels");
|
||||||
throw new Error("Missing discordChannels or ircChannels")
|
throw new Error("Missing discordChannels or ircChannels")
|
||||||
|
|
@ -17,7 +17,7 @@ class Bridge extends EventEmitter {
|
||||||
this.ircClient = new IRCClient(this, verbose, ircChannels)
|
this.ircClient = new IRCClient(this, verbose, ircChannels)
|
||||||
|
|
||||||
this.on("message", (msg, channel) => {
|
this.on("message", (msg, channel) => {
|
||||||
this.log("NEW MESSAGE !")
|
this.log("NEW MESSAGE !", channel)
|
||||||
this.messageListener(msg, channel)
|
this.messageListener(msg, channel)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +45,7 @@ class Bridge extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log("IRC Channels", this.config)
|
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)
|
this.log("ICHAN BROADCAST", ichan, msg, excludechan)
|
||||||
if (!(excludechan.type == "irc" && ichan == excludechan.name)) {
|
if (!(excludechan.type == "irc" && ichan == excludechan.name)) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,64 +2,73 @@ const { Client } = require("irc-framework");
|
||||||
|
|
||||||
class IRCClient extends Client {
|
class IRCClient extends Client {
|
||||||
constructor(bridge, verbose = false, channels) {
|
constructor(bridge, verbose = false, channels) {
|
||||||
super()
|
super();
|
||||||
this.bridge = bridge
|
this.bridge = bridge;
|
||||||
this.channels = channels
|
this.channels = channels.map((chan) => chan.toLowerCase());
|
||||||
this.verbose = verbose
|
this.verbose = verbose;
|
||||||
|
|
||||||
this.on("message", (msg) => {
|
this.on("message", (msg) => {
|
||||||
// this.log(msg)
|
if (!msg.target) {
|
||||||
if (!channels.includes(msg.target) && !channels.includes(msg.channel) && msg.nick != this.user.nick) return
|
return;
|
||||||
// this.log("Message is okay")
|
|
||||||
this.bridge.emit("message", msg, {type: "irc", name: msg.target})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
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) {
|
log(...args) {
|
||||||
if (this.verbose) console.log("[IRC]", ...args)
|
if (this.verbose) console.log("[IRC]", ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const timeOutMsg = setTimeout(() => {
|
const timeOutMsg = setTimeout(() => {
|
||||||
this.log("Trying to connect . . . ")
|
this.log("Trying to connect . . . ");
|
||||||
}, 10000)
|
}, 10000);
|
||||||
this.on("connected", () => {
|
this.on("connected", () => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log("Client connected")
|
this.log("Client connected");
|
||||||
for (const channel of this.channels) {
|
for (const channel of this.channels) {
|
||||||
this.join(channel)
|
this.join(channel);
|
||||||
}
|
}
|
||||||
resolve()
|
resolve();
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("join", (channel) => {
|
this.on("join", (channel) => {
|
||||||
this.log(`Joined ${channel.channel}`)
|
this.log(`Joined ${channel.channel}`);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("socket close", () => {
|
this.on("socket close", () => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log("Socket closed")
|
this.log("Socket closed");
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("socket error", (error) => {
|
this.on("socket error", (error) => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log("Socket error: ", error)
|
this.log("Socket error: ", error);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("irc error", (error) => {
|
this.on("irc error", (error) => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log("IRC error: ", error)
|
this.log("IRC error: ", error);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("error", (error) => {
|
this.on("error", (error) => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log("Error: ", error)
|
this.log("Error: ", error);
|
||||||
})
|
});
|
||||||
|
|
||||||
this.on("close", () => {
|
this.on("close", () => {
|
||||||
clearTimeout(timeOutMsg)
|
clearTimeout(timeOutMsg);
|
||||||
this.log(`Can't connect to ${process.env.IRC_HOST}:${process.env.IRC_PORT}`)
|
this.log(
|
||||||
})
|
`Can't connect to ${process.env.IRC_HOST}:${process.env.IRC_PORT}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.connect({
|
this.connect({
|
||||||
|
|
@ -67,14 +76,13 @@ nick
|
||||||
port: process.env.IRC_PORT,
|
port: process.env.IRC_PORT,
|
||||||
nick: process.env.NICKNAME,
|
nick: process.env.NICKNAME,
|
||||||
username: process.env.NICKNAME,
|
username: process.env.NICKNAME,
|
||||||
tls: true
|
tls: true,
|
||||||
})
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error)
|
reject(error);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = IRCClient
|
module.exports = IRCClient;
|
||||||
|
|
|
||||||
|
|
@ -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é):
|
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
|
```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:
|
il faut un fichier .env spécifiant les variables suivantes:
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"verbose": true,
|
"verbose": true,
|
||||||
"discordChannels": [
|
"discordChannels": [
|
||||||
"1161739009614151751",
|
"1335942797726846989",
|
||||||
"727212463988146206",
|
"727212463988146206",
|
||||||
"1207060538341720104"
|
"1207060538341720104"
|
||||||
],
|
],
|
||||||
"ircChannels": ["#f2ville.dev"]
|
"ircChannels": ["#UrLab"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue