feat(plugins): minimal account API (#6554)

Co-authored-by: Mm2PL <mm2pl+gh@kotmisia.pl>
Reviewed-by: Mm2PL <mm2pl+gh@kotmisia.pl>
This commit is contained in:
nerix
2025-12-05 15:56:51 +01:00
committed by GitHub
parent c4ed716c33
commit c67953d14f
10 changed files with 266 additions and 0 deletions
+10
View File
@@ -376,6 +376,16 @@ declare namespace c2 {
Original,
Repost,
}
class TwitchAccount implements IWeakResource {
is_valid(): boolean;
user_login(): string;
user_id(): string;
color(): string;
is_anon(): boolean;
}
function current_account(): TwitchAccount;
}
declare module "chatterino.json" {
+32
View File
@@ -54,6 +54,38 @@ c2.ChannelType = {
-- End src/common/Channel.hpp
-- Begin src/controllers/plugins/api/Accounts.hpp
---@class c2.TwitchAccount
c2.TwitchAccount = {}
--- Returns true if the account this object points to is valid.
--- If the object expired, returns false
---
---@return boolean success
function c2.TwitchAccount:is_valid() end
---@return string user_login The (login) name of the account
function c2.TwitchAccount:login() end
---@return string user_id The Twitch user ID of the account
function c2.TwitchAccount:id() end
---@return string? color Color in chat of this account. `nil` if not yet known
function c2.TwitchAccount:color() end
---@return boolean is_anon `true` if this account is an anonymous account (no associated Twitch user)
function c2.TwitchAccount:is_anon() end
---@return string str
function c2.TwitchAccount:__tostring() end
---Gets the currently logged in Twitch account. This account might be an anonymous one (see `is_anon`).
---@return c2.TwitchAccount account
function c2.current_account() end
-- End src/controllers/plugins/api/Accounts.hpp
-- Begin src/controllers/plugins/api/ChannelRef.hpp
-- Begin src/providers/twitch/TwitchChannel.hpp
+45
View File
@@ -219,6 +219,51 @@ c2.register_callback(
)
```
#### `current_account()`
Returns a `TwitchAccount` representing the current account.
#### `TwitchAccount`
Represents a Twitch account. There can only be one selected at a time but
unselected accounts stay valid. An account can become invalid if removed by the
user in the settings. Using an invalid account produces an error.
```lua
local acc = c2.current_account()
print(acc:is_valid()) -- true unless user removed account
```
##### `TwitchAccount:login()`
Returns the login name of the account. This string may only contain lowercase ASCII.
```lua
print(acc:login()) -- "mm2pl"
```
##### `TwitchAccount:id()`
Returns the Twitch user ID of the account. This uniquely and persistently identifies the account.
```lua
print(acc:id()) -- "117691339"
```
##### `TwitchAccount:color()`
Returns the color in chat of this account. If the user has not sent any
messages this will be `nil`.
```lua
print(acc:color()) -- "#ffdaa520"
```
##### `TwitchAccount:is_anon()`
Returns `true` if this account is an anonymous account (no associated Twitch user).
#### `ChannelType` enum
This table describes channel types Chatterino supports. The values behind the