Compare commits

...

4 commits

Author SHA1 Message Date
Simon Ser
2f1bf8a2fe lib/client: don't mutate input argument in fetchHistoryBetween() 2024-11-16 12:45:08 +01:00
Simon Ser
75eb175e24 eslint: enable object-shorthand 2024-11-16 12:28:17 +01:00
Simon Ser
db0a69dcfd commands: use Map instead of object 2024-11-16 12:27:34 +01:00
Simon Ser
9c2beac7dd eslint: enable no-implicit-coercion 2024-11-16 12:18:17 +01:00
6 changed files with 86 additions and 46 deletions

View file

@ -53,6 +53,7 @@ function markServerBufferUnread(app) {
} }
const join = { const join = {
name: "join",
usage: "<name> [password]", usage: "<name> [password]",
description: "Join a channel", description: "Join a channel",
execute: (app, args) => { execute: (app, args) => {
@ -69,6 +70,7 @@ const join = {
}; };
const kick = { const kick = {
name: "kick",
usage: "<nick> [comment]", usage: "<nick> [comment]",
description: "Remove a user from the channel", description: "Remove a user from the channel",
execute: (app, args) => { execute: (app, args) => {
@ -83,6 +85,7 @@ const kick = {
}; };
const ban = { const ban = {
name: "ban",
usage: "[nick]", usage: "[nick]",
description: "Ban a user from the channel, or display the current ban list", description: "Ban a user from the channel, or display the current ban list",
execute: (app, args) => { execute: (app, args) => {
@ -111,8 +114,9 @@ function givemode(app, args, mode) {
}); });
} }
export default { const commands = [
"away": { {
name: "away",
usage: "[message]", usage: "[message]",
description: "Set away message", description: "Set away message",
execute: (app, args) => { execute: (app, args) => {
@ -123,8 +127,9 @@ export default {
getActiveClient(app).send({command: "AWAY", params}); getActiveClient(app).send({command: "AWAY", params});
}, },
}, },
"ban": ban, ban,
"buffer": { {
name: "buffer",
usage: "<name>", usage: "<name>",
description: "Switch to a buffer", description: "Switch to a buffer",
execute: (app, args) => { execute: (app, args) => {
@ -138,7 +143,8 @@ export default {
throw new Error("Unknown buffer"); throw new Error("Unknown buffer");
}, },
}, },
"close": { {
name: "close",
description: "Close the current buffer", description: "Close the current buffer",
execute: (app, args) => { execute: (app, args) => {
let activeBuffer = app.state.buffers.get(app.state.activeBuffer); let activeBuffer = app.state.buffers.get(app.state.activeBuffer);
@ -148,29 +154,34 @@ export default {
app.close(activeBuffer.id); app.close(activeBuffer.id);
}, },
}, },
"deop": { {
name: "deop",
usage: "<nick>", usage: "<nick>",
description: "Remove operator status for a user on this channel", description: "Remove operator status for a user on this channel",
execute: (app, args) => givemode(app, args, "-o"), execute: (app, args) => givemode(app, args, "-o"),
}, },
"devoice": { {
name: "devoice",
usage: "<nick>", usage: "<nick>",
description: "Remove voiced status for a user on this channel", description: "Remove voiced status for a user on this channel",
execute: (app, args) => givemode(app, args, "-v"), execute: (app, args) => givemode(app, args, "-v"),
}, },
"disconnect": { {
name: "disconnect",
description: "Disconnect from the server", description: "Disconnect from the server",
execute: (app, args) => { execute: (app, args) => {
app.disconnect(); app.disconnect();
}, },
}, },
"help": { {
name: "help",
description: "Show help menu", description: "Show help menu",
execute: (app, args) => { execute: (app, args) => {
app.openHelp(); app.openHelp();
}, },
}, },
"invite": { {
name: "invite",
usage: "<nick>", usage: "<nick>",
description: "Invite a user to the channel", description: "Invite a user to the channel",
execute: (app, args) => { execute: (app, args) => {
@ -184,10 +195,11 @@ export default {
]}); ]});
}, },
}, },
"j": join, { ...join, name: "j" },
"join": join, join,
"kick": kick, kick,
"kickban": { {
name: "kickban",
usage: "<target>", usage: "<target>",
description: "Ban a user and removes them from the channel", description: "Ban a user and removes them from the channel",
execute: (app, args) => { execute: (app, args) => {
@ -195,7 +207,8 @@ export default {
ban.execute(app, args); ban.execute(app, args);
}, },
}, },
"lusers": { {
name: "lusers",
usage: "[<mask> [<target>]]", usage: "[<mask> [<target>]]",
description: "Request user statistics about the network", description: "Request user statistics about the network",
execute: (app, args) => { execute: (app, args) => {
@ -203,7 +216,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"me": { {
name: "me",
usage: "<action>", usage: "<action>",
description: "Send an action message to the current buffer", description: "Send an action message to the current buffer",
execute: (app, args) => { execute: (app, args) => {
@ -213,7 +227,8 @@ export default {
app.privmsg(target, text); app.privmsg(target, text);
}, },
}, },
"mode": { {
name: "mode",
usage: "[target] [modes] [mode args...]", usage: "[target] [modes] [mode args...]",
description: "Query or change a channel or user mode", description: "Query or change a channel or user mode",
execute: (app, args) => { execute: (app, args) => {
@ -225,7 +240,8 @@ export default {
getActiveClient(app).send({ command: "MODE", params: args }); getActiveClient(app).send({ command: "MODE", params: args });
}, },
}, },
"motd": { {
name: "motd",
usage: "[server]", usage: "[server]",
description: "Get the Message Of The Day", description: "Get the Message Of The Day",
execute: (app, args) => { execute: (app, args) => {
@ -233,7 +249,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"msg": { {
name: "msg",
usage: "<target> <message>", usage: "<target> <message>",
description: "Send a message to a nickname or a channel", description: "Send a message to a nickname or a channel",
execute: (app, args) => { execute: (app, args) => {
@ -242,7 +259,8 @@ export default {
getActiveClient(app).send({ command: "PRIVMSG", params: [target, text] }); getActiveClient(app).send({ command: "PRIVMSG", params: [target, text] });
}, },
}, },
"nick": { {
name: "nick",
usage: "<nick>", usage: "<nick>",
description: "Change current nickname", description: "Change current nickname",
execute: (app, args) => { execute: (app, args) => {
@ -250,7 +268,8 @@ export default {
getActiveClient(app).send({ command: "NICK", params: [newNick] }); getActiveClient(app).send({ command: "NICK", params: [newNick] });
}, },
}, },
"notice": { {
name: "notice",
usage: "<target> <message>", usage: "<target> <message>",
description: "Send a notice to a nickname or a channel", description: "Send a notice to a nickname or a channel",
execute: (app, args) => { execute: (app, args) => {
@ -259,12 +278,14 @@ export default {
getActiveClient(app).send({ command: "NOTICE", params: [target, text] }); getActiveClient(app).send({ command: "NOTICE", params: [target, text] });
}, },
}, },
"op": { {
name: "op",
usage: "<nick>", usage: "<nick>",
description: "Give a user operator status on this channel", description: "Give a user operator status on this channel",
execute: (app, args) => givemode(app, args, "+o"), execute: (app, args) => givemode(app, args, "+o"),
}, },
"part": { {
name: "part",
usage: "[reason]", usage: "[reason]",
description: "Leave a channel", description: "Leave a channel",
execute: (app, args) => { execute: (app, args) => {
@ -277,7 +298,8 @@ export default {
getActiveClient(app).send({ command: "PART", params }); getActiveClient(app).send({ command: "PART", params });
}, },
}, },
"query": { {
name: "query",
usage: "<nick> [message]", usage: "<nick> [message]",
description: "Open a buffer to send messages to a nickname", description: "Open a buffer to send messages to a nickname",
execute: (app, args) => { execute: (app, args) => {
@ -293,7 +315,8 @@ export default {
} }
}, },
}, },
"quiet": { {
name: "quiet",
usage: "[nick]", usage: "[nick]",
description: "Quiet a user in the channel, or display the current quiet list", description: "Quiet a user in the channel, or display the current quiet list",
execute: (app, args) => { execute: (app, args) => {
@ -307,13 +330,15 @@ export default {
} }
}, },
}, },
"quit": { {
name: "quit",
description: "Quit", description: "Quit",
execute: (app, args) => { execute: (app, args) => {
app.close({ name: SERVER_BUFFER }); app.close({ name: SERVER_BUFFER });
}, },
}, },
"quote": { {
name: "quote",
usage: "<command>", usage: "<command>",
description: "Send a raw IRC command to the server", description: "Send a raw IRC command to the server",
execute: (app, args) => { execute: (app, args) => {
@ -326,13 +351,15 @@ export default {
getActiveClient(app).send(msg); getActiveClient(app).send(msg);
}, },
}, },
"reconnect": { {
name: "reconnect",
description: "Reconnect to the server", description: "Reconnect to the server",
execute: (app, args) => { execute: (app, args) => {
app.reconnect(); app.reconnect();
}, },
}, },
"setname": { {
name: "setname",
usage: "<realname>", usage: "<realname>",
description: "Change current realname", description: "Change current realname",
execute: (app, args) => { execute: (app, args) => {
@ -345,7 +372,8 @@ export default {
// TODO: save to local storage // TODO: save to local storage
}, },
}, },
"stats": { {
name: "stats",
usage: "<query> [server]", usage: "<query> [server]",
description: "Request server statistics", description: "Request server statistics",
execute: (app, args) => { execute: (app, args) => {
@ -361,7 +389,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"topic": { {
name: "topic",
usage: "<topic>", usage: "<topic>",
description: "Change the topic of the current channel", description: "Change the topic of the current channel",
execute: (app, args) => { execute: (app, args) => {
@ -373,26 +402,30 @@ export default {
getActiveClient(app).send({ command: "TOPIC", params }); getActiveClient(app).send({ command: "TOPIC", params });
}, },
}, },
"unban": { {
name: "unban",
usage: "<nick>", usage: "<nick>",
description: "Remove a user from the ban list", description: "Remove a user from the ban list",
execute: (app, args) => { execute: (app, args) => {
return setUserHostMode(app, args, "-b"); return setUserHostMode(app, args, "-b");
}, },
}, },
"unquiet": { {
name: "unquiet",
usage: "<nick>", usage: "<nick>",
description: "Remove a user from the quiet list", description: "Remove a user from the quiet list",
execute: (app, args) => { execute: (app, args) => {
return setUserHostMode(app, args, "-q"); return setUserHostMode(app, args, "-q");
}, },
}, },
"voice": { {
name: "voice",
usage: "<nick>", usage: "<nick>",
description: "Give a user voiced status on this channel", description: "Give a user voiced status on this channel",
execute: (app, args) => givemode(app, args, "+v"), execute: (app, args) => givemode(app, args, "+v"),
}, },
"who": { {
name: "who",
usage: "<mask>", usage: "<mask>",
description: "Retrieve a list of users", description: "Retrieve a list of users",
execute: (app, args) => { execute: (app, args) => {
@ -400,7 +433,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"whois": { {
name: "whois",
usage: "<nick>", usage: "<nick>",
description: "Retrieve information about a user", description: "Retrieve information about a user",
execute: (app, args) => { execute: (app, args) => {
@ -412,7 +446,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"whowas": { {
name: "whowas",
usage: "<nick> [count]", usage: "<nick> [count]",
description: "Retrieve information about an offline user", description: "Retrieve information about an offline user",
execute: (app, args) => { execute: (app, args) => {
@ -423,7 +458,8 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
"list": { {
name: "list",
usage: "[filter]", usage: "[filter]",
description: "Retrieve a list of channels from a network", description: "Retrieve a list of channels from a network",
execute: (app, args) => { execute: (app, args) => {
@ -431,4 +467,6 @@ export default {
markServerBufferUnread(app); markServerBufferUnread(app);
}, },
}, },
}; ];
export default new Map(commands.map((cmd) => [cmd.name, cmd]));

View file

@ -515,7 +515,7 @@ export default class App extends Component {
this.setState((state) => { this.setState((state) => {
let updated; let updated;
[id, updated] = State.createBuffer(state, name, serverID, client); [id, updated] = State.createBuffer(state, name, serverID, client);
isNew = !!updated; isNew = Boolean(updated);
return updated; return updated;
}); });
if (isNew) { if (isNew) {
@ -1583,7 +1583,7 @@ export default class App extends Component {
let name = parts[0].toLowerCase().slice(1); let name = parts[0].toLowerCase().slice(1);
let args = parts.slice(1); let args = parts.slice(1);
let cmd = commands[name]; let cmd = commands.get(name);
if (!cmd) { if (!cmd) {
this.showError(`Unknown command "${name}" (run "/help" to get a command list)`); this.showError(`Unknown command "${name}" (run "/help" to get a command list)`);
return; return;
@ -1715,7 +1715,7 @@ export default class App extends Component {
} }
if (prefix.startsWith("/")) { if (prefix.startsWith("/")) {
let repl = fromList(Object.keys(commands), prefix.slice(1)); let repl = fromList([...commands.keys()], prefix.slice(1));
return repl.map((cmd) => "/" + cmd); return repl.map((cmd) => "/" + cmd);
} }

View file

@ -26,6 +26,8 @@ export default [
"eqeqeq": "error", "eqeqeq": "error",
"no-invalid-this": "error", "no-invalid-this": "error",
"prefer-arrow-callback": "error", "prefer-arrow-callback": "error",
"no-implicit-coercion": "warn",
"object-shorthand": "warn",
"@stylistic/js/indent": ["warn", "tab"], "@stylistic/js/indent": ["warn", "tab"],
"@stylistic/js/quotes": ["warn", "double"], "@stylistic/js/quotes": ["warn", "double"],
"@stylistic/js/semi": "warn", "@stylistic/js/semi": "warn",

View file

@ -121,7 +121,7 @@ export function setup(app) {
return; return;
} }
candidates = candidates.filter((binding) => { candidates = candidates.filter((binding) => {
return !!binding.altKey === event.altKey && !!binding.ctrlKey === event.ctrlKey; return Boolean(binding.altKey) === event.altKey && Boolean(binding.ctrlKey) === event.ctrlKey;
}); });
if (candidates.length !== 1) { if (candidates.length !== 1) {
return; return;

View file

@ -853,7 +853,7 @@ export default class Client extends EventTarget {
} }
let msg = { let msg = {
command: "JOIN", command: "JOIN",
params: params, params,
}; };
return this.roundtrip(msg, (msg) => { return this.roundtrip(msg, (msg) => {
switch (msg.command) { switch (msg.command) {
@ -940,7 +940,7 @@ export default class Client extends EventTarget {
} }
if (messages.length >= max) { if (messages.length >= max) {
// There are still more messages to fetch // There are still more messages to fetch
after.time = messages[messages.length - 1].tags.time; after = { ...after, time: messages[messages.length - 1].tags.time };
return await this.fetchHistoryBetween(target, after, before, limit); return await this.fetchHistoryBetween(target, after, before, limit);
} }
return { messages }; return { messages };

View file

@ -634,7 +634,7 @@ export const State = {
return updateUser(msg.prefix.name, { account }); return updateUser(msg.prefix.name, { account });
case "AWAY": case "AWAY":
let awayMessage = msg.params[0]; let awayMessage = msg.params[0];
return updateUser(msg.prefix.name, { away: !!awayMessage }); return updateUser(msg.prefix.name, { away: Boolean(awayMessage) });
case "TOPIC": case "TOPIC":
channel = msg.params[0]; channel = msg.params[0];
topic = msg.params[1]; topic = msg.params[1];