Skip to content

Commit d4d7e88

Browse files
committed
Consume my irc-framework fork for serialize_writes fix
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
1 parent 0f85a1a commit d4d7e88

File tree

8 files changed

+211
-113
lines changed

8 files changed

+211
-113
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM node:18 as base
22
WORKDIR /app/drc
3+
RUN apt-get clean all
34
RUN apt update
5+
RUN apt -y upgrade
6+
RUN apt -y autoremove
47
RUN apt -y install nmap figlet
58
RUN useradd -u 1001 -U -p discordrc drc
69
COPY package*.json ./

config/default.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const _config = {
125125
ctcpVersionOverride: null,
126126
ctcpVersionPrefix: 'Discord Relay Chat',
127127
ctcpVersionUrl: 'https://discordrc.com',
128-
floodProtectWaitMs: 500,
128+
floodProtectWaitMs: 150,
129129
quitMsgChanId: '',
130130
channelXformsPath: 'config/channelXforms.json',
131131
heartbeatFrequencyMs: 5000,
@@ -136,6 +136,10 @@ const _config = {
136136
"user": {
137137
// any options valid for the irc-framework constructor[1] are valid here
138138
"nick": "",
139+
// highly recommended to set this to true to ensure that multi-line messages are always sent in-order
140+
"serialize_writes": true,
141+
// if you're connecting to a TLS port, you must still explicitly set this to true
142+
"tls": true,
139143
"account": { // will, generally, auto-authenticate with nickserv when present. if not, use !onConnect
140144
"account": "nickservRegisteredName",
141145
"password": "" // if falsy, will be prompted for on the console

discord/events/messageCreate.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ module.exports = async (context, data) => {
190190

191191
if (channel.parent === config.discord.privMsgCategoryId) {
192192
const network /* shadowed! */ = await PrivmsgMappings.findNetworkForKey(data.channelId);
193-
console.log('PM CAT', channel, data.channelId, network, await PrivmsgMappings.forNetwork(network), data.content);
193+
console.log('PM CAT', channel, data.channelId, network, data.content);
194194
ticklePmChanExpiry(network, data.channelId);
195-
console.error('PM FN?!', await PrivmsgMappings.forNetwork(network));
196195
return await redisClient.publish(PREFIX, JSON.stringify({
197196
type: 'discord:requestSay:irc',
198197
data: {

discord/ipcMessages/irc-responseWhois-full.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const logsSearch = async (network, d, embed, aliases = []) => {
3333
}, new Set());
3434

3535
const uniqSearchRes = logsSearchRes.reduce((accObj, srObj) => {
36-
Object.values(srObj).forEach((objList) => objList.forEach((intObj) => Object.entries(intObj).forEach(([k, v]) => accObj[k].add(v))));
36+
Object.values(srObj).forEach((objList) => objList.forEach((intObj) => Object.entries(intObj).forEach(([k, v]) => accObj[k]?.add(v))));
3737
return accObj;
3838
}, {
3939
hostname: new Set(),

irc.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,19 @@ async function main () {
309309

310310
if (channel) {
311311
channel = await resolveNameForDiscord(host, channel);
312-
const chanSpecs = specServers[host].channels.filter(x => x.name === channel);
313-
if (chanSpecs.length > 1) {
314-
console.error(`Duplicate channel specs found for ${host}/${channel}, full list:`, chanSpecs);
312+
const chanSpecs = specServers[host].channels?.filter(x => x.name === channel);
313+
314+
if (!chanSpecs) {
315+
console.error(`No chan specs for ${host}/${channel}?!`);
315316
}
316317

317318
if (chanSpecs.length > 0) {
318319
[chanSpec] = chanSpecs;
319320
}
321+
322+
if (chanSpecs.length > 1) {
323+
console.error(`Duplicate channel specs found for ${host}/${channel}, full list:`, chanSpecs);
324+
}
320325
}
321326

322327
try {

irc/ipcMessage.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,16 @@ module.exports = async (context, chan, msg) => {
203203
throw new Error(`!botClient ${serverSpec.name}`);
204204
}
205205

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

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

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

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

0 commit comments

Comments
 (0)