Skip to content

Commit

Permalink
Consume my irc-framework fork for serialize_writes fix
Browse files Browse the repository at this point in the history
Until kiwiirc/irc-framework#362 can be merged upstream.

Also includes the following fixes/updates:
* fix bug in log search consumed by irc-responseWhois-full.js
* fix join flood when isReconnect is true even though it should not be
* improve os image initial setup for base image in Dockerfile
  • Loading branch information
edfletcher committed Jun 22, 2023
1 parent 0f85a1a commit d4d7e88
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 113 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM node:18 as base
WORKDIR /app/drc
RUN apt-get clean all
RUN apt update
RUN apt -y upgrade
RUN apt -y autoremove
RUN apt -y install nmap figlet
RUN useradd -u 1001 -U -p discordrc drc
COPY package*.json ./
Expand Down
6 changes: 5 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const _config = {
ctcpVersionOverride: null,
ctcpVersionPrefix: 'Discord Relay Chat',
ctcpVersionUrl: 'https://discordrc.com',
floodProtectWaitMs: 500,
floodProtectWaitMs: 150,
quitMsgChanId: '',
channelXformsPath: 'config/channelXforms.json',
heartbeatFrequencyMs: 5000,
Expand All @@ -136,6 +136,10 @@ const _config = {
"user": {
// any options valid for the irc-framework constructor[1] are valid here
"nick": "",
// highly recommended to set this to true to ensure that multi-line messages are always sent in-order
"serialize_writes": true,
// if you're connecting to a TLS port, you must still explicitly set this to true
"tls": true,
"account": { // will, generally, auto-authenticate with nickserv when present. if not, use !onConnect
"account": "nickservRegisteredName",
"password": "" // if falsy, will be prompted for on the console
Expand Down
3 changes: 1 addition & 2 deletions discord/events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ module.exports = async (context, data) => {

if (channel.parent === config.discord.privMsgCategoryId) {
const network /* shadowed! */ = await PrivmsgMappings.findNetworkForKey(data.channelId);
console.log('PM CAT', channel, data.channelId, network, await PrivmsgMappings.forNetwork(network), data.content);
console.log('PM CAT', channel, data.channelId, network, data.content);
ticklePmChanExpiry(network, data.channelId);
console.error('PM FN?!', await PrivmsgMappings.forNetwork(network));
return await redisClient.publish(PREFIX, JSON.stringify({
type: 'discord:requestSay:irc',
data: {
Expand Down
2 changes: 1 addition & 1 deletion discord/ipcMessages/irc-responseWhois-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const logsSearch = async (network, d, embed, aliases = []) => {
}, new Set());

const uniqSearchRes = logsSearchRes.reduce((accObj, srObj) => {
Object.values(srObj).forEach((objList) => objList.forEach((intObj) => Object.entries(intObj).forEach(([k, v]) => accObj[k].add(v))));
Object.values(srObj).forEach((objList) => objList.forEach((intObj) => Object.entries(intObj).forEach(([k, v]) => accObj[k]?.add(v))));
return accObj;
}, {
hostname: new Set(),
Expand Down
11 changes: 8 additions & 3 deletions irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,19 @@ async function main () {

if (channel) {
channel = await resolveNameForDiscord(host, channel);
const chanSpecs = specServers[host].channels.filter(x => x.name === channel);
if (chanSpecs.length > 1) {
console.error(`Duplicate channel specs found for ${host}/${channel}, full list:`, chanSpecs);
const chanSpecs = specServers[host].channels?.filter(x => x.name === channel);

if (!chanSpecs) {
console.error(`No chan specs for ${host}/${channel}?!`);
}

if (chanSpecs.length > 0) {
[chanSpec] = chanSpecs;
}

if (chanSpecs.length > 1) {
console.error(`Duplicate channel specs found for ${host}/${channel}, full list:`, chanSpecs);
}
}

try {
Expand Down
13 changes: 6 additions & 7 deletions irc/ipcMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,16 @@ module.exports = async (context, chan, msg) => {
throw new Error(`!botClient ${serverSpec.name}`);
}

console.log(`Joining channels on ${serverSpec.name}...`);
console.log(`Joining channels on ${serverSpec.name}... (isReconnect: ${isReconnect})`);

const joinFuncs = [];
chanPrefixes[serverSpec.name] = await Promise.all(serverSpec.channels.map(getChannelJoinFunc.bind(null, joinFuncs, serverSpec), []));

// XXX: pretty sure this function is never actually called on the reconnect path!
if (isReconnect) {
await Promise.all(joinFuncs.map((f) => f()));
} else {
await floodProtect(joinFuncs);
}
// isReconnect logic is not always correct, for example: start the IRC daemon first and let it fully connect to IRC, then
// start the discord daemon. isReconnect will be 'true' even though it is the first connection for the lifetime of either process.
// as a stop-gap until that logic is corrected, we must always use floodProtect() here lest we get into the aforementioned
// situation and flood the server with joins, getting kicked accordingly
await floodProtect(joinFuncs);

console.log(`Joined ${joinFuncs.length} channels on ${serverSpec.name}.`);
console.debug('chanPrefixes for', serverSpec.name, chanPrefixes[serverSpec.name]);
Expand Down
Loading

0 comments on commit d4d7e88

Please sign in to comment.