diff --git a/docs/clientapi.md b/docs/clientapi.md index 5bd37a3f..001f0606 100644 --- a/docs/clientapi.md +++ b/docs/clientapi.md @@ -101,6 +101,9 @@ Part/leave a channel with an optional parting message. ##### `.setTopic(channel, newTopic)` Set the topic of a channel +##### `.clearTopic(channel)` +Remove the topic of a channel + ##### `.ctcpRequest(target, type [, paramN])` Send a CTCP request to target with any number of parameters. diff --git a/src/client.js b/src/client.js index 85f54baa..9297d2c8 100644 --- a/src/client.js +++ b/src/client.js @@ -611,13 +611,20 @@ module.exports = class IrcClient extends EventEmitter { } setTopic(channel, newTopic) { - if (newTopic && newTopic.trim()) { - this.raw('TOPIC', channel, newTopic); + if (!newTopic || !newTopic.trim()) { + // If newTopic is undefined or empty, remove the existing topic + // this check is to prevent unexpectedly requesting the current topic + // when trying to clear the topic + this.clearTopic(channel); return; } - // If newTopic is undefined or empty, remove the existing topic - // this is needed because without the : then it would be requesting the current topic + this.raw('TOPIC', channel, newTopic); + } + + clearTopic(channel) { + // The trailing `:` is required otherwise it would be requesting the topic + // and not clearing it this.raw(`TOPIC ${channel} :`); }