Skip to content

Commit 3f50b31

Browse files
committed
feat: add new channel endpoint data
1 parent 79ced64 commit 3f50b31

File tree

5 files changed

+101
-24
lines changed

5 files changed

+101
-24
lines changed

bun.lock

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"": {
55
"name": "kient",
66
"dependencies": {
7+
"@kakasoo/deep-strict-types": "^2.0.2",
78
"defu": "^6.1.4",
89
"destr": "^2.0.3",
910
"hono": "^4.7.2",
@@ -150,6 +151,10 @@
150151

151152
"@jridgewell/sourcemap-codec": ["@jridgewell/[email protected]", "", {}, "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ=="],
152153

154+
"@kakasoo/deep-strict-types": ["@kakasoo/[email protected]", "", { "dependencies": { "@kakasoo/proto-typescript": "^1.28.7" } }, "sha512-UdIQK2gkAiamPZonXfoiTyrtLJ7/pgFIQDJ+o8Frftf0YcRSGkFG8fIYg1uuThW0CNBZSH2dSyaGD9ElfLjZIw=="],
155+
156+
"@kakasoo/proto-typescript": ["@kakasoo/[email protected]", "", {}, "sha512-5lbFseSDzrZaQifPyDlFgCnB0duFb3ISi3fU7DGTMnZatIVEBz5rZZX0Wkq6HwsX5TNm0b+2d3s03tmPKh4WWw=="],
157+
153158
"@rollup/rollup-android-arm-eabi": ["@rollup/[email protected]", "", { "os": "android", "cpu": "arm" }, "sha512-qZdlImWXur0CFakn2BJ2znJOdqYZKiedEPEVNTBrpfPjc/YuTGcaYZcdmNFTkUj3DU0ZM/AElcM8Ybww3xVLzA=="],
154159

155160
"@rollup/rollup-android-arm64": ["@rollup/[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-4KW7P53h6HtJf5Y608T1ISKvNIYLWRKMvfnG0c44M6In4DQVU58HZFEVhWINDZKp7FZps98G3gxwC1sb0wXUUg=="],

example/get-channels.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { env } from 'bun'
2-
import { Kient } from 'kient'
2+
import { Kient, kientToJSON } from 'kient'
33

44
const kient = new Kient()
55
kient.setAuthToken(env.KICK_TOKEN as string)
66

7-
const currentUser = await kient.api.channel.getAuthorisedUser()
8-
console.log(currentUser.toJSON())
7+
// const currentUser = await kient.api.channel.getAuthorisedUser()
8+
// console.log(currentUser.toJSON())
99

10-
const multipleUsers = await kient.api.channel.getByIds([1, 2, 3])
11-
console.log(multipleUsers.map((user) => user.toJSON()))
10+
// const multipleUsers = await kient.api.channel.getByIds([1, 2, 3])
11+
// console.log(kientToJSON(multipleUsers))
1212

13-
const specificUser = await kient.api.channel.getById(2)
13+
const specificUser = await kient.api.channel.getById(676)
1414
console.log(specificUser.toJSON())

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"typescript": "^5.6.3"
4040
},
4141
"dependencies": {
42+
"@kakasoo/deep-strict-types": "^2.0.2",
4243
"defu": "^6.1.4",
4344
"destr": "^2.0.3",
4445
"hono": "^4.7.2",

src/api/channel/get-channels.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@ export interface ChannelResponse {
1212
}
1313
channel_description: string
1414
slug: string
15-
stream?: {
16-
key: string
17-
url: string
15+
stream: {
16+
key?: string
17+
url?: string
18+
category: {
19+
id: number
20+
name: string
21+
thumbnail: string
22+
}
23+
is_live: boolean
24+
is_mature: boolean
25+
language: string
26+
start_time: string
27+
stream_title: string
28+
viewer_count: number
1829
}
1930
stream_title: string
2031
}
@@ -36,9 +47,19 @@ export async function getChannelsByID(kient: Kient, ids: number[] = []) {
3647
slug: channelData.slug,
3748
bannerPicture: channelData.banner_picture,
3849
channelDescription: channelData.channel_description,
39-
streamTitle: channelData.stream_title,
40-
category: channelData.category,
41-
stream: channelData.stream,
50+
stream: {
51+
category: channelData.stream.category,
52+
isLive: channelData.stream.is_live,
53+
isMature: channelData.stream.is_mature,
54+
language: channelData.stream.language,
55+
startTime: channelData.stream.start_time,
56+
streamTitle: channelData.stream.stream_title,
57+
viewerCount: channelData.stream.viewer_count,
58+
},
59+
ingest: {
60+
key: channelData.stream.key || '',
61+
url: channelData.stream.url || '',
62+
},
4263
})
4364
channelInstances.push(channel)
4465
}

