feat(plugins): add basic message construction (#5754)

This commit is contained in:
nerix
2025-07-31 15:36:39 +02:00
committed by GitHub
parent 7e7c4112d7
commit a4478748f7
29 changed files with 2070 additions and 36 deletions
+54
View File
@@ -350,6 +350,24 @@ Example:
pajladas:add_system_message("Hello, world!")
```
#### `Channel:add_message(message[, context[, override_flags]])`
Add a rich message to a channel. The message can be created with [`Message.new`](#messagenewdata).
Example:
```lua
channel:add_message(c2.Message.new({
id = "myplugin-1234",
elements = {
{
type = "text",
text = "Hello, World!",
}
}
}))
```
##### `Channel:is_twitch_channel()`
Returns `true` if the channel is a Twitch channel, that is its type name has
@@ -503,6 +521,42 @@ request:execute()
-- ConnectionRefusedError
```
#### `Message`
Allows creation of rich chat messages. This is currently limited but is expected to be expanded soon.
##### `Message.new(data)`
Creates a new message from a table. The message can be added to a channel using
[`Channel:add_message`](#channeladd_messagemessage-context-override_flags):
```lua
c2.register_command("/testing", function(ctx)
ctx.channel:add_message(c2.Message.new({
id = "myplugin-1234",
highlight_color = "#80ff0000",
flags = c2.MessageFlag.Highlighted,
elements = {
{
type = "text",
color = "link",
text = "Hover me!",
tooltip = "<h1>This is text from my plugin</h1>"
},
{
type = "mention",
display_name = "@User",
login_name = "twitchdev",
fallback_color = "text",
user_color = "blue",
}
}
}))
end)
```
The full range of options can be found in the typing files ([LuaLS](./plugin-meta.lua), [TypeScript](./chatterino.d.ts)).
### Input/Output API
These functions are wrappers for Lua's I/O library. Functions on file pointer