Created and implemented status search flag for search command

This commit is contained in:
roflmaoqwerty 2020-01-22 21:32:47 +11:00 committed by Dragory
parent d2dc69f35d
commit 77e5f429c5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -120,6 +120,7 @@ type MemberSearchParams = {
sort?: string; sort?: string;
"case-sensitive"?: boolean; "case-sensitive"?: boolean;
regex?: boolean; regex?: boolean;
"status-search"?: boolean;
}; };
class SearchError extends Error {} class SearchError extends Error {}
@ -381,6 +382,15 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
throw new SearchError("Unsafe/too complex regex (star depth is limited to 1)"); throw new SearchError("Unsafe/too complex regex (star depth is limited to 1)");
} }
if (args["status-search"]) {
matchingMembers = matchingMembers.filter(member => {
if (member.game) {
if (member.game.name && member.game.name.match(queryRegex)) return true;
if (member.game.state && member.game.state.match(queryRegex)) return true;
}
return false;
});
} else {
matchingMembers = matchingMembers.filter(member => { matchingMembers = matchingMembers.filter(member => {
if (member.nick && member.nick.match(queryRegex)) return true; if (member.nick && member.nick.match(queryRegex)) return true;
@ -390,6 +400,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
return false; return false;
}); });
} }
}
const [, sortDir, sortBy] = args.sort ? args.sort.match(/^(-?)(.*)$/) : [null, "ASC", "name"]; const [, sortDir, sortBy] = args.sort ? args.sort.match(/^(-?)(.*)$/) : [null, "ASC", "name"];
const realSortDir = sortDir === "-" ? "DESC" : "ASC"; const realSortDir = sortDir === "-" ? "DESC" : "ASC";
@ -469,6 +480,11 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
shortcut: "re", shortcut: "re",
isSwitch: true, isSwitch: true,
}, },
{
name: "status-search",
shortcut: "ss",
isSwitch: true,
},
], ],
extra: { extra: {
info: <CommandInfo>{ info: <CommandInfo>{
@ -500,6 +516,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
export?: boolean; export?: boolean;
ids?: boolean; ids?: boolean;
regex?: boolean; regex?: boolean;
"status-search"?: boolean;
}, },
) { ) {
const formatSearchResultList = (members: Member[]): string => { const formatSearchResultList = (members: Member[]): string => {