Skip to content
ForgeCastDocs

Chat

Read chat, listen for it, and filter it before anyone sees it.

Functions

chats.get(opts)

Recent chat from every stream being watched, oldest first.

Returns Chat[]

chats.count(opts)

How many chat lines match.

Returns integer

chats.authors(opts)

The people who wrote recently, most active first: { id, name, avatar, count, last_ts, is_member, is_mod, is_owner }.

Returns table[]

chats.random(opts)

Pick a random line of recent chat (one per person by default, so it's fair for giveaways). Returns nil when nothing matches. With count it returns a list instead.

Returns Chat|nil

chats.on(event, handler, opts)

Run handler for chat events. The history read when a stream is first opened is skipped unless you pass { backlog = true }. Returns an id for chats.off.

Name

Type

Returns integer id

chats.on(Event.SuperChat, function(chat)
  ui.notify{ title = chat.author.name, message = chat.amount_text }
end)

chats.off(id)

Stop a handler made with chats.on.

  • id: integer

Returns boolean found

chats.use(handler)

Middleware: look at every new line before it is shown anywhere (Dashboard, pop-out, alerts, other plugins). Return false to block it (optionally with a reason for the console), a string or { text = "…" } to change its text, or nothing to let it through. Keep it quick: a slow middleware is skipped.

  • handler: fun(chat: Chat): boolean|string|{ text?: string, drop?: boolean, reason?: string }|nil, string?

Returns integer id

chats.use(function(chat)
  if chat.text:lower():find("spam") then return false, "contains spam" end
end)

chats.unuse(id)

Remove middleware made with chats.use.

  • id: integer

Returns boolean found

Types

Open a type to see its fields; type names above link here.

On this page