src/structures/channel.ts

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import type { DeepStrictOmit } from '@kakasoo/deep-strict-types'
12
import type { Kient } from '../kient'
23
import { flatten, type Flattened } from '../util/flatten'
34
import { Base } from './base'
45
import { Category } from './category'
56

7+
type ChannelParams = DeepStrictOmit<Flattened<Channel>, 'stream.startTime'> & {
8+
stream: {
9+
startTime: string
10+
}
11+
}
12+
613
/**
714
* Data structure of a user's channel
815
*
@@ -30,19 +37,50 @@ export class Channel extends Base {
3037
channelDescription: string
3138

3239
/**
33-
* The stream title of the channel
40+
* The channel's current stream details
41+
* Note: If the channel is currently not live, this will show data of the most recent broadcast ot live, this will show data of the most recent broadcast ot live, this will show data of the most recent broadcast
3442
*/
35-
streamTitle: string
43+
stream: {
44+
/**
45+
* The current directory category of the stream
46+
*/
47+
category: Category
3648

37-
/**
38-
* The current directory category of the channel
39-
*/
40-
category: Category
49+
/**
50+
* Indicates if the stream is currently live
51+
*/
52+
isLive: boolean
53+
54+
/**
55+
* Indicates if the stream is for mature audiences only
56+
*/
57+
isMature: boolean
58+
59+
/**
60+
* The primary language of the stream
61+
*/
62+
language: string
63+
64+
/**
65+
* The start time of the stream
66+
*/
67+
startTime: Date
68+
69+
/**
70+
* The title of the stream
71+
*/
72+
streamTitle: string
73+
74+
/**
75+
* The viewer count of the stream
76+
*/
77+
viewerCount: number
78+
}
4179

4280
/**
43-
* The stream key details of the channel
81+
* The channel's private ingest details
4482
*/
45-
stream?: {
83+
ingest?: {
4684
/**
4785
* The stream key of the channel
4886
*/
@@ -55,16 +93,28 @@ export class Channel extends Base {
5593
}
5694

5795
/** @internal */
58-
constructor(kient: Kient, data: Flattened<Channel>) {
96+
constructor(kient: Kient, data: ChannelParams) {
5997
super(kient)
6098

6199
this.id = data.id
62100
this.slug = data.slug
63101
this.bannerPicture = data.bannerPicture
64102
this.channelDescription = data.channelDescription
65-
this.streamTitle = data.streamTitle
66-
this.category = new Category(kient, data.category)
67-
this.stream = data.stream
103+
this.stream = {
104+
category: new Category(kient, data.stream.category),
105+
isLive: data.stream.isLive,
106+
isMature: data.stream.isMature,
107+
language: data.stream.language,
108+
startTime: new Date(data.stream.startTime),
109+
streamTitle: data.stream.streamTitle,
110+
viewerCount: data.stream.viewerCount,
111+
}
112+
if (data.ingest?.key && data.ingest.url) {
113+
this.ingest = {
114+
key: data.ingest.key,
115+
url: data.ingest.url,
116+
}
117+
}
68118
}
69119

70120
toJSON() {

0 commit comments

Comments
 (0)