3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +00:00

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,14 +382,24 @@ 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)");
} }
matchingMembers = matchingMembers.filter(member => { if (args["status-search"]) {
if (member.nick && member.nick.match(queryRegex)) return true; 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;
const fullUsername = `${member.user.username}#${member.user.discriminator}`; const fullUsername = `${member.user.username}#${member.user.discriminator}`;
if (fullUsername.match(queryRegex)) return true; if (fullUsername.match(queryRegex)) return true;
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"];
@ -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 => {