|
1 | 1 | import { connect as netConnect, type Socket } from "node:net"; |
2 | 2 | import { connect as tlsConnect } from "node:tls"; |
3 | 3 | import { defineBot, tokenSetup, type BotCtx, type BotEvent, type BotHandler } from "@profullstack/sh1pt-core"; |
| 4 | +import { parseTwitchTimestamp } from "./timestamp.js"; |
4 | 5 |
|
5 | 6 | // Twitch bot using Twitch IRC chat over TLS. OAuth token via TWITCH_OAUTH_TOKEN |
6 | 7 | // with chat:read and chat:write scopes. |
@@ -203,7 +204,7 @@ function toBotEvent(message: IrcMessage, commandPrefix: string): BotEvent | unde |
203 | 204 | const channel = toChannelName(message.params[0] ?? ""); |
204 | 205 | const text = message.trailing ?? ""; |
205 | 206 | const user = parseUser(message); |
206 | | - const timestamp = tagTimestamp(message.tags["tmi-sent-ts"]); |
| 207 | + const timestamp = parseTwitchTimestamp(message.tags["tmi-sent-ts"]); |
207 | 208 | if (text.startsWith(commandPrefix) && text.length > commandPrefix.length) { |
208 | 209 | const [command, ...args] = text.slice(commandPrefix.length).trim().split(/\s+/).filter(Boolean); |
209 | 210 | if (command) { |
@@ -254,12 +255,6 @@ function parseUser(message: IrcMessage): BotEvent["user"] { |
254 | 255 | }; |
255 | 256 | } |
256 | 257 |
|
257 | | -function tagTimestamp(value: string | undefined): string { |
258 | | - if (!value) return new Date().toISOString(); |
259 | | - const timestamp = Number(value); |
260 | | - return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : new Date().toISOString(); |
261 | | -} |
262 | | - |
263 | 258 | function matches(handler: BotHandler, event: BotEvent): boolean { |
264 | 259 | const match = handler.match; |
265 | 260 | if (match.type !== event.type) return false; |
|
0 commit comments