Sort commands by name

This commit is contained in:
Simon Ser 2021-03-07 21:06:26 +01:00
parent 6c0878eeac
commit 718929f0d2

View file

@ -9,18 +9,15 @@ function getActiveClient(app) {
} }
export default { export default {
"quit": (app, args) => { "buffer": (app, args) => {
if (window.localStorage) { var name = args[0];
localStorage.removeItem("autoconnect"); for (var buf of app.state.buffers.values()) {
if (buf.name === name) {
app.switchBuffer(buf);
return;
}
} }
app.close({ name: SERVER_BUFFER }); throw new Error("Unknown buffer");
},
"query": (app, args) => {
var nick = args[0];
if (!nick) {
throw new Error("Missing nickname");
}
app.open(nick);
}, },
"close": (app, args) => { "close": (app, args) => {
var activeBuffer = app.state.buffers.get(app.state.activeBuffer); var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
@ -29,6 +26,9 @@ export default {
} }
app.close(activeBuffer.id); app.close(activeBuffer.id);
}, },
"disconnect": (app, args) => {
app.disconnect();
},
"join": (app, args) => { "join": (app, args) => {
var channel = args[0]; var channel = args[0];
if (!channel) { if (!channel) {
@ -36,6 +36,29 @@ export default {
} }
getActiveClient(app).send({ command: "JOIN", params: [channel] }); getActiveClient(app).send({ command: "JOIN", params: [channel] });
}, },
"me": (app, args) => {
var action = args.join(" ");
var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
if (!activeBuffer) {
throw new Error("Not in a buffer");
}
var text = `\x01ACTION ${action}\x01`;
app.privmsg(activeBuffer.name, text);
},
"msg": (app, args) => {
var target = args[0];
var text = args.slice(1).join(" ");
getActiveClient(app).send({ command: "PRIVMSG", params: [target, text] });
},
"nick": (app, args) => {
var newNick = args[0];
getActiveClient(app).send({ command: "NICK", params: [newNick] });
},
"notice": (app, args) => {
var target = args[0];
var text = args.slice(1).join(" ");
getActiveClient(app).send({ command: "NOTICE", params: [target, text] });
},
"part": (app, args) => { "part": (app, args) => {
var reason = args.join(" "); var reason = args.join(" ");
var activeBuffer = app.state.buffers.get(app.state.activeBuffer); var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
@ -48,38 +71,21 @@ export default {
} }
getActiveClient(app).send({ command: "PART", params }); getActiveClient(app).send({ command: "PART", params });
}, },
"msg": (app, args) => { "query": (app, args) => {
var target = args[0]; var nick = args[0];
var text = args.slice(1).join(" "); if (!nick) {
getActiveClient(app).send({ command: "PRIVMSG", params: [target, text] }); throw new Error("Missing nickname");
},
"me": (app, args) => {
var action = args.join(" ");
var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
if (!activeBuffer) {
throw new Error("Not in a buffer");
} }
var text = `\x01ACTION ${action}\x01`; app.open(nick);
app.privmsg(activeBuffer.name, text);
}, },
"nick": (app, args) => { "quit": (app, args) => {
var newNick = args[0]; if (window.localStorage) {
getActiveClient(app).send({ command: "NICK", params: [newNick] }); localStorage.removeItem("autoconnect");
},
"notice": (app, args) => {
var target = args[0];
var text = args.slice(1).join(" ");
getActiveClient(app).send({ command: "NOTICE", params: [target, text] });
},
"buffer": (app, args) => {
var name = args[0];
for (var buf of app.state.buffers.values()) {
if (buf.name === name) {
app.switchBuffer(buf);
return;
}
} }
throw new Error("Unknown buffer"); app.close({ name: SERVER_BUFFER });
},
"reconnect": (app, args) => {
app.reconnect();
}, },
"topic": (app, args) => { "topic": (app, args) => {
var activeBuffer = app.state.buffers.get(app.state.activeBuffer); var activeBuffer = app.state.buffers.get(app.state.activeBuffer);
@ -92,10 +98,4 @@ export default {
} }
getActiveClient(app).send({ command: "TOPIC", params }); getActiveClient(app).send({ command: "TOPIC", params });
}, },
"reconnect": (app, args) => {
app.reconnect();
},
"disconnect": (app, args) => {
app.disconnect();
},
}; };