diff --git a/src/account.ts b/src/account.ts index ce10ea2..7c2d1b2 100644 --- a/src/account.ts +++ b/src/account.ts @@ -213,7 +213,7 @@ export function stripAccountInfo(account: Account, access: Access = Access.PUBLI /** * Checks if `value` is a valid `key` * @param key The attribute to check - * @param _value The value + * @param value The value */ export function checkAccountAttribute(key: K, value: FullAccount[K]): void { const [_key, _value] = [key, value] as KeyValue; @@ -322,15 +322,37 @@ export async function deleteAccount(id: string, reason?: string): Promise * @returns The account's data */ export async function getAccount(id: string): Promise; +export async function getAccount(key: string, value?: string): Promise; export async function getAccount(key: string, value?: string): Promise { if (!(key in accountAttributes)) { [key, value] = ['id', key]; } checkAccountAttribute(key as keyof FullAccount, value); - const result = await request('POST', 'account/info', { action: 'get', [key]: value }); + const result = await request('POST', 'account/info', { [key]: value, multiple: false }); return parseAccount(result); } +/** + * Gets info about accounts (Requires authorization: Mod) + * @param key the key to identify accounts with (e.g. id) + * @param value the value of the key (e.g. the accounts role) + * @returns The accounts + */ +export async function getAccounts(key: string, value?: string): Promise { + checkAccountAttribute(key as keyof FullAccount, value); + const results = await request('POST', 'account/info', { [key]: value, multiple: true }); + return results.map(result => parseAccount(result)); +} + +/** + * Gets info about all account (Requires authorization: Mod) + * @returns The accounts + */ +export async function getAllAccounts(): Promise { + const results = await request('POST', 'account/info', { multiple: true, all: true }); + return results.map(result => parseAccount(result)); +} + /** * Updates an attribute of an account * @param id the account's id