API_Events - frankischilling/crust GitHub Wiki
Events
Callbacks registered with c2.register_callback() receive a typed Lua table.
Every payload includes a type field matching the event name.
Common Nested Tables
Some events include nested tables reused across the API:
channel: same shape asc2.channel_by_name()badge: badge snapshot tablename_paint: sender name-paint tableprofile: user profile snapshot tablemessage: chat message tablesender: message sender tableflags: message flags tablereply: reply metadata tabletwitch_emote: Twitch emote range tablenotice: system notice tableitem: AutoMod queue item tablerequest: unban-request tableivr_log_entry: IVR log entry table
The shared channel table includes:
namedisplay_nameplatform: one oftwitch,kick, orircidis_twitchis_ircis_kickis_joined: omitted only when the host has no channel snapshotis_mod: omitted only when the host has no channel snapshotis_vip: omitted only when the host has no channel snapshotis_broadcaster: omitted only when the host has no channel snapshot
The shared badge table includes:
nameversionurl: omitted when the badge has no image URL
The shared name_paint table includes:
functionangle: omitted when the paint has no anglerepeatimage_url: omitted when the paint has no backing image URLshadows: always present, possibly emptystops: always present, possibly empty
Each shadows entry includes:
x_offsety_offsetradiuscolor
Each stops entry includes:
at: integer stop position in thousandthscolor
The shared message table includes:
idserver_id: omitted when the message has no server-assigned idtimestampchannelsenderraw_textspans: always present, possibly emptytwitch_emotes: always present, possibly emptyflagsreply: omitted when the message is not a replymsg_kind
The shared sender table includes:
user_idlogindisplay_namecolor: omitted when the sender has no colorname_paint: omitted when the sender has no resolved name paintbadges: always present, possibly empty
The shared flags table includes:
is_actionis_highlightedis_deletedis_first_msgis_pinnedis_selfis_mentioncustom_reward_id: omitted when the message is not tied to a custom rewardis_history
The shared reply table includes:
parent_msg_idparent_user_loginparent_display_nameparent_msg_body
The shared twitch_emote table includes:
idstartend
The shared profile table includes:
idlogindisplay_namedescriptioncreated_at: omitted when unavailableavatar_url: omitted when unavailablefollowers: omitted when unavailableis_partneris_affiliatepronouns: omitted when unavailablefollowed_at: omitted when unavailablechat_color: omitted when unavailableis_livestream_title: omitted when unavailablestream_game: omitted when unavailablestream_viewers: omitted when unavailablelast_broadcast_at: omitted when unavailableis_bannedban_reason: omitted when unavailable
The shared notice table includes:
channel: omitted when the notice is not tied to a specific channeltexttimestamp
The shared item table includes:
message_idsender_user_idsender_logintextreason: omitted when the queue item has no moderation reason
The shared request table includes:
request_iduser_iduser_logintext: omitted when unavailablecreated_at: omitted when unavailablestatus: omitted when unavailable
The shared ivr_log_entry table includes:
texttimestampdisplay_namemsg_type
Completion
c2.EventType.CompletionRequested
Fields:
queryfull_text_contentcursor_positionis_first_wordchannel: omitted when completion is requested without channel context
Return a table with:
valueshide_others
Account And Connection Events
c2.EventType.Authenticated
Fields:
usernameuser_id
c2.EventType.LoggedOut
No payload fields.
c2.EventType.AccountListUpdated
Fields:
accountsactive: omitted when no authenticated account is activedefault: omitted when no default account is configured
c2.EventType.ConnectionStateChanged
Fields:
state
state is currently rendered to one of these strings:
DisconnectedConnecting…ConnectedReconnecting (attempt N)…Error: ...
c2.EventType.AuthExpired
No payload fields.
Loader And Emote Events
c2.EventType.EmoteImageReady
Fields:
uriwidthheightraw_bytes_base64
raw_bytes_base64 contains the image bytes encoded as base64.
No Lua numeric byte array is emitted.
c2.EventType.EmoteCatalogUpdated
Fields:
emotes
Each emotes entry includes:
codeproviderurlscope
c2.EventType.ImagePrefetchQueued
Fields:
count
This event reports how many image-prefetch jobs were queued.
Chat And Channel Events
c2.EventType.ChannelJoined
Fields:
channel
c2.EventType.ChannelParted
Fields:
channel
c2.EventType.ChannelRedirected
Fields:
old_channelnew_channel
c2.EventType.ChannelMessagesCleared
Fields:
channel
This event reports that the runtime cleared the whole visible channel buffer.
c2.EventType.ClearUserMessagesLocally
Fields:
channel
This event reports a local-only request to hide one user's messages in the current channel view.
c2.EventType.MessageReceived
Fields:
channelmessage
The message table includes the same rich message metadata the UI uses,
including sender data, spans, flags, timestamps, reply info, and message kind.
message, sender, flags, and reply use the shared table shapes
documented above.
Each spans entry includes a type field and then type-specific fields:
Text:text,is_actionEmote:id,code,url,url_hd,providerEmoji:text,urlBadge:name,versionMention:loginUrl:text,url
For Emote, url_hd is omitted when no HD image URL exists.
The nested msg_kind table includes a type field and then variant-specific fields:
ChatSub:display_name,months,plan,is_gift,sub_msgRaid:display_name,viewer_countTimeout:login,secondsBan:loginChatClearedSystemInfoChannelPointsReward:user_login,reward_title,cost,reward_id,redemption_id,user_input,statusSuspiciousUserMessageBits:amount
For ChannelPointsReward, reward_id, redemption_id, user_input, and
status are omitted when unavailable.
c2.EventType.WhisperReceived
Fields:
from_loginfrom_display_nametarget_logintexttwitch_emotesis_selftimestampis_history
Each twitch_emotes entry includes:
idstartend
c2.EventType.MessageDeleted
Fields:
channelserver_id
c2.EventType.UserMessagesCleared
Fields:
channellogin
This event reports a moderation-driven user clear from the runtime.
c2.EventType.SystemNotice
Fields:
notice
The nested notice table includes:
channeltexttimestamp
c2.EventType.Error
Fields:
contextmessage
c2.EventType.IrcTopicChanged
Fields:
channeltopic
c2.EventType.UserStateUpdated
Fields:
channelis_modbadgescolor: omitted when the runtime has no user color
Each badges entry includes:
nameversionurl
Each badge entry uses the shared badge table shape, so url is omitted when
the badge has no image URL.
c2.EventType.SelfAvatarLoaded
Fields:
avatar_url
c2.EventType.SenderCosmeticsUpdated
Fields:
user_idcolor: omitted when no color update is availablename_paint: omitted when no name-paint update is availablebadge: omitted when no badge update is availableavatar_url: omitted when no avatar update is available
When present, name_paint includes:
functionanglerepeatimage_urlshadowsstops
Each shadows entry includes:
x_offsety_offsetradiuscolor
Each stops entry includes:
atcolor
When present, badge uses the shared badge table shape.
Fetch Result Events
c2.EventType.HistoryLoaded
Fields:
channelmessages
Each messages entry uses the same message table shape documented under
c2.EventType.MessageReceived.
c2.EventType.UserProfileLoaded
Fields:
profile
profile uses the shared profile table shape documented above, including the
same omission rules for optional fields.
c2.EventType.UserProfileUnavailable
Fields:
login
c2.EventType.StreamStatusUpdated
Fields:
loginis_livetitle: omitted when unavailablegame: omitted when unavailableviewers: omitted when unavailable
c2.EventType.IvrLogsLoaded
Fields:
usernamemessages
Each messages entry includes:
texttimestampdisplay_namemsg_type
msg_type is currently:
1: normal message2: timeout/ban event
c2.EventType.IvrLogsFailed
Fields:
usernameerror
c2.EventType.ChannelEmotesLoaded
Fields:
channelcount
c2.EventType.LinkPreviewReady
Fields:
urltitledescriptionthumbnail_urlsite_name
These fields are omitted when the upstream metadata source does not provide them.
Settings And Moderation Events
c2.EventType.BetaFeaturesUpdated
Fields:
kick_enabledirc_enabledirc_nickserv_userirc_nickserv_passalways_on_top
c2.EventType.ChatUiBehaviorUpdated
Fields:
prevent_overlong_twitch_messagescollapse_long_messagescollapse_long_message_linesanimations_when_focused
c2.EventType.GeneralSettingsUpdated
Fields:
show_timestampsshow_timestamp_secondsuse_24h_timestampslocal_log_indexing_enabledauto_joinhighlightsignoresdesktop_notifications_enabled
c2.EventType.SlashUsageCountsUpdated
Fields:
usage_counts
Each usage_counts entry includes:
namecount
c2.EventType.EmotePickerPreferencesUpdated
Fields:
favoritesrecentprovider_boost
c2.EventType.AppearanceSettingsUpdated
Fields:
channel_layoutsidebar_visibleanalytics_visibleirc_status_visibletab_styleshow_tab_close_buttonsshow_tab_live_indicatorssplit_header_show_titlesplit_header_show_gamesplit_header_show_viewer_count
c2.EventType.RoomStateUpdated
Fields:
channelemote_only: omitted when unchanged or unavailablefollowers_only: omitted when unchanged or unavailableslow: omitted when unchanged or unavailablesubs_only: omitted when unchanged or unavailabler9k: omitted when unchanged or unavailable
c2.EventType.AutoModQueueAppend
Fields:
channelitem
The nested item table includes:
message_idsender_user_idsender_logintextreason
c2.EventType.AutoModQueueRemove
Fields:
channelmessage_idaction
action is omitted when the runtime removes the queue item without reporting a
resolution string.
c2.EventType.UnbanRequestsLoaded
Fields:
channelrequests
Each requests entry includes:
request_iduser_iduser_logintextcreated_atstatus
c2.EventType.UnbanRequestsFailed
Fields:
channelerror
c2.EventType.UnbanRequestUpsert
Fields:
channelrequest
The nested request table includes:
request_iduser_iduser_logintextcreated_atstatus
c2.EventType.UnbanRequestResolved
Fields:
channelrequest_idstatus
c2.EventType.OpenModerationTools
Fields:
channel
channel may be omitted when the host opens the moderation tools without a
specific channel target.
c2.EventType.HighlightRulesUpdated
Fields:
rules
Each rules entry includes:
patternis_regexcase_sensitiveenabledshow_in_mentionscolorhas_alerthas_soundsound_url
When present, color is a three-item RGB array.
sound_url is omitted when unset.
c2.EventType.FilterRecordsUpdated
Fields:
records
Each records entry includes:
namepatternis_regexcase_sensitiveenabledscopechannelactionfilter_sender
scope is currently one of:
GlobalChannel
action is currently one of:
HideDim
channel is omitted when scope is Global.
c2.EventType.ModActionPresetsUpdated
Fields:
presets
Each presets entry includes:
labelcommand_templateicon_url
icon_url is omitted when unset.
Each presets entry includes:
labelcommand_templateicon_url
icon_url is omitted when unset.
c2.EventType.PluginUiAction
Fields:
plugin_namesurface_kindsurface_idwidget_idactionvalueform_values
Notes:
- plugin UI events are dispatched only to the owning plugin
surface_kindis currentlywindow,settings_page, orhost_panel.surface_idmatches the registered window id, settings-page id, or host-panel id.actionis omitted when the widget did not declare one.valueis omitted when the action widget did not send one.form_valuesis always a table; it may be empty.
c2.EventType.PluginUiChange
Fields:
plugin_namesurface_kindsurface_idwidget_idvalueform_values
Notes:
- plugin UI events are dispatched only to the owning plugin
surface_kindis currentlywindow,settings_page, orhost_panel.surface_idmatches the registered window id, settings-page id, or host-panel id.valueis the changed widget value.valueis emitted as a plain Lua string, boolean, number, or array of strings.form_valuesis the current host-form snapshot for the surface.- controlled widgets still emit
value, but they only appear inform_valueswhenhost_form = true.
c2.EventType.PluginUiSubmit
Fields:
plugin_namesurface_kindsurface_idwidget_idactionform_values
Notes:
- plugin UI events are dispatched only to the owning plugin
surface_kindis currentlywindow,settings_page, orhost_panel.surface_idmatches the registered window id, settings-page id, or host-panel id.widget_idis omitted when the submit originated from a surface-level action without a widget id.actionis omitted when the submit widget did not declare one.form_valuesis the current host-form snapshot for the surface.
c2.EventType.PluginUiWindowClosed
Fields:
plugin_namewindow_id
Notes:
- this event is emitted when the user closes a floating plugin window through the window chrome
- calling
c2.ui.close_window(id)updates retained state but does not emitPluginUiWindowClosed
Example
c2.register_callback(c2.EventType.ImagePrefetchQueued, function(ev)
c2.log(c2.LogLevel.Info, "queued " .. tostring(ev.count or 0) .. " image jobs")
end)
c2.register_callback(c2.EventType.EmoteImageReady, function(ev)
c2.log(
c2.LogLevel.Info,
"image ready " .. tostring(ev.uri or "") .. " bytes=" .. tostring(#(ev.raw_bytes_base64 or ""))
)
end)
c2.register_callback(c2.EventType.PluginUiSubmit, function(ev)
c2.log(c2.LogLevel.Info, "saved ui surface " .. tostring(ev.surface_id or ""))
end)