Skip to content

Commit

Permalink
Move plugins to Sol (#5622)
Browse files Browse the repository at this point in the history
Co-authored-by: Nerixyz <nerixdev@outlook.de>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
  • Loading branch information
3 people authored Oct 20, 2024
1 parent 9345050 commit 352a4ec
Show file tree
Hide file tree
Showing 42 changed files with 2,062 additions and 2,150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
matrix:
os: [macos-13]
qt-version: [5.15.2, 6.7.1]
plugins: [false]
plugins: [true]
fail-fast: false
env:
C2_BUILD_WITH_QT6: ${{ startsWith(matrix.qt-version, '6.') && 'ON' || 'OFF' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
matrix:
os: [windows-latest]
qt-version: [5.15.2, 6.7.1]
plugins: [false]
plugins: [true]
skip-artifact: [false]
skip-crashpad: [false]
fail-fast: false
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@
[submodule "lib/expected-lite"]
path = lib/expected-lite
url = /~https://github.com/martinmoene/expected-lite
[submodule "lib/sol2"]
path = lib/sol2
url = /~https://github.com/ThePhD/sol2.git
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
- Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607)
- Dev: `GIFTimer` is no longer initialized in tests. (#5608)
- Dev: Emojis now use flags instead of a set of strings for capabilities. (#5616)
- Dev: Move plugins to Sol2. (#5622)
- Dev: Refactored static `MessageBuilder` helpers to standalone functions. (#5652)
- Dev: Decoupled reply parsing from `MessageBuilder`. (#5660)

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ endif()
if (CHATTERINO_PLUGINS)
set(LUA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/lua/src")
add_subdirectory(lib/lua)

find_package(Sol2 REQUIRED)
endif()

if (BUILD_WITH_CRASHPAD)
Expand Down
21 changes: 21 additions & 0 deletions cmake/FindSol2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include(FindPackageHandleStandardArgs)

find_path(Sol2_INCLUDE_DIR sol/sol.hpp HINTS ${CMAKE_SOURCE_DIR}/lib/sol2/include)

find_package_handle_standard_args(Sol2 DEFAULT_MSG Sol2_INCLUDE_DIR)

if (Sol2_FOUND)
add_library(Sol2 INTERFACE IMPORTED)
set_target_properties(Sol2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Sol2_INCLUDE_DIR}"
)
target_compile_definitions(Sol2 INTERFACE
SOL_ALL_SAFETIES_ON=1
SOL_USING_CXX_LUA=1
SOL_NO_NIL=0
)
target_link_libraries(Sol2 INTERFACE lua)
add_library(sol2::sol2 ALIAS Sol2)
endif ()

mark_as_advanced(Sol2_INCLUDE_DIR)
89 changes: 57 additions & 32 deletions docs/plugin-meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -131,31 +161,15 @@ 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.
---
---@param id string ID of the owner of the channel.
---@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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
23 changes: 7 additions & 16 deletions docs/wip-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand All @@ -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)`
Expand Down Expand Up @@ -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()`
Expand Down
Loading

0 comments on commit 352a4ec

Please sign in to comment.