@overlaysymphony/twitch 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TwitchUser,
|
|
1
|
+
import { type TwitchUser, getUser } from "../helix/users/index.ts"
|
|
2
2
|
|
|
3
3
|
export interface Authentication {
|
|
4
4
|
tokenType: "bearer"
|
|
@@ -61,7 +61,10 @@ export async function getAuthentication(
|
|
|
61
61
|
return undefined
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const
|
|
64
|
+
const user = await getUser(authentication as Authentication)
|
|
65
|
+
if (!user) {
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
65
68
|
|
|
66
69
|
return {
|
|
67
70
|
...authentication,
|
package/src/chat/chat.ts
CHANGED
|
@@ -21,13 +21,7 @@ type ChatMessageSubscriber = (
|
|
|
21
21
|
type ChatCommandSubscriber = (
|
|
22
22
|
name: string,
|
|
23
23
|
callback: (event: ChatCommand) => void,
|
|
24
|
-
___?: never,
|
|
25
24
|
) => () => void
|
|
26
|
-
// type ChatCommandSubscriber = (
|
|
27
|
-
// name: string,
|
|
28
|
-
// pattern: string,
|
|
29
|
-
// callback: (event: ChatCommand) => void,
|
|
30
|
-
// ) => () => void
|
|
31
25
|
|
|
32
26
|
export interface TwitchChat {
|
|
33
27
|
send: ChatSender
|
|
@@ -56,25 +50,18 @@ export default async function createChat(
|
|
|
56
50
|
})
|
|
57
51
|
}
|
|
58
52
|
|
|
59
|
-
const onCommand: ChatCommandSubscriber = (name,
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const callback = typeof args[0] === "function" ? args[0] : args[1]
|
|
63
|
-
if (!callback) {
|
|
64
|
-
throw new Error("onCommand: Missing callback.")
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const regex = new RegExp(`^\\s*!([a-z0-9])(?:\\s+(.+))$`, "i")
|
|
53
|
+
const onCommand: ChatCommandSubscriber = (name, callback) => {
|
|
54
|
+
const regex = /^\s*!([a-z0-9]+)(?:\s+(.+))?$/i
|
|
68
55
|
|
|
69
56
|
return onMessage((payload) => {
|
|
70
|
-
const [command, text] =
|
|
57
|
+
const [, command, text] =
|
|
71
58
|
payload.message.text.match(regex) ?? ([] as Array<string | undefined>)
|
|
72
59
|
|
|
73
60
|
if (command !== name) {
|
|
74
61
|
return
|
|
75
62
|
}
|
|
76
63
|
|
|
77
|
-
const parameters =
|
|
64
|
+
const parameters = text?.split(" ")
|
|
78
65
|
|
|
79
66
|
callback({
|
|
80
67
|
...payload,
|
package/src/helix/chat/send.ts
CHANGED
|
@@ -39,7 +39,7 @@ export async function sendChatAnnouncement(
|
|
|
39
39
|
color?: string
|
|
40
40
|
}
|
|
41
41
|
>(authentication, {
|
|
42
|
-
method: "
|
|
42
|
+
method: "POST",
|
|
43
43
|
path: "/chat/announcements",
|
|
44
44
|
params: {
|
|
45
45
|
moderator_id: authentication.user.id,
|
|
@@ -64,7 +64,7 @@ export async function sendChatShoutout(
|
|
|
64
64
|
to_broadcaster_id: string
|
|
65
65
|
}
|
|
66
66
|
>(authentication, {
|
|
67
|
-
method: "
|
|
67
|
+
method: "POST",
|
|
68
68
|
path: "/chat/shoutouts",
|
|
69
69
|
params: {
|
|
70
70
|
moderator_id: authentication.user.id,
|
|
@@ -92,7 +92,7 @@ export async function sendChatMessage(
|
|
|
92
92
|
reply_parent_message_id?: string
|
|
93
93
|
}
|
|
94
94
|
>(authentication, {
|
|
95
|
-
method: "
|
|
95
|
+
method: "POST",
|
|
96
96
|
path: "/chat/message",
|
|
97
97
|
params: {
|
|
98
98
|
sender_id: authentication.user.id,
|
package/src/helix/users/users.ts
CHANGED
|
@@ -21,11 +21,11 @@ interface UsersResponse {
|
|
|
21
21
|
>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export async function
|
|
24
|
+
export async function getUser(
|
|
25
25
|
authentication: Authentication,
|
|
26
|
-
id?: string | string[],
|
|
27
26
|
login?: string | string[],
|
|
28
|
-
|
|
27
|
+
id?: string | string[],
|
|
28
|
+
): Promise<TwitchUser | undefined> {
|
|
29
29
|
const { data: users } = await helix<
|
|
30
30
|
UsersResponse,
|
|
31
31
|
{ id?: string | string[]; login?: string | string[] }
|
|
@@ -38,8 +38,10 @@ export async function getUsers(
|
|
|
38
38
|
},
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const [{ created_at, ...user }] = users
|
|
42
|
+
|
|
43
|
+
return {
|
|
42
44
|
...user,
|
|
43
45
|
created_at: new Date(created_at),
|
|
44
|
-
}
|
|
46
|
+
}
|
|
45
47
|
}
|