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;
"case-sensitive"?: boolean;
regex?: boolean;
"status-search"?: boolean;
};
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)");
}
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 => {
if (member.nick && member.nick.match(queryRegex)) return true;
@ -390,6 +400,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
return false;
});
}
}
const [, sortDir, sortBy] = args.sort ? args.sort.match(/^(-?)(.*)$/) : [null, "ASC", "name"];
const realSortDir = sortDir === "-" ? "DESC" : "ASC";
@ -469,6 +480,11 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
shortcut: "re",
isSwitch: true,
},
{
name: "status-search",
shortcut: "ss",
isSwitch: true,
},
],
extra: {
info: <CommandInfo>{
@ -500,6 +516,7 @@ export class UtilityPlugin extends ZeppelinPlugin<TConfigSchema> {
export?: boolean;
ids?: boolean;
regex?: boolean;
"status-search"?: boolean;
},
) {
const formatSearchResultList = (members: Member[]): string => {