-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e15d8a
commit 85570b6
Showing
7 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { env } from 'bun' | ||
import { Kient } from 'kient' | ||
|
||
const kient = new Kient() | ||
kient.setAuthToken(env.KICK_TOKEN as string) | ||
|
||
const currentUser = await kient.api.users.getAuthorisedUser() | ||
console.log(currentUser.toJSON()) | ||
|
||
const multipleUsers = await kient.api.users.getByIds([1, 2, 3]) | ||
console.log(multipleUsers[0].toJSON()) | ||
|
||
const specificUser = await kient.api.users.getById(2) | ||
console.log(specificUser.toJSON()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { cast } from '@deepkit/type' | ||
import type { Kient } from 'kient' | ||
// biome-ignore lint/style/useImportType: deepkit/type runtime type information | ||
import { APIResponse } from '../../util/api-response' | ||
// biome-ignore lint/style/useImportType: deepkit/type runtime type information | ||
import { User } from '../../structures/user' | ||
|
||
export async function getUsersByIds(kient: Kient, ids?: number[]) { | ||
const params = new URLSearchParams() | ||
for (const id of ids || []) { | ||
params.append('id', id.toString()) | ||
} | ||
const response = await kient._apiClient.fetch<APIResponse<User[]>>(`/users?${params}`) | ||
|
||
const responseKientInjected = response.data.map((user) => ({ | ||
...user, | ||
kient, | ||
})) | ||
|
||
const typedResponse = cast<User[]>(responseKientInjected) | ||
return typedResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { APIBase } from '../api-base' | ||
import { getUsersByIds } from './get-users' | ||
|
||
/** | ||
* Description placeholder | ||
* | ||
* @group APIs | ||
*/ | ||
export class UsersAPI extends APIBase { | ||
/** | ||
* Returns an array of users by an array of IDs | ||
* | ||
* @param {number[]} ids Accepts an user IDs that will be queried for | ||
*/ | ||
getByIds(ids: number[]) { | ||
return getUsersByIds(this.kient, ids) | ||
} | ||
|
||
/** | ||
* Returns a singular user by ID | ||
* | ||
* @param {number} id Accepts a user ID that will be queried for | ||
*/ | ||
async getById(id: number) { | ||
return (await getUsersByIds(this.kient, [id]))[0] | ||
} | ||
|
||
/** | ||
* Returns the currently authorised user's details | ||
*/ | ||
async getAuthorisedUser() { | ||
return (await getUsersByIds(this.kient))[0] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters