Move plugins to Sol (#5622)

Co-authored-by: Nerixyz <nerixdev@outlook.de>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL
2024-10-20 11:57:05 +02:00
committed by GitHub
parent 9345050868
commit 352a4ec132
42 changed files with 2120 additions and 2208 deletions
+57 -32
View File
@@ -5,14 +5,23 @@
-- Add the folder this file is in to "Lua.workspace.library".
c2 = {}
---@alias c2.LogLevel integer
---@type { Debug: c2.LogLevel, Info: c2.LogLevel, Warning: c2.LogLevel, Critical: c2.LogLevel }
---@alias c2.LogLevel.Debug "c2.LogLevel.Debug"
---@alias c2.LogLevel.Info "c2.LogLevel.Info"
---@alias c2.LogLevel.Warning "c2.LogLevel.Warning"
---@alias c2.LogLevel.Critical "c2.LogLevel.Critical"
---@alias c2.LogLevel c2.LogLevel.Debug|c2.LogLevel.Info|c2.LogLevel.Warning|c2.LogLevel.Critical
---@type { Debug: c2.LogLevel.Debug, Info: c2.LogLevel.Info, Warning: c2.LogLevel.Warning, Critical: c2.LogLevel.Critical }
c2.LogLevel = {}
---@alias c2.EventType integer
---@type { CompletionRequested: c2.EventType }
-- Begin src/controllers/plugins/api/EventType.hpp
---@alias c2.EventType.CompletionRequested "c2.EventType.CompletionRequested"
---@alias c2.EventType c2.EventType.CompletionRequested
---@type { CompletionRequested: c2.EventType.CompletionRequested }
c2.EventType = {}
-- End src/controllers/plugins/api/EventType.hpp
---@class CommandContext
---@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
---@field channel c2.Channel The channel the command was executed in.
@@ -29,19 +38,40 @@ c2.EventType = {}
-- Begin src/common/Channel.hpp
---@alias c2.ChannelType integer
---@type { None: c2.ChannelType, Direct: c2.ChannelType, Twitch: c2.ChannelType, TwitchWhispers: c2.ChannelType, TwitchWatching: c2.ChannelType, TwitchMentions: c2.ChannelType, TwitchLive: c2.ChannelType, TwitchAutomod: c2.ChannelType, TwitchEnd: c2.ChannelType, Irc: c2.ChannelType, Misc: c2.ChannelType }
---@alias c2.ChannelType.None "c2.ChannelType.None"
---@alias c2.ChannelType.Direct "c2.ChannelType.Direct"
---@alias c2.ChannelType.Twitch "c2.ChannelType.Twitch"
---@alias c2.ChannelType.TwitchWhispers "c2.ChannelType.TwitchWhispers"
---@alias c2.ChannelType.TwitchWatching "c2.ChannelType.TwitchWatching"
---@alias c2.ChannelType.TwitchMentions "c2.ChannelType.TwitchMentions"
---@alias c2.ChannelType.TwitchLive "c2.ChannelType.TwitchLive"
---@alias c2.ChannelType.TwitchAutomod "c2.ChannelType.TwitchAutomod"
---@alias c2.ChannelType.TwitchEnd "c2.ChannelType.TwitchEnd"
---@alias c2.ChannelType.Misc "c2.ChannelType.Misc"
---@alias c2.ChannelType c2.ChannelType.None|c2.ChannelType.Direct|c2.ChannelType.Twitch|c2.ChannelType.TwitchWhispers|c2.ChannelType.TwitchWatching|c2.ChannelType.TwitchMentions|c2.ChannelType.TwitchLive|c2.ChannelType.TwitchAutomod|c2.ChannelType.TwitchEnd|c2.ChannelType.Misc
---@type { None: c2.ChannelType.None, Direct: c2.ChannelType.Direct, Twitch: c2.ChannelType.Twitch, TwitchWhispers: c2.ChannelType.TwitchWhispers, TwitchWatching: c2.ChannelType.TwitchWatching, TwitchMentions: c2.ChannelType.TwitchMentions, TwitchLive: c2.ChannelType.TwitchLive, TwitchAutomod: c2.ChannelType.TwitchAutomod, TwitchEnd: c2.ChannelType.TwitchEnd, Misc: c2.ChannelType.Misc }
c2.ChannelType = {}
-- End src/common/Channel.hpp
-- Begin src/controllers/plugins/api/ChannelRef.hpp
---@alias c2.Platform integer
--- This enum describes a platform for the purpose of searching for a channel.
--- Currently only Twitch is supported because identifying IRC channels is tricky.
---@type { Twitch: c2.Platform }
c2.Platform = {}
-- Begin src/providers/twitch/TwitchChannel.hpp
---@class StreamStatus
---@field live boolean
---@field viewer_count number
---@field title string Stream title or last stream title
---@field game_name string
---@field game_id string
---@field uptime number Seconds since the stream started.
---@class RoomModes
---@field subscriber_only boolean
---@field unique_chat boolean You might know this as r9kbeta or robot9000.
---@field emotes_only boolean Whether or not text is allowed in messages. Note that "emotes" here only means Twitch emotes, not Unicode emoji, nor 3rd party text-based emotes
-- End src/providers/twitch/TwitchChannel.hpp
---@class c2.Channel
c2.Channel = {}
@@ -72,7 +102,7 @@ function c2.Channel:get_display_name() end
--- Note that this does not execute client-commands.
---
---@param message string
---@param execute_commands boolean Should commands be run on the text?
---@param execute_commands? boolean Should commands be run on the text?
function c2.Channel:send_message(message, execute_commands) end
--- Adds a system message client-side
@@ -131,9 +161,8 @@ function c2.Channel:__tostring() end
--- - /automod
---
---@param name string Which channel are you looking for?
---@param platform c2.Platform Where to search for the channel?
---@return c2.Channel?
function c2.Channel.by_name(name, platform) end
function c2.Channel.by_name(name) end
--- Finds a channel by the Twitch user ID of its owner.
---
@@ -141,21 +170,6 @@ function c2.Channel.by_name(name, platform) end
---@return c2.Channel?
function c2.Channel.by_twitch_id(id) end
---@class RoomModes
---@field unique_chat boolean You might know this as r9kbeta or robot9000.
---@field subscriber_only boolean
---@field emotes_only boolean Whether or not text is allowed in messages. Note that "emotes" here only means Twitch emotes, not Unicode emoji, nor 3rd party text-based emotes
---@field follower_only number? Time in minutes you need to follow to chat or nil.
---@field slow_mode number? Time in seconds you need to wait before sending messages or nil.
---@class StreamStatus
---@field live boolean
---@field viewer_count number
---@field uptime number Seconds since the stream started.
---@field title string Stream title or last stream title
---@field game_name string
---@field game_id string
-- End src/controllers/plugins/api/ChannelRef.hpp
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
@@ -176,6 +190,9 @@ function HTTPResponse:status() end
---
function HTTPResponse:error() end
---@return string
function HTTPResponse:__tostring() end
-- End src/controllers/plugins/api/HTTPResponse.hpp
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
@@ -219,6 +236,9 @@ function HTTPRequest:set_header(name, value) end
---
function HTTPRequest:execute() end
---@return string
function HTTPRequest:__tostring() end
--- Creates a new HTTPRequest
---
---@param method HTTPMethod Method to use
@@ -230,8 +250,13 @@ function HTTPRequest.create(method, url) end
-- Begin src/common/network/NetworkCommon.hpp
---@alias HTTPMethod integer
---@type { Get: HTTPMethod, Post: HTTPMethod, Put: HTTPMethod, Delete: HTTPMethod, Patch: HTTPMethod }
---@alias HTTPMethod.Get "HTTPMethod.Get"
---@alias HTTPMethod.Post "HTTPMethod.Post"
---@alias HTTPMethod.Put "HTTPMethod.Put"
---@alias HTTPMethod.Delete "HTTPMethod.Delete"
---@alias HTTPMethod.Patch "HTTPMethod.Patch"
---@alias HTTPMethod HTTPMethod.Get|HTTPMethod.Post|HTTPMethod.Put|HTTPMethod.Delete|HTTPMethod.Patch
---@type { Get: HTTPMethod.Get, Post: HTTPMethod.Post, Put: HTTPMethod.Put, Delete: HTTPMethod.Delete, Patch: HTTPMethod.Patch }
HTTPMethod = {}
-- End src/common/network/NetworkCommon.hpp
@@ -245,7 +270,7 @@ function c2.register_command(name, handler) end
--- Registers a callback to be invoked when completions for a term are requested.
---
---@param type "CompletionRequested"
---@param type c2.EventType.CompletionRequested
---@param func fun(event: CompletionEvent): CompletionList The callback to be invoked.
function c2.register_callback(type, func) end
+7 -16
View File
@@ -171,7 +171,7 @@ function cmd_words(ctx)
-- ctx contains:
-- words - table of words supplied to the command including the trigger
-- channel - the channel the command is being run in
channel:add_system_message("Words are: " .. table.concat(ctx.words, " "))
ctx.channel:add_system_message("Words are: " .. table.concat(ctx.words, " "))
end
c2.register_command("/words", cmd_words)
@@ -183,7 +183,7 @@ Limitations/known issues:
rebuilding the window content caused by reloading another plugin will solve this.
- Spaces in command names aren't handled very well (https://github.com/Chatterino/chatterino2/issues/1517).
#### `register_callback("CompletionRequested", handler)`
#### `register_callback(c2.EventType.CompletionRequested, handler)`
Registers a callback (`handler`) to process completions. The callback takes a single table with the following entries:
@@ -207,7 +207,7 @@ function string.startswith(s, other)
end
c2.register_callback(
"CompletionRequested",
c2.EventType.CompletionRequested,
function(event)
if ("!join"):startswith(event.query) then
---@type CompletionList
@@ -219,15 +219,6 @@ c2.register_callback(
)
```
#### `Platform` enum
This table describes platforms that can be accessed. Chatterino supports IRC
however plugins do not yet have explicit access to get IRC channels objects.
The values behind the names may change, do not count on them. It has the
following keys:
- `Twitch`
#### `ChannelType` enum
This table describes channel types Chatterino supports. The values behind the
@@ -260,9 +251,9 @@ used on non-Twitch channels. Special channels while marked as
is an actual Twitch chatroom use `Channel:get_type()` instead of
`Channel:is_twitch_channel()`.
##### `Channel:by_name(name, platform)`
##### `Channel:by_name(name)`
Finds a channel given by `name` on `platform` (see [`Platform` enum](#Platform-enum)). Returns the channel or `nil` if not open.
Finds a channel given by `name`. Returns the channel or `nil` if not open.
Some miscellaneous channels are marked as if they are specifically Twitch channels:
@@ -275,7 +266,7 @@ Some miscellaneous channels are marked as if they are specifically Twitch channe
Example:
```lua
local pajladas = c2.Channel.by_name("pajlada", c2.Platform.Twitch)
local pajladas = c2.Channel.by_name("pajlada")
```
##### `Channel:by_twitch_id(id)`
@@ -363,7 +354,7 @@ pajladas:add_system_message("Hello, world!")
Returns `true` if the channel is a Twitch channel, that is its type name has
the `Twitch` prefix. This returns `true` for special channels like Mentions.
You might want `Channel:get_type() == "Twitch"` if you want to use
You might want `Channel:get_type() == c2.ChannelType.Twitch` if you want to use
Twitch-specific functions.
##### `Channel:get_twitch_id()`