import { EventEmitter } from 'node:events' import type { ActivityRef } from '../../shared/schemas.ts' import type { MessageRef, ReplyTarget } from '../atproto/bot.ts' /** Side effects the bot can have on Streamplace. Swapped for a recorder in tests. */ export interface Platform { botDid(): string canSend(): boolean send(channelDid: string, text: string, reply?: ReplyTarget): Promise hide(channelDid: string, messageUri: string): Promise block(channelDid: string, subjectDid: string): Promise unblock(channelDid: string, blockUri: string): Promise findBlocks(channelDid: string, subjectDid: string): Promise pin(channelDid: string, messageUri: string, expiresAt?: string): Promise updateStream(channelDid: string, patch: { title?: string; activity?: ActivityRef | null }): Promise } /** Live events pushed to dashboards over SSE. */ export type ChannelEvent = | { type: 'chat'; message: ChatEntry } | { type: 'hidden'; uri: string } | { type: 'live'; live: unknown } | { type: 'media' } | { type: 'giveaway' } | { type: 'audit'; entry: unknown } | { type: 'status'; status: unknown } export interface ChatEntry { uri: string did: string handle: string displayName: string text: string badges: string[] color: string | null createdAt: string isBot: boolean hidden: boolean } export const bus = new EventEmitter<{ event: [string, ChannelEvent] }>() bus.setMaxListeners(1000) export function publish(channelId: string, event: ChannelEvent) { bus.emit('event', channelId, event) }