diff --git a/docs/clientapi.md b/docs/clientapi.md index 914e01f..9a1eec9 100644 --- a/docs/clientapi.md +++ b/docs/clientapi.md @@ -109,7 +109,10 @@ Join a channel, optionally with a key/password. Part/leave a channel with an optional parting message. ##### `.setTopic(channel, newTopic)` -Set the topic of a channel +Set the topic of a channel, if newTopic is falsy or only whitespace then `.clearTopic()` will be called. + +##### `.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 33ed8b7..41dc30d 100644 --- a/src/client.js +++ b/src/client.js @@ -611,9 +611,23 @@ module.exports = class IrcClient extends EventEmitter { } setTopic(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; + } + 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} :`); + } + ctcpRequest(target, type /*, paramN */) { const params = Array.prototype.slice.call(arguments, 1);