hiroyannnn/yuru-kit/lib does not have a README file

    ChatSource

    pub(open) trait ChatSource {
    async fn run(Self, emit : async (Comment) -> Unit) -> Unit
    }

    ライブチャットの入口。emit にコメントを 1 件ずつ渡す。 run は Source が尽きるまで(チャットなら配信が終わるか、呼び出し側が止めるまで)戻らない。 emit の中で起きたエラーの扱いは呼び出し側に任せる(Source は次のコメントに進む)。

    YouTubeError

    pub(all) suberror YouTubeError {
    VideoNotFound
    NotLive
    ChatUnavailable(String)
    TypeMismatch(String)
    } derive(Eq,
    Debug
    )

    YouTube Data API v3 のレスポンス解釈エラー。

    Comment

    pub(all) struct Comment {
    participant_id : String
    author : String
    text : String
    at : Int64
    emotes : Array[String]
    channel : String
    } derive(Eq, ToJson,
    Debug
    )

    Source が供給する 1 コメント。

    Comment::new

    fn Comment::new(participant_id : String, text : String, author? : String, at? : Int64, emotes? : Array[String], channel? : String) -> Comment

    Comment::platform

    fn Comment::platform(self : Comment) -> String

    参加者 ID のプレフィックス(twitch / youtube / stdin / replay)。

    InnertubeConfig

    pub(all) struct InnertubeConfig {
    api_key : String
    client_version : String
    continuation : String
    } derive(Eq,
    Debug
    )

    youtube.com/live_chat?v=… のページから取り出した、キー無しでチャットを読むための設定。 ブラウザと同じ経路(innertube)なので Data API のキーもクォータも要らないが、非公式でページ構造が変わると壊れる。

    IrcMessage

    pub(all) enum IrcMessage {
    Ping(String)
    Chat(Comment)
    Other(String)
    } derive(Eq,
    Debug
    )

    Twitch IRC から読んだ 1 行の解釈結果。

    LiveChatPage

    pub(all) struct LiveChatPage {
    comments : Array[Comment]
    next_page_token : String?
    polling_interval_ms : Int
    } derive(
    Debug
    )

    liveChatMessages.list の 1 ページ分。

    DEFAULT_POLLING_INTERVAL_MS

    let DEFAULT_POLLING_INTERVAL_MS : Int

    pollingIntervalMillis が無いときの既定値(クォータ節約のため長め)。

    connection_was_healthy

    fn connection_was_healthy(connected_ms~ : Int64, healthy_ms? : Int64) -> Bool

    切れる前の接続が十分に長くもっていたか。もっていたなら失敗の数を 0 に戻してすぐ再接続する。

    innertube_live_chat_body

    fn innertube_live_chat_body(config : InnertubeConfig, continuation : String) -> Json

    innertube_live_chat_url

    fn innertube_live_chat_url(config : InnertubeConfig) -> String

    live_chat_messages_url

    fn live_chat_messages_url(live_chat_id : String, api_key : String, page_token : String?) -> String

    liveChatMessages.list(part=snippet,authorDetails) の URL。

    merge_env

    fn merge_env(env : Map[String, String], dotenv : Map[String, String]) -> Map[String, String]

    環境変数を優先し、無いキーだけを .env で補う。

    parse_dotenv

    fn parse_dotenv(text : String) -> Map[String, String]

    .env の中身を読む。KEY=value の行だけを取り、# のコメント・空行・export を無視する。 値は前後の空白を除き、"…" / '…' で囲まれていれば中身をそのまま(囲みの外の # … は捨てる)。

    parse_get_live_chat

    fn parse_get_live_chat(json : Json) -> LiveChatPage raise YouTubeError

    get_live_chat のレスポンスを分解する。 通常のテキストとスーパーチャットを読み、システムメッセージやバナーは読み飛ばす。

    parse_irc_line

    fn parse_irc_line(raw : String) -> IrcMessage

    IRC の 1 行([@tags] [:prefix] COMMAND [params] [:trailing])を解釈する。

    parse_live_chat_id

    fn parse_live_chat_id(json : Json) -> String raise YouTubeError

    videos.list のレスポンスから activeLiveChatId を取り出す。

    parse_live_chat_page

    fn parse_live_chat_page(json : Json) -> LiveChatPage raise YouTubeError

    liveChatMessages.list のレスポンスを分解する。 displayMessage の無い項目(メンバー加入通知など)は読み飛ばす。

    parse_live_chat_page_html

    fn parse_live_chat_page_html(html : String) -> InnertubeConfig raise YouTubeError

    live_chat ページから innertube の設定を取り出す。

    parse_stdin_line

    fn parse_stdin_line(line : String, at~ : Int64, anonymous_id? : String, source? : String) -> Comment?

    標準入力の 1 行(参加者ID<TAB>発言)を Comment にする。 TAB が無ければ匿名参加者(stdin:<anonymous_id>)の発言。空行は None。 source は ID のプレフィックス(外部ブリッジをパイプするときに tiktok などへ変える)。

    participant_id

    fn participant_id(source : String, id : String) -> String

    参加者 ID を作る。Source 名をプレフィックスにして、Source 間で衝突しないようにする。

    pong_line

    fn pong_line(payload : String) -> String

    PING への返答行。

    qr_matrix

    fn qr_matrix(text : String) ->
    Matrix
    ?

    文字列(参加用 URL)を QR のマトリクスにする。空文字や長すぎる文字列は None。 誤り訂正レベルは M。スマホのカメラで画面越しに読む用途に十分な強さ。

    qr_svg

    fn qr_svg(text : String) -> String?

    文字列を余白付きの QR の SVG にする。

    reconnect_delay_ms

    fn reconnect_delay_ms(failures : Int, base_ms? : Int, max_ms? : Int) -> Int

    再接続までの待ち時間(ミリ秒)。失敗が続くごとに倍にし、max_ms で止める。

    twitch_login_lines

    fn twitch_login_lines(nick : String, channel : String) -> Array[String]

    匿名ユーザーで読み取り専用接続するためのログイン行。 twitch.tv/tags を要求して user-id・表示名・エモートの位置・送信時刻を受け取る。

    videos_list_url

    fn videos_list_url(video_id : String, api_key : String) -> String

    videos.list(part=liveStreamingDetails) の URL。