commands: add password param to /join

This commit is contained in:
delthas 2022-02-02 17:40:19 +01:00 committed by Simon Ser
parent 9f93e200ed
commit fab42ba2ee
3 changed files with 14 additions and 6 deletions

View File

@ -54,14 +54,18 @@ function markServerBufferUnread(app) {
} }
const join = { const join = {
usage: "<name>", usage: "<name> [password]",
description: "Join a channel", description: "Join a channel",
execute: (app, args) => { execute: (app, args) => {
let channel = args[0]; let channel = args[0];
if (!channel) { if (!channel) {
throw new Error("Missing channel name"); throw new Error("Missing channel name");
} }
app.open(channel); if (args.length > 1) {
app.open(channel, null, args[1]);
} else {
app.open(channel);
}
}, },
}; };

View File

@ -1122,7 +1122,7 @@ export default class App extends Component {
client.monitor(target); client.monitor(target);
} }
open(target, serverID) { open(target, serverID, password) {
if (!serverID) { if (!serverID) {
serverID = State.getActiveServerID(this.state); serverID = State.getActiveServerID(this.state);
} }
@ -1132,7 +1132,7 @@ export default class App extends Component {
this.switchBuffer({ server: serverID }); this.switchBuffer({ server: serverID });
} else if (client.isChannel(target)) { } else if (client.isChannel(target)) {
this.switchToChannel = target; this.switchToChannel = target;
client.join(target).catch((err) => { client.join(target, password).catch((err) => {
this.showError(err); this.showError(err);
}); });
} else { } else {

View File

@ -802,10 +802,14 @@ export default class Client extends EventTarget {
}); });
} }
join(channel) { join(channel, password) {
let params = [channel];
if (password) {
params.push(password);
}
let msg = { let msg = {
command: "JOIN", command: "JOIN",
params: [channel], params: params,
}; };
return this.roundtrip(msg, (msg) => { return this.roundtrip(msg, (msg) => {
switch (msg.command) { switch (msg.command) {