feat(plugins): allow message introspection (#6353)

This allows users to introspect messages (i.e. look at the elements they're made up of).

Reviewed-by: Mm2PL <mm2pl+gh@kotmisia.pl>
This commit is contained in:
nerix
2025-12-07 15:52:59 +01:00
committed by GitHub
parent 0aff6fbe83
commit 74b4674c6b
12 changed files with 1836 additions and 210 deletions
+125 -1
View File
@@ -160,8 +160,24 @@ declare namespace c2 {
var WebSocket: WebSocketConstructor;
interface Message {
__dummy: void; // avoid being an empty interface
flags: MessageFlag;
id: string;
parse_time: number;
search_text: string;
message_text: string;
login_name: string;
display_name: string;
localized_name: string;
user_id: string;
channel_name: string;
username_color: string;
server_received_time: number;
highlight_color: string | null;
frozen: boolean;
elements(): MessageElement[];
append_element(init: MessageElementInit): void;
}
interface MessageConstructor {
new: (this: void, init: MessageInit) => Message;
}
@@ -184,6 +200,14 @@ declare namespace c2 {
elements?: MessageElementInit[];
}
interface MessageElementBase {
flags: MessageElementFlag;
tooltip: string;
trailing_space: boolean;
link: Link;
add_flags(flags: MessageElementFlag): void;
}
interface MessageElementInitBase {
tooltip?: string;
trailing_space?: boolean;
@@ -192,6 +216,25 @@ declare namespace c2 {
type MessageColor = "text" | "link" | "system" | string;
type MessageElement =
| TextElement
| SingleLineTextElement
| MentionElement
| TimestampElement
| TwitchModerationElement
| LinebreakElement
| ReplyCurveElement
| LinkElement
| EmoteElement
| LayeredEmoteElement
| ImageElement
| CircularImageElement
| ScalingImageElement
| BadgeElement
| ModBadgeElement
| VipBadgeElement
| FfzBadgeElement;
type MessageElementInit =
| TextElementInit
| SingleLineTextElementInit
@@ -201,6 +244,13 @@ declare namespace c2 {
| LinebreakElementInit
| ReplyCurveElementInit;
interface TextElement extends MessageElementBase {
type: "text";
words: string[];
color: string;
style: c2.FontStyle;
}
interface TextElementInit extends MessageElementInitBase {
type: "text";
text: string;
@@ -209,6 +259,13 @@ declare namespace c2 {
style?: FontStyle;
}
interface SingleLineTextElement extends MessageElementBase {
type: "single-line-text";
words: string[];
color: string;
style: c2.FontStyle;
}
interface SingleLineTextElementInit extends MessageElementInitBase {
type: "single-line-text";
text: string;
@@ -217,6 +274,14 @@ declare namespace c2 {
style?: FontStyle;
}
interface MentionElement extends Omit<TextElement, "type"> {
type: "mention";
display_name: string;
login_name: string;
fallback_color: string;
user_color: string;
}
interface MentionElementInit extends MessageElementInitBase {
type: "mention";
display_name: string;
@@ -225,24 +290,83 @@ declare namespace c2 {
user_color: MessageColor;
}
interface TimestampElement extends MessageElementBase {
type: "timestamp";
time: number;
}
interface TimestampElementInit extends MessageElementInitBase {
type: "timestamp";
time?: number;
}
interface TwitchModerationElement extends MessageElementBase {
type: "twitch-moderation";
}
interface TwitchModerationElementInit extends MessageElementInitBase {
type: "twitch-moderation";
}
interface LinebreakElement extends MessageElementBase {
type: "linebreak";
}
interface LinebreakElementInit extends MessageElementInitBase {
type: "linebreak";
flags?: MessageElementFlag;
}
interface ReplyCurveElement extends MessageElementBase {
type: "reply-curve";
}
interface ReplyCurveElementInit extends MessageElementInitBase {
type: "reply-curve";
}
interface LinkElement extends Omit<TextElement, "type"> {
type: "link";
lowercase: string;
original: string;
}
interface EmoteElement extends MessageElementBase {
type: "emote";
}
interface LayeredEmoteElement extends MessageElementBase {
type: "layered-emote";
}
interface ImageElement extends MessageElementBase {
type: "image";
}
interface CircularImageElement extends MessageElementBase {
type: "circular-image";
}
interface ScalingImageElement extends MessageElementBase {
type: "scaling-image";
}
interface BadgeElement extends MessageElementBase {
type: "badge";
}
interface ModBadgeElement extends Omit<BadgeElement, "type"> {
type: "mod-badge";
}
interface VipBadgeElement extends Omit<BadgeElement, "type"> {
type: "ffz-badge";
}
interface FfzBadgeElement extends Omit<BadgeElement, "type"> {
type: "ffz-badge";
}
interface Link {
type: LinkType;
value: string;