Move clientCommands to client
This approach automatically imports the command names.
This commit is contained in:
parent
521426bb05
commit
bbda392c3d
@ -6,6 +6,7 @@ import Mousetrap from "mousetrap";
|
|||||||
import {Textcomplete, Textarea} from "textcomplete";
|
import {Textcomplete, Textarea} from "textcomplete";
|
||||||
import fuzzy from "fuzzy";
|
import fuzzy from "fuzzy";
|
||||||
|
|
||||||
|
import commands from "./commands/index";
|
||||||
import emojiMap from "./helpers/simplemap.json";
|
import emojiMap from "./helpers/simplemap.json";
|
||||||
import store from "./store";
|
import store from "./store";
|
||||||
|
|
||||||
@ -311,8 +312,19 @@ function completeNicks(word, isFuzzy) {
|
|||||||
return users.filter((w) => !w.toLowerCase().indexOf(word));
|
return users.filter((w) => !w.toLowerCase().indexOf(word));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCommands() {
|
||||||
|
const clientCommands = Object.keys(commands).map((cmd) => `/${cmd}`);
|
||||||
|
const cmds = [...new Set(Array.from(constants.commands).concat(clientCommands))];
|
||||||
|
|
||||||
|
if (!store.state.settings.searchEnabled) {
|
||||||
|
cmds.pop("/search");
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmds.sort();
|
||||||
|
}
|
||||||
|
|
||||||
function completeCommands(word) {
|
function completeCommands(word) {
|
||||||
const words = constants.commands.slice();
|
const words = getCommands().slice();
|
||||||
|
|
||||||
return fuzzyGrep(word, words);
|
return fuzzyGrep(word, words);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
const clientSideCommands = ["/collapse", "/expand"];
|
|
||||||
|
|
||||||
const passThroughCommands = [
|
const passThroughCommands = [
|
||||||
"/as",
|
"/as",
|
||||||
"/bs",
|
"/bs",
|
||||||
@ -43,19 +41,12 @@ const userInputs = [
|
|||||||
|
|
||||||
const pluginCommands = new Map();
|
const pluginCommands = new Map();
|
||||||
|
|
||||||
const getCommands = (client) => {
|
const getCommands = () =>
|
||||||
const commands = Array.from(userInputs.keys())
|
Array.from(userInputs.keys())
|
||||||
.concat(Array.from(pluginCommands.keys()))
|
.concat(Array.from(pluginCommands.keys()))
|
||||||
.map((command) => `/${command}`)
|
.map((command) => `/${command}`)
|
||||||
.concat(clientSideCommands)
|
.concat(passThroughCommands)
|
||||||
.concat(passThroughCommands);
|
.sort();
|
||||||
|
|
||||||
if (client.messageProvider !== undefined) {
|
|
||||||
commands.push("/search");
|
|
||||||
}
|
|
||||||
|
|
||||||
return commands.sort();
|
|
||||||
};
|
|
||||||
|
|
||||||
const addPluginCommand = (packageInfo, command, func) => {
|
const addPluginCommand = (packageInfo, command, func) => {
|
||||||
func.packageInfo = packageInfo;
|
func.packageInfo = packageInfo;
|
||||||
|
@ -692,7 +692,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
|
|||||||
),
|
),
|
||||||
token: tokenToSend,
|
token: tokenToSend,
|
||||||
});
|
});
|
||||||
socket.emit("commands", inputs.getCommands(client));
|
socket.emit("commands", inputs.getCommands());
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Helper.config.public) {
|
if (Helper.config.public) {
|
||||||
|
@ -4,34 +4,16 @@ const expect = require("chai").expect;
|
|||||||
const inputs = require("../../../src/plugins/inputs");
|
const inputs = require("../../../src/plugins/inputs");
|
||||||
|
|
||||||
describe("inputs", function () {
|
describe("inputs", function () {
|
||||||
const client = {
|
|
||||||
messageProvider: undefined,
|
|
||||||
};
|
|
||||||
const clientWithProvider = {
|
|
||||||
...client,
|
|
||||||
messageProvider: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
describe(".getCommands", function () {
|
describe(".getCommands", function () {
|
||||||
it("should return a non-empty array", function () {
|
it("should return a non-empty array", function () {
|
||||||
expect(inputs.getCommands(client)).to.be.an("array").that.is.not.empty;
|
expect(inputs.getCommands()).to.be.an("array").that.is.not.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should only return strings with no whitespaces and starting with /", function () {
|
it("should only return strings with no whitespaces and starting with /", function () {
|
||||||
inputs.getCommands(client).forEach((command) => {
|
inputs.getCommands().forEach((command) => {
|
||||||
expect(command).to.be.a("string").that.does.not.match(/\s/);
|
expect(command).to.be.a("string").that.does.not.match(/\s/);
|
||||||
expect(command[0]).to.equal("/");
|
expect(command[0]).to.equal("/");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not include /search without a message provider", function () {
|
|
||||||
expect(inputs.getCommands(client)).to.be.an("array").that.does.not.contains("/search");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should include /search with a message provider", function () {
|
|
||||||
expect(inputs.getCommands(clientWithProvider))
|
|
||||||
.to.be.an("array")
|
|
||||||
.that.contains("/search");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user