Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setTopic() remove the topic if newTopic is falsy #367

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down