Skip to content

Commit

Permalink
IRC setup: check the list of users on the channel before running actions
Browse files Browse the repository at this point in the history
This update makes the code retrieve the list of IRC channel users sent by the
server when the bot joins a channel. The code then only invites/dismisses
RRSAgent and Zakim when needed.
  • Loading branch information
tidoust committed Oct 16, 2023
1 parent dc4157b commit f5f2d8b
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions tools/setup-irc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ async function main({ number, onlyCommands, dismissBots } = {}) {
}
});

// Listen to the list of users in the channels we joined
bot.addListener('names', (channel, nicks) => {
if (pendingIRCMessage.what.command === 'names' &&
pendingIRCMessage.what.channel === channel) {
pendingIRCMessage.resolve(Object.keys(nicks));
}
});

// Listen to the MESSAGE messages that contain bot replies to our commands.
bot.addListener('message', (nick, channel, text, message) => {
if (pendingIRCMessage.what.command === 'message' &&
Expand Down Expand Up @@ -230,7 +238,7 @@ async function main({ number, onlyCommands, dismissBots } = {}) {
console.log(`/join ${channel}`);
if (!onlyCommands) {
bot.join(channel);
return waitForIRCMessage({ command: 'join', channel, nick: botName });
return waitForIRCMessage({ command: 'names', channel, nick: botName });
}
}

Expand Down Expand Up @@ -326,15 +334,27 @@ async function main({ number, onlyCommands, dismissBots } = {}) {
});
}

async function draftMinutes(session) {
async function draftMinutes(session, channelUsers) {
const channel = getChannel(session);
await say(channel, `Zakim, bye`);
await say(channel, {
to: 'RRSAgent',
message: 'draft minutes',
reply: 'I have made the request to generate'
});
await say(channel, `RRSAgent, bye`);
if (channelUsers.includes('Zakim')) {
await say(channel, `Zakim, bye`);
}
if (channelUsers.includes('RRSAgent')) {
// Should have been already done in theory, but worth re-doing just in
// case, especially since RRSAgent won't leave a channel until some
// access level has been specified.
await say(channel, {
to: 'RRSAgent',
message: `make logs ${session.description.attendance === 'restricted' ? 'member' : 'public'}`,
reply: `I have made the request, ${botName}`
});
await say(channel, {
to: 'RRSAgent',
message: 'draft minutes',
reply: 'I have made the request to generate'
});
await say(channel, `RRSAgent, bye`);
}
}

// Helper function to send a message to a channel. The function waits for a
Expand All @@ -361,15 +381,19 @@ async function main({ number, onlyCommands, dismissBots } = {}) {
console.log(`session ${session.number}`);
console.log('-----');
try {
await joinChannel(session);
const channelUsers = await joinChannel(session);
if (dismissBots) {
await draftMinutes(session);
await draftMinutes(session, channelUsers);
}
else {
await setTopic(session);
await inviteBot(session, 'RRSAgent');
if (!channelUsers.includes('RRSAgent')) {
await inviteBot(session, 'RRSAgent');
}
await setupRRSAgent(session);
await inviteBot(session, 'Zakim');
if (!channelUsers.includes('Zakim')) {
await inviteBot(session, 'Zakim');
}
await setupZakim(session);
await leaveChannel(session);
}
Expand Down

0 comments on commit f5f2d8b

Please sign in to comment.