1 parent
97dc183bdf
commit
e7573fbcd0
6 files changed
+193
-22
No files matched your search
@@ -29,6 +29,9 @@ namespace Echoion::Api
|
||||
struct BotConfig {
|
||||
std::string botName = "Echoion";
|
||||
std::string commandPrefix = "!";
|
||||
// Default bot language ("en" or "ru"). Applies to users who have not
|
||||
// picked a per-user language. Anything else normalises to "en".
|
||||
std::string language = "en";
|
||||
float defaultVolume = 0.5f;
|
||||
uint32_t maxQueueSize = 100;
|
||||
// How long the playback engine waits (emitting silence) for a
|
||||
@@ -58,6 +61,27 @@ namespace Echoion::Api
|
||||
std::string rpcBindAddress = "127.0.0.1";
|
||||
};
|
||||
|
||||
// Browser web interface (EchoionWeb). Serves the static UI and hosts the
|
||||
// independent sync-watch WebSocket. Bot control from the browser goes
|
||||
// directly to the RPC server (network.rpcPort), not through this server.
|
||||
struct WebConfig {
|
||||
bool enabled = false;
|
||||
uint16_t port = 8080;
|
||||
std::string bindAddress = "127.0.0.1";
|
||||
std::string webRoot = "./web";
|
||||
// Explicit RPC WebSocket URL the browser should use. When empty the
|
||||
// UI derives ws://<page-host>:<rpcPort> from the served config.
|
||||
std::string rpcUrl;
|
||||
// Public address users reach the web interface at (e.g.
|
||||
// "https://bot.example.com"). Presentation only — !help links to
|
||||
// it when set; serving is unaffected.
|
||||
std::string publicUrl;
|
||||
// Allow the Now Playing view to show the current song's video
|
||||
// (muted, synced). Users can still disable it locally; this is
|
||||
// the server-wide off switch, surfaced through /config.json.
|
||||
bool nowPlayingVideo = true;
|
||||
};
|
||||
|
||||
// Music source resolution chain. Default order tries the native
|
||||
// innertube YouTube path and Yandex Music first, then falls back to
|
||||
// (optionally proxied) yt-dlp last.
|
||||
@@ -108,6 +132,9 @@ namespace Echoion::Api
|
||||
std::chrono::milliseconds(3600000);
|
||||
bool enableAuditLog = true;
|
||||
std::optional<std::string> apiKey;
|
||||
// Reserved, not currently honored: the web UI, /rpc bridge and /ws
|
||||
// are all same-origin behind the web server, so no CORS headers are
|
||||
// emitted anywhere.
|
||||
bool allowCors = false;
|
||||
std::vector<std::string> corsOrigins;
|
||||
};
|
||||
@@ -136,6 +163,10 @@ namespace Echoion::Api
|
||||
std::string shuffleMode = "off";
|
||||
std::string repeatMode = "off";
|
||||
uint32_t maxHistorySize = 50;
|
||||
|
||||
// Vote-to-skip: votes needed to skip the current track.
|
||||
// 0 = majority of online subscribers.
|
||||
uint32_t voteSkipThreshold = 0;
|
||||
};
|
||||
|
||||
// Advanced Settings
|
||||
@@ -181,6 +212,7 @@ namespace Echoion::Api
|
||||
FeaturesConfig features;
|
||||
AdvancedConfig advanced;
|
||||
AdminCredentials admin;
|
||||
WebConfig web;
|
||||
std::map<std::string, ConfigEntry> custom;
|
||||
};
|
||||
|
||||
|
||||
@@ -64,6 +64,27 @@ namespace Echoion::Api
|
||||
uint64_t mostPlayedCount = 0;
|
||||
};
|
||||
|
||||
// Server-wide aggregate statistics (web dashboard)
|
||||
struct AggregateStats {
|
||||
uint64_t tracksToday = 0; // completed plays today
|
||||
uint64_t listeningMsToday = 0; // summed play duration today
|
||||
uint64_t queueAdditionsToday = 0;
|
||||
uint64_t skipsToday = 0;
|
||||
uint64_t playsTotal = 0;
|
||||
uint64_t skipsTotal = 0;
|
||||
// Most active requesters, most additions first.
|
||||
struct TopRequester {
|
||||
std::string uid; // TeamSpeak uid (may be empty for old rows)
|
||||
std::string nickname;
|
||||
uint64_t count = 0;
|
||||
};
|
||||
std::vector<TopRequester> topRequesters;
|
||||
// Source split over the whole history
|
||||
uint64_t youtubeCount = 0;
|
||||
uint64_t yandexCount = 0;
|
||||
uint64_t otherCount = 0;
|
||||
};
|
||||
|
||||
// Main database interface
|
||||
class Database
|
||||
{
|
||||
@@ -158,6 +179,14 @@ namespace Echoion::Api
|
||||
[[nodiscard]] Api::Result<std::vector<TrackInfo>>
|
||||
getRecentlyPlayed(uint64_t userId, size_t limit = 20);
|
||||
|
||||
// Record a skipped track (playback aborted by user action)
|
||||
Api::Result<void> recordSkip(const TrackInfo& track,
|
||||
uint64_t playedBy);
|
||||
|
||||
// Log a queue addition (daily stats / top requesters)
|
||||
Api::Result<void> logQueueAddition(const std::string& uid,
|
||||
const std::string& nickname);
|
||||
|
||||
// ===== Favorites =====
|
||||
|
||||
// Add track to favorites
|
||||
@@ -189,6 +218,9 @@ namespace Echoion::Api
|
||||
std::vector<std::pair<TrackInfo, uint64_t>>>
|
||||
getMostPlayed(uint64_t userId, size_t limit = 10);
|
||||
|
||||
// Get server-wide aggregate statistics (web dashboard)
|
||||
[[nodiscard]] Api::Result<AggregateStats> getAggregateStats();
|
||||
|
||||
// ===== Key/value store =====
|
||||
// Small persisted state (healthy instance lists, ...). Values
|
||||
// are opaque strings (callers serialize as needed).
|
||||
@@ -197,6 +229,53 @@ namespace Echoion::Api
|
||||
Api::Result<void> setKv(const std::string& key,
|
||||
const std::string& value);
|
||||
|
||||
// ===== Custom emojis (web UI image emotes) =====
|
||||
// Admin-managed image emotes referenced by :name: shortcodes in
|
||||
// watch chat/reactions. `data` is base64-encoded image bytes.
|
||||
struct CustomEmoji {
|
||||
std::string name;
|
||||
std::string mime;
|
||||
std::string dataBase64;
|
||||
std::string addedBy;
|
||||
};
|
||||
[[nodiscard]] Api::Result<std::vector<CustomEmoji>>
|
||||
getCustomEmojis();
|
||||
// Image (mime + base64 data) for one emoji name, or nullopt.
|
||||
[[nodiscard]] Api::Result<std::optional<CustomEmoji>>
|
||||
getCustomEmoji(const std::string& name);
|
||||
Api::Result<void> addCustomEmoji(const std::string& name,
|
||||
const std::string& mime,
|
||||
const std::string& dataBase64,
|
||||
const std::string& addedBy);
|
||||
Api::Result<void> removeCustomEmoji(const std::string& name);
|
||||
|
||||
// ===== Cached avatars (web UI) =====
|
||||
// TeamSpeak avatar images persisted by uid so the web UI can show
|
||||
// them even when the client is offline or out of the bot's view
|
||||
// (the live TS avatar cache only holds in-view clients). `data` is
|
||||
// base64-encoded image bytes, like custom emojis.
|
||||
struct CachedAvatar {
|
||||
std::string uid;
|
||||
std::string mime;
|
||||
std::string dataBase64;
|
||||
// The source myTeamSpeak avatar URL, so an offline user's
|
||||
// avatar can be re-fetched even when the image bytes were
|
||||
// never stored. Empty for legacy/file avatars.
|
||||
std::string url;
|
||||
};
|
||||
// Image (mime + base64 data + url) for one uid, or nullopt if none.
|
||||
[[nodiscard]] Api::Result<std::optional<CachedAvatar>>
|
||||
getCachedAvatar(const std::string& uid);
|
||||
// Insert or replace the cached avatar image for a uid (keeps any
|
||||
// previously stored url).
|
||||
Api::Result<void> putCachedAvatar(const std::string& uid,
|
||||
const std::string& mime,
|
||||
const std::string& dataBase64);
|
||||
// Record just the source url for a uid (upsert), so it survives to
|
||||
// be re-fetched after the user goes offline.
|
||||
Api::Result<void> putCachedAvatarUrl(const std::string& uid,
|
||||
const std::string& url);
|
||||
|
||||
// ===== Subscriptions =====
|
||||
|
||||
// Subscriber info
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Echoion::Api::Events
|
||||
struct PlaylistLoadStarted {
|
||||
std::string playlistId;
|
||||
uint64_t requestedByClientId;
|
||||
uint64_t databasePlaylistId;
|
||||
uint64_t databasePlaylistId = 0;
|
||||
};
|
||||
|
||||
struct PlaylistTrackLoaded {
|
||||
@@ -110,7 +110,7 @@ namespace Echoion::Api::Events
|
||||
TrackInfo track;
|
||||
uint32_t loadedCount;
|
||||
uint32_t totalCount;
|
||||
uint64_t databasePlaylistId;
|
||||
uint64_t databasePlaylistId = 0;
|
||||
};
|
||||
|
||||
struct PlaylistLoadCompleted {
|
||||
@@ -133,16 +133,6 @@ namespace Echoion::Api::Events
|
||||
uint64_t clientId;
|
||||
};
|
||||
|
||||
// Connection events
|
||||
struct ClientConnected {
|
||||
ClientInfo client;
|
||||
};
|
||||
|
||||
struct ClientDisconnected {
|
||||
uint64_t clientId;
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
// Error events
|
||||
struct PlaybackError {
|
||||
ErrorCode code;
|
||||
|
||||
@@ -36,6 +36,45 @@ namespace Echoion::Api
|
||||
getClients() = 0;
|
||||
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
|
||||
getClient(uint64_t clientId) = 0;
|
||||
// Network address of a client as reported by TeamSpeak
|
||||
// (CONNECTION_CLIENT_IP). Requires the bot to hold the
|
||||
// b_client_remoteaddress_view permission; hosts that cannot
|
||||
// resolve the address return nullopt.
|
||||
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||
getClientIp(uint64_t /*clientId*/)
|
||||
{
|
||||
return std::optional<std::string>{};
|
||||
}
|
||||
// Local filesystem path of the client's avatar image as cached
|
||||
// by the TeamSpeak client (getAvatar). The cache is only
|
||||
// populated for clients the TS client has seen; nullopt when the
|
||||
// client has no avatar or it is not (yet) downloaded.
|
||||
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||
getClientAvatarPath(uint64_t /*clientId*/)
|
||||
{
|
||||
return std::optional<std::string>{};
|
||||
}
|
||||
// The client's myTeamSpeak avatar URL, if set. Modern clients store
|
||||
// their avatar as a public HTTPS URL (CLIENT_MYTS_AVATAR, formatted
|
||||
// "<version>,<url>") rather than the legacy file-transfer avatar.
|
||||
// Returns the bare URL, or nullopt when unset/legacy.
|
||||
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||
getClientAvatarUrl(uint64_t /*clientId*/)
|
||||
{
|
||||
return std::optional<std::string>{};
|
||||
}
|
||||
// Actively fetch a client's avatar from the server into `destDir`
|
||||
// (used when it isn't in the TS client's own cache — e.g. the
|
||||
// client is not in view). Returns the local path once the file is
|
||||
// present; returns nullopt when the client has no avatar or the
|
||||
// download was just triggered and hasn't finished yet (a later
|
||||
// call returns the path). Downloads run asynchronously.
|
||||
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||
requestClientAvatar(uint64_t /*clientId*/,
|
||||
const std::string& /*destDir*/)
|
||||
{
|
||||
return std::optional<std::string>{};
|
||||
}
|
||||
virtual Result<void> moveClient(uint64_t clientId,
|
||||
uint64_t channelId) = 0;
|
||||
virtual Result<void> kickClient(uint64_t clientId,
|
||||
|
||||
@@ -38,7 +38,10 @@ namespace Echoion::Api
|
||||
SeekPosition,
|
||||
HotReloadRequested,
|
||||
HotReloadCompleted,
|
||||
ConfigurationChanged
|
||||
ConfigurationChanged,
|
||||
// Appended: fired once the TeamSpeak connection is fully established
|
||||
// (client list available), so the core can resolve online subscribers.
|
||||
ConnectionEstablished
|
||||
};
|
||||
|
||||
// Minimal track info for Plugin (no internal types)
|
||||
@@ -51,15 +54,15 @@ namespace Echoion::Api
|
||||
|
||||
struct PluginEvent {
|
||||
PluginEventType type;
|
||||
std::optional<std::string> clientName;
|
||||
std::optional<TrackSummary>
|
||||
trackSummary; // Opaque summary instead of full TrackInfo
|
||||
std::optional<std::string> clientName = {};
|
||||
std::optional<TrackSummary> trackSummary =
|
||||
{}; // Opaque summary instead of full TrackInfo
|
||||
uint64_t clientId = 0;
|
||||
std::optional<uint64_t> targetChannelId;
|
||||
std::optional<std::string> message;
|
||||
std::optional<float> volume;
|
||||
std::optional<int> queuePosition;
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
std::optional<uint64_t> targetChannelId = {};
|
||||
std::optional<std::string> message = {};
|
||||
std::optional<float> volume = {};
|
||||
std::optional<int> queuePosition = {};
|
||||
std::chrono::system_clock::time_point timestamp = {};
|
||||
};
|
||||
|
||||
// ===== Connection Types =====
|
||||
|
||||
@@ -69,7 +69,34 @@ namespace Echoion::Api
|
||||
// Library (appended)
|
||||
GetPlaylist, // playlist contents by id
|
||||
GetHistory, // recently played tracks
|
||||
GetStats // playback statistics
|
||||
GetStats, // playback statistics
|
||||
|
||||
// Web UI (appended)
|
||||
GetFavorites, // authenticated user's favorites
|
||||
AddFavorite, // add a track to favorites
|
||||
RemoveFavorite, // remove by track url
|
||||
VoteSkip, // vote to skip the current track
|
||||
Announce, // admin: broadcast an announcement
|
||||
GetAggregateStats, // server-wide dashboard statistics
|
||||
|
||||
// Web UI round 2 (appended)
|
||||
AuthenticateByAddress, // sign in by matching the caller's IP against
|
||||
// online subscribers' TeamSpeak addresses
|
||||
RestartWebInterface, // admin: stop+start the web server in place
|
||||
ToggleAutoplay, // admin: flip radio mode (autoplay)
|
||||
|
||||
// Web UI round 3 (appended)
|
||||
GetUserPrefs, // per-user preferences (language, …) from the kv store
|
||||
SetUserPrefs, // update per-user preferences; keys shared with the
|
||||
// chat commands (e.g. !lang) so both stay in sync
|
||||
|
||||
// Web UI round 4 (appended): custom emojis for watch chat/reactions
|
||||
GetCustomEmojis, // list custom emoji names (+ mime)
|
||||
AddCustomEmoji, // admin: add/replace a custom emoji (base64 image)
|
||||
RemoveCustomEmoji, // admin: delete a custom emoji
|
||||
|
||||
// Web UI round 5 (appended): lyrics for the current track (lrclib)
|
||||
GetLyrics // plain + time-synced lyrics for the now-playing track
|
||||
};
|
||||
|
||||
struct RpcRequest {
|
||||
@@ -113,6 +140,7 @@ namespace Echoion::Api
|
||||
std::chrono::milliseconds playbackPosition;
|
||||
BotConfig config;
|
||||
std::map<std::string, std::string> sessionData;
|
||||
bool autoplay = false;
|
||||
|
||||
[[nodiscard]] bool shouldPreservePlayback() const noexcept
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user