Optimise commands processing

This commit is contained in:
JeDaYoshi 2021-07-06 15:43:02 +00:00
parent bbda392c3d
commit 0d839c501e
No known key found for this signature in database
GPG Key ID: 8060B288C274219D
2 changed files with 13 additions and 7 deletions

View File

@ -6,7 +6,6 @@ import Mousetrap from "mousetrap";
import {Textcomplete, Textarea} from "textcomplete";
import fuzzy from "fuzzy";
import commands from "./commands/index";
import emojiMap from "./helpers/simplemap.json";
import store from "./store";
@ -313,14 +312,17 @@ function completeNicks(word, isFuzzy) {
}
function getCommands() {
const clientCommands = Object.keys(commands).map((cmd) => `/${cmd}`);
const cmds = [...new Set(Array.from(constants.commands).concat(clientCommands))];
const cmds = constants.commands;
if (!store.state.settings.searchEnabled) {
cmds.pop("/search");
if (store.state.settings.searchEnabled === false) {
const search = cmds.indexOf("/search");
if (search !== -1) {
cmds.splice(search, 1);
}
}
return cmds.sort();
return cmds;
}
function completeCommands(word) {

View File

@ -1,8 +1,12 @@
const constants = require("../constants");
import localCommands from "../commands/index";
import socket from "../socket";
const clientCommands = Object.keys(localCommands).map((cmd) => `/${cmd}`);
socket.on("commands", function (commands) {
if (commands) {
constants.commands = commands;
const cmds = [...new Set(commands.concat(clientCommands))];
constants.commands = cmds.sort();
}
});