Skip to content

Commit

Permalink
add clearTopic function
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Jan 10, 2024
1 parent ba7f144 commit 664935c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/clientapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
15 changes: 11 additions & 4 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} :`);
}

Expand Down

0 comments on commit 664935c

Please sign in to comment.