1 parent
d146f11f02
commit
5c036d91fb
72 files changed
+5875
-1243
No files matched your search
@@ -67,9 +67,26 @@ namespace Echoion::Core
|
||||
// Check if decode is finished
|
||||
[[nodiscard]] bool isFinished() const { return eof_.load(); }
|
||||
|
||||
// Decoded audio waiting in the queue, in interleaved S16 samples.
|
||||
// The crossfade readiness gate uses this: a fade only starts once
|
||||
// the incoming decoder has buffered enough audio to survive it.
|
||||
[[nodiscard]] std::size_t queuedSamples() const;
|
||||
|
||||
// True when the decode queue is at capacity (the decode thread is
|
||||
// backpressured) — waiting longer cannot buffer any more.
|
||||
[[nodiscard]] bool queueSaturated() const;
|
||||
|
||||
private:
|
||||
|
||||
void decodeThread();
|
||||
// One read→decode→flush pass over the source; returns on EOF or
|
||||
// shutdown. decodeThread() parks between sessions awaiting a
|
||||
// seek request, so a post-EOF seek resumes decoding.
|
||||
void decodeSession();
|
||||
// Perform a pending seek request on the decode thread (the only
|
||||
// thread allowed to touch the FFmpeg contexts while decoding).
|
||||
// Returns true if a request was consumed.
|
||||
bool consumePendingSeek();
|
||||
// Borrow a chunk buffer of `samples` length from the recycle
|
||||
// free-list (reusing pooled storage), or allocate one if the
|
||||
// free-list is empty.
|
||||
@@ -100,6 +117,9 @@ namespace Echoion::Core
|
||||
// S16 audio queue (like reference) - avoids float conversion
|
||||
std::deque<std::vector<int16_t>> int16Queue_;
|
||||
static constexpr size_t MAX_INT16_QUEUE_SIZE = 100;
|
||||
// Max samples per swr_convert() output call; outputBuffer_ is
|
||||
// sized for this.
|
||||
static constexpr int MAX_OUT_SAMPLES = 4096;
|
||||
|
||||
// Free-list of recycled chunk buffers. getNextChunk() swaps the
|
||||
// caller's previous buffer in here and decodeThread() reuses that
|
||||
@@ -116,6 +136,9 @@ namespace Echoion::Core
|
||||
// Decode position in ms; written by the decode thread per frame,
|
||||
// read cross-thread by getPosition() (prefetch decisions).
|
||||
std::atomic<int64_t> currentPositionMs_{0};
|
||||
// Pending seek target in ms, -1 = none. Written by seek() under
|
||||
// mutex_ (coordinated with eof_), consumed by the decode thread.
|
||||
std::atomic<int64_t> seekRequestMs_{-1};
|
||||
std::string currentUrl_;
|
||||
|
||||
std::atomic<uint32_t> streamSampleRate_{48000};
|
||||
|
||||
@@ -6,16 +6,18 @@
|
||||
#include <Types.hpp>
|
||||
#include <Void/Async/ThreadPool.hpp>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core
|
||||
@@ -148,6 +150,47 @@ namespace Echoion::Core
|
||||
class HelpCommand;
|
||||
void registerHelpCommand();
|
||||
|
||||
// Internal page-navigator command (!page/!next/!prev), defined in
|
||||
// the .cpp so it can reach the paged-reply cache below.
|
||||
class PageNavCommand;
|
||||
void registerPageCommands();
|
||||
|
||||
// Resolve the language a client should be answered in: their stored
|
||||
// per-user preference (kv_store "lang:<uid>") if any, else the
|
||||
// configured bot default, else English.
|
||||
[[nodiscard]] I18n::Language resolveLanguage(
|
||||
uint64_t clientId,
|
||||
const std::weak_ptr<MusicManager>& musicManager) const;
|
||||
|
||||
// --- Oversized-reply pagination -------------------------------
|
||||
// Long replies (from any command except help / the navigator) are
|
||||
// kept to a single message: page 1 is sent with a footer and the
|
||||
// remaining pages are cached here for !page/!next/!prev.
|
||||
struct PagedReply {
|
||||
std::vector<std::string> pages;
|
||||
std::size_t current = 0;
|
||||
std::chrono::steady_clock::time_point ts{};
|
||||
};
|
||||
mutable std::mutex pagedMutex_;
|
||||
std::unordered_map<uint64_t, PagedReply> pagedReplies_;
|
||||
static constexpr std::size_t kPageLimitBytes = 700;
|
||||
static constexpr std::chrono::minutes kPageTtl{10};
|
||||
|
||||
// Split `text` into pages, cache pages 2..N for `clientId`, and
|
||||
// return page 1 (with a footer when there is more than one page).
|
||||
// Replies that already fit one message pass through unchanged.
|
||||
std::string paginateReply(uint64_t clientId, std::string text,
|
||||
I18n::Language lang);
|
||||
|
||||
// Re-render a cached page for `clientId`. When `absolute` is set
|
||||
// the current page jumps to it (1-based, clamped); otherwise it
|
||||
// moves by `delta`. Returns std::nullopt when nothing is cached /
|
||||
// expired.
|
||||
std::optional<std::string>
|
||||
renderCachedPage(uint64_t clientId,
|
||||
std::optional<long> absolute, int delta,
|
||||
I18n::Language lang);
|
||||
|
||||
std::string prefix_ = "!";
|
||||
|
||||
// Non-owning service registry threaded into each CommandContext
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
#include "CommandManager.hpp"
|
||||
#include "ConfigLoader.hpp"
|
||||
#include "LyricsService.hpp"
|
||||
#include "MusicManager.hpp"
|
||||
#include "NetworkClient.hpp"
|
||||
#include "RpcServer.hpp"
|
||||
#ifdef ECHOION_WITH_WEB
|
||||
#include "echoion/web/HttpServer.hpp"
|
||||
#endif
|
||||
#include <ConfigManager.hpp>
|
||||
#include <ConfigTypes.hpp>
|
||||
#include <CoreInterface.hpp>
|
||||
@@ -16,9 +20,13 @@
|
||||
#include <Types.hpp>
|
||||
#include <Void/Service/Registry.hpp>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
namespace Void::Logging
|
||||
{
|
||||
@@ -154,10 +162,24 @@ namespace Echoion::Core
|
||||
void onMusicEvent(const Api::PluginEvent& event);
|
||||
void broadcastEvent(const Api::PluginEvent& event);
|
||||
[[nodiscard]] bool isAdmin(uint64_t clientId) const;
|
||||
[[nodiscard]] bool isDj(uint64_t clientId) const;
|
||||
void updateWhisperList();
|
||||
void setupRpcHandlers();
|
||||
void setupEventBusSubscriptions() noexcept;
|
||||
|
||||
// Fetch an online client's avatar bytes (TS local cache, then the
|
||||
// myTeamSpeak URL, then a legacy file-transfer download) and persist
|
||||
// them — and the myTS URL — to the database keyed by uid. Returns
|
||||
// {contentType, bytes} on success. Web-agnostic; used by both the
|
||||
// avatar HTTP provider and the background warmer.
|
||||
[[nodiscard]] std::optional<std::pair<std::string, std::string>>
|
||||
fetchClientAvatarBytes(const std::string& uid,
|
||||
uint64_t clientId);
|
||||
// Periodically cache avatars for every online client so they remain
|
||||
// available (from the DB) once the user goes offline. Runs on
|
||||
// avatarWarmer_.
|
||||
void warmAvatarCache();
|
||||
|
||||
// Build the console + split-file logging stack and install it as
|
||||
// the global Void::Log sink (logSink_ must outlive logging).
|
||||
void installLogging();
|
||||
@@ -167,6 +189,7 @@ namespace Echoion::Core
|
||||
|
||||
// Components
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::shared_ptr<LyricsService> lyricsService_;
|
||||
std::shared_ptr<MusicManager> musicManager_;
|
||||
std::unique_ptr<CommandManager> commandManager_;
|
||||
Api::PluginInterfacePtr pluginInterface_;
|
||||
@@ -176,21 +199,67 @@ namespace Echoion::Core
|
||||
std::filesystem::path configPath_;
|
||||
std::chrono::system_clock::time_point startTime_;
|
||||
std::atomic<bool> initialized_{false};
|
||||
// Guards triggerAutoConnect() against duplicate connection
|
||||
// attempts (reset on a failed initiation so a retry can run).
|
||||
std::atomic<bool> autoConnectInitiated_{false};
|
||||
|
||||
// Event callbacks
|
||||
std::vector<Api::EventCallback> eventCallbacks_;
|
||||
mutable std::mutex eventMutex_;
|
||||
|
||||
// Admin tracking
|
||||
// Admin / DJ tracking (RPC clients whose TeamSpeak identity is in
|
||||
// a configured teamspeak.adminGroups / djGroups server group).
|
||||
std::vector<uint64_t> adminClients_;
|
||||
std::vector<uint64_t> djClients_;
|
||||
mutable std::mutex adminMutex_;
|
||||
|
||||
// Authenticated RPC client -> stable TS uid + nickname, resolved
|
||||
// at token auth. Keys per-user features (favorites, vote-skip).
|
||||
struct RpcIdentity {
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
};
|
||||
std::map<uint64_t, RpcIdentity> rpcIdentities_;
|
||||
mutable std::mutex rpcIdentityMutex_;
|
||||
[[nodiscard]] std::optional<RpcIdentity>
|
||||
rpcIdentity(uint64_t clientId) const;
|
||||
|
||||
// Full identity behind an RPC token: uid, display nickname and
|
||||
// admin standing. Shared by token auth, IP autologin and the
|
||||
// watch-together identity resolver.
|
||||
struct TokenIdentity {
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
bool isAdmin = false;
|
||||
bool isDj = false;
|
||||
};
|
||||
[[nodiscard]] std::optional<TokenIdentity>
|
||||
identityForToken(const std::string& token);
|
||||
// Mark an RPC connection authenticated as `identity` (auth set,
|
||||
// admin list, per-client identity map).
|
||||
void registerRpcAuth(uint64_t clientId,
|
||||
const TokenIdentity& identity);
|
||||
// Guards RestartWebInterface against overlapping restarts.
|
||||
std::atomic<bool> webRestartPending_{false};
|
||||
|
||||
// Database for persistence
|
||||
std::shared_ptr<Api::Database> database_;
|
||||
|
||||
// Background avatar cache warmer + the uids already cached this
|
||||
// session (so we don't re-download an unchanged avatar every cycle).
|
||||
std::jthread avatarWarmer_;
|
||||
std::unordered_set<std::string> warmedUids_;
|
||||
|
||||
// RPC server for Desktop/API clients
|
||||
std::shared_ptr<RpcServer> rpcServer_;
|
||||
|
||||
#ifdef ECHOION_WITH_WEB
|
||||
// Browser web interface: serves the static UI and hosts the
|
||||
// independent sync-watch WebSocket. Bot control from the browser
|
||||
// goes straight to the RPC server, so this holds no bot handles.
|
||||
std::shared_ptr<Web::HttpServer> webServer_;
|
||||
#endif
|
||||
|
||||
// Composition root: a type-keyed registry of all Core services
|
||||
// (logger, config, event bus, network, database, music, rpc).
|
||||
// initialize() provides each instance; resolveServices() and other
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include "echoion/core/NetworkClient.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// Fetches song lyrics from lrclib.net (free, no auth) for the currently
|
||||
// playing track. Returns both plain lyrics and, when available, LRC
|
||||
// time-synced lines so the web UI can highlight the active line against the
|
||||
// playback clock. Results are cached in-process for a while since lyrics
|
||||
// never change and the same track is asked about repeatedly (chat command,
|
||||
// web panel, reconnects).
|
||||
//
|
||||
// Reachable by chat commands via the service registry and directly by the
|
||||
// RPC handlers. All network calls are synchronous; callers already run off
|
||||
// the audio thread (command thread pool / RPC worker).
|
||||
class LyricsService
|
||||
{
|
||||
public:
|
||||
|
||||
struct Line {
|
||||
std::int64_t ms = 0; // offset from track start
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct Lyrics {
|
||||
bool found = false;
|
||||
std::string plain; // full plain-text lyrics
|
||||
std::vector<Line> synced; // empty when only plain exists
|
||||
std::string source; // "lrclib" when resolved
|
||||
std::string title; // as reported by the provider
|
||||
std::string artist;
|
||||
};
|
||||
|
||||
explicit LyricsService(std::shared_ptr<NetworkClient> net);
|
||||
|
||||
// Resolve lyrics for a track. `durationSec` == 0 means unknown and
|
||||
// skips the exact-duration lookup (search fallback still runs).
|
||||
[[nodiscard]] Lyrics fetch(const std::string& title,
|
||||
const std::string& artist,
|
||||
const std::string& album,
|
||||
long long durationSec);
|
||||
|
||||
private:
|
||||
|
||||
[[nodiscard]] Lyrics
|
||||
fetchUncached(const std::string& title,
|
||||
const std::string& artist,
|
||||
const std::string& album,
|
||||
long long durationSec) const;
|
||||
|
||||
// Parse an LRC-format string ("[mm:ss.xx] text") into sorted,
|
||||
// timestamped lines, ignoring metadata tags ([ar:], [ti:], …).
|
||||
[[nodiscard]] static std::vector<Line>
|
||||
parseLrc(const std::string& lrc);
|
||||
|
||||
std::shared_ptr<NetworkClient> net_;
|
||||
|
||||
struct Entry {
|
||||
Lyrics value;
|
||||
std::chrono::steady_clock::time_point at;
|
||||
};
|
||||
mutable std::mutex mutex_;
|
||||
std::unordered_map<std::string, Entry> cache_;
|
||||
static constexpr std::chrono::hours kCacheTtl{6};
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "NetworkClient.hpp"
|
||||
#include "PlaylistLoader.hpp"
|
||||
#include "RpcTypes.hpp"
|
||||
#include "Socks5HttpBridge.hpp"
|
||||
#include "SubscriptionManager.hpp"
|
||||
#include "SubscriptionService.hpp"
|
||||
#include "TrackCache.hpp"
|
||||
@@ -100,6 +101,21 @@ namespace Echoion::Core
|
||||
seek(std::chrono::milliseconds position);
|
||||
[[nodiscard]] Api::Result<void> setVolume(float volume);
|
||||
|
||||
// Vote-to-skip the current track. Votes are keyed by the voter's
|
||||
// stable uid and reset whenever the current track changes. The
|
||||
// threshold is features.voteSkipThreshold, or a majority of
|
||||
// online subscribers when 0. Reaching it skips the track.
|
||||
struct VoteSkipStatus {
|
||||
uint32_t votes = 0;
|
||||
uint32_t needed = 0;
|
||||
bool voted = false; // caller has an active vote
|
||||
bool skipped = false;
|
||||
};
|
||||
[[nodiscard]] Api::Result<VoteSkipStatus>
|
||||
voteSkip(const std::string& uid);
|
||||
[[nodiscard]] VoteSkipStatus
|
||||
voteSkipStatus(const std::string& uid) const;
|
||||
|
||||
[[nodiscard]] Api::Result<uint64_t>
|
||||
queueTrack(const Api::TrackInfo& track, uint64_t clientId);
|
||||
[[nodiscard]] Api::Result<void> removeFromQueue(uint32_t position);
|
||||
@@ -134,7 +150,7 @@ namespace Echoion::Core
|
||||
[[nodiscard]] std::chrono::milliseconds getPlaybackPosition() const;
|
||||
|
||||
// Which catalog(s) a text search targets.
|
||||
enum class SearchScope { All, YouTube, Yandex };
|
||||
enum class SearchScope { All, YouTube, Yandex, SoundCloud };
|
||||
|
||||
[[nodiscard]] Api::Result<Api::SearchResult>
|
||||
search(const std::string& query,
|
||||
@@ -158,6 +174,17 @@ namespace Echoion::Core
|
||||
return autoplay_.load();
|
||||
}
|
||||
|
||||
// Start playback (or seed radio) if nothing is playing and an
|
||||
// online subscriber is listening. Idempotent — safe to call after a
|
||||
// restore/hot-reload or when a subscriber connects, so radio resumes
|
||||
// without a manual !play / !radio toggle.
|
||||
void maybeAutoStart();
|
||||
|
||||
// Set shuffle/repeat mode directly (used when restoring persisted
|
||||
// state); persists the session snapshot.
|
||||
void setShuffle(bool enabled);
|
||||
void setRepeat(bool enabled);
|
||||
|
||||
// Help command
|
||||
[[nodiscard]] std::string getHelpText() const;
|
||||
|
||||
@@ -278,6 +305,17 @@ namespace Echoion::Core
|
||||
std::chrono::milliseconds duration) override;
|
||||
void onEngineIdle() override;
|
||||
void onLocalFileDone(const std::string& path) override;
|
||||
|
||||
// Persist the live queue + shuffle/repeat/autoplay to the database
|
||||
// (kv "session.state") so a full restart can restore them; restore
|
||||
// them at startup. persistSession() is a no-op while a restore is in
|
||||
// progress to avoid recursive writes. includeCurrent=false drops
|
||||
// the currently-playing track from the snapshot — used by stop(),
|
||||
// where the engine clears its entry asynchronously and would
|
||||
// otherwise be persisted as still queued.
|
||||
void persistSession(bool includeCurrent = true);
|
||||
void restoreSession();
|
||||
std::atomic<bool> restoringSession_{false};
|
||||
void onPlaybackError(const Api::Error& error,
|
||||
const std::optional<Api::QueueEntry>& entry)
|
||||
override;
|
||||
@@ -309,9 +347,13 @@ namespace Echoion::Core
|
||||
downloadAudioForPlayback(const Api::TrackInfo& track);
|
||||
void cleanupTempFile(const std::string& filepath);
|
||||
|
||||
// True when a SOCKS5 proxy is configured: ffmpeg cannot route
|
||||
// IP-locked googlevideo URLs through it, so those are downloaded.
|
||||
[[nodiscard]] bool socksProxyActive() const;
|
||||
// The proxy the playback engine (ffmpeg) should use. ffmpeg only
|
||||
// speaks HTTP CONNECT, so a SOCKS5 config starts the local
|
||||
// Socks5HttpBridge and is rewritten to an Http proxy pointing at
|
||||
// it; Http/none pass through unchanged (and stop the bridge).
|
||||
[[nodiscard]] std::optional<Void::Net::ProxyConfig>
|
||||
effectiveEngineProxy(
|
||||
const std::optional<Void::Net::ProxyConfig>& proxy);
|
||||
|
||||
// ---- state -----------------------------------------------------
|
||||
|
||||
@@ -342,6 +384,14 @@ namespace Echoion::Core
|
||||
QueueService queue_;
|
||||
std::unique_ptr<TrackCache> trackCache_;
|
||||
|
||||
// Vote-to-skip state: voter uids for the queue entry identified
|
||||
// by voteSkipQueueId_ (cleared lazily when the track changes).
|
||||
mutable std::mutex voteSkipMutex_;
|
||||
std::set<std::string> voteSkipUids_;
|
||||
uint64_t voteSkipQueueId_ = 0;
|
||||
std::atomic<uint32_t> voteSkipThreshold_{0}; // 0 = auto majority
|
||||
[[nodiscard]] uint32_t voteSkipNeeded() const;
|
||||
|
||||
// Autoplay state: seed track for recommendations + re-entrancy
|
||||
// guard for the async fetch. The seed's catalog decides where
|
||||
// related tracks are pulled from (YouTube radio mix vs. Yandex
|
||||
@@ -364,6 +414,10 @@ namespace Echoion::Core
|
||||
std::atomic<bool> importRunning_{false};
|
||||
std::jthread importThread_;
|
||||
std::unique_ptr<PlaybackEngine> engine_;
|
||||
// HTTP CONNECT -> SOCKS5 tunnel for ffmpeg (see
|
||||
// effectiveEngineProxy); only running while the configured proxy
|
||||
// is SOCKS5.
|
||||
std::unique_ptr<Socks5HttpBridge> ffmpegProxyBridge_;
|
||||
std::unique_ptr<SubscriptionService> subscriptions_;
|
||||
|
||||
// Pending search results per client (for select command)
|
||||
|
||||
@@ -73,10 +73,18 @@ namespace Echoion::Core::Dto
|
||||
};
|
||||
|
||||
struct ManageUsersRequest {
|
||||
std::string action; // "list" | "remove"
|
||||
std::string action; // "list" | "remove" | "clearAll"
|
||||
std::optional<std::string> uid;
|
||||
};
|
||||
|
||||
struct UrlRequest {
|
||||
std::string url;
|
||||
};
|
||||
|
||||
struct AnnounceRequest {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
// ── RPC handler responses ───────────────────────────────────────────────
|
||||
|
||||
struct Track {
|
||||
@@ -88,6 +96,9 @@ namespace Echoion::Core::Dto
|
||||
int source = 0;
|
||||
std::optional<std::string> thumbnailUrl;
|
||||
std::optional<std::string> url; // originalUrl (play-by-url)
|
||||
// Shortened faumaray.ru link when available; the web UI prefers
|
||||
// it for "open original link" (falls back to url).
|
||||
std::optional<std::string> shortenedUrl;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline Track toTrack(const Api::TrackInfo& t)
|
||||
@@ -104,7 +115,28 @@ namespace Echoion::Core::Dto
|
||||
.thumbnailUrl = t.thumbnailUrl,
|
||||
.url = t.originalUrl.empty()
|
||||
? std::nullopt
|
||||
: std::optional(t.originalUrl)};
|
||||
: std::optional(t.originalUrl),
|
||||
.shortenedUrl =
|
||||
t.shortenedUrl && !t.shortenedUrl->empty()
|
||||
? t.shortenedUrl
|
||||
: std::nullopt};
|
||||
}
|
||||
|
||||
// Inverse of toTrack (client-supplied tracks, e.g. AddFavorite).
|
||||
[[nodiscard]] inline Api::TrackInfo fromTrack(const Track& t)
|
||||
{
|
||||
Api::TrackInfo info;
|
||||
info.id = t.id;
|
||||
info.title = t.title;
|
||||
info.artist = t.artist;
|
||||
info.album = t.album;
|
||||
if (t.duration) {
|
||||
info.duration = std::chrono::milliseconds(*t.duration);
|
||||
}
|
||||
info.source = static_cast<Api::TrackSource>(t.source);
|
||||
info.thumbnailUrl = t.thumbnailUrl;
|
||||
info.originalUrl = t.url.value_or("");
|
||||
return info;
|
||||
}
|
||||
|
||||
struct QueueItem {
|
||||
@@ -127,6 +159,12 @@ namespace Echoion::Core::Dto
|
||||
float volume = 0.0f;
|
||||
bool repeat = false;
|
||||
bool shuffle = false;
|
||||
// Radio mode: auto-enqueue related tracks when the queue runs dry.
|
||||
bool autoplay = false;
|
||||
// Vote-skip state for the current track (additive fields).
|
||||
std::uint32_t skipVotes = 0;
|
||||
std::uint32_t skipVotesNeeded = 0;
|
||||
bool skipVoted = false;
|
||||
};
|
||||
|
||||
struct Success {
|
||||
@@ -143,6 +181,37 @@ namespace Echoion::Core::Dto
|
||||
float volume = 0.0f;
|
||||
};
|
||||
|
||||
struct Autoplay {
|
||||
bool autoplay = false;
|
||||
};
|
||||
|
||||
// Per-user preferences stored in the kv store; `language` shares the
|
||||
// "lang:<uid>" key with the !lang chat command so the web switcher and
|
||||
// the bot stay in sync.
|
||||
struct UserPrefs {
|
||||
std::string language;
|
||||
};
|
||||
|
||||
// Custom emoji metadata (name + mime); the image itself is served at
|
||||
// GET /emoji/<name>, not inlined here.
|
||||
struct CustomEmojiDto {
|
||||
std::string name;
|
||||
std::string mime;
|
||||
std::string addedBy;
|
||||
};
|
||||
struct CustomEmojiList {
|
||||
std::vector<CustomEmojiDto> emojis;
|
||||
};
|
||||
// AddCustomEmoji request: name + mime + base64-encoded image bytes.
|
||||
struct AddEmojiRequest {
|
||||
std::string name;
|
||||
std::string mime;
|
||||
std::string dataBase64;
|
||||
};
|
||||
struct EmojiNameRequest {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct QueuedResponse {
|
||||
bool success = true;
|
||||
std::uint64_t queueId = 0;
|
||||
@@ -192,6 +261,13 @@ namespace Echoion::Core::Dto
|
||||
std::uint32_t connectedClients = 0;
|
||||
std::uint32_t subscribers = 0;
|
||||
std::uint32_t queueLength = 0;
|
||||
std::uint32_t onlineSubscribers = 0;
|
||||
// Nicknames behind onlineSubscribers, so non-admin clients can
|
||||
// render a "listening now" list without the admin user API.
|
||||
std::vector<std::string> onlineSubscriberNames;
|
||||
// TeamSpeak uids parallel to onlineSubscriberNames (same order), so
|
||||
// the web UI can fetch each listener's avatar at /avatar/<uid>.
|
||||
std::vector<std::string> onlineSubscriberUids;
|
||||
};
|
||||
|
||||
struct AuditEntryDto {
|
||||
@@ -207,12 +283,77 @@ namespace Echoion::Core::Dto
|
||||
struct SubscriberDto {
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
bool online = false;
|
||||
};
|
||||
|
||||
struct UsersResponse {
|
||||
std::vector<SubscriberDto> users;
|
||||
};
|
||||
|
||||
// Authenticate success. isAdmin/isDj/uid/nickname are additive — older
|
||||
// clients that only read `message` keep working.
|
||||
struct AuthSuccess {
|
||||
bool success = true;
|
||||
std::string message;
|
||||
bool isAdmin = false;
|
||||
bool isDj = false;
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
// Set by address-based autologin so the client can persist the
|
||||
// session token it never typed; empty for normal token auth.
|
||||
std::string token;
|
||||
};
|
||||
|
||||
struct AddFavoriteRequest {
|
||||
Track track;
|
||||
};
|
||||
|
||||
struct FavoritesResponse {
|
||||
std::vector<Track> tracks;
|
||||
};
|
||||
|
||||
// GetLyrics response: plain text plus, when available, time-synced lines
|
||||
// (ms offset from track start) so the web UI can highlight the active line.
|
||||
struct LyricsLineDto {
|
||||
std::int64_t ms = 0;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct LyricsResponse {
|
||||
bool found = false;
|
||||
std::string plain;
|
||||
std::vector<LyricsLineDto> synced;
|
||||
std::string source; // "lrclib" when resolved
|
||||
std::string title;
|
||||
std::string artist;
|
||||
};
|
||||
|
||||
struct VoteSkipResponse {
|
||||
std::uint32_t votes = 0;
|
||||
std::uint32_t needed = 0;
|
||||
bool voted = false;
|
||||
bool skipped = false;
|
||||
};
|
||||
|
||||
struct RequesterDto {
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
std::uint64_t count = 0;
|
||||
};
|
||||
|
||||
struct AggregateStatsResponse {
|
||||
std::uint64_t tracksToday = 0;
|
||||
std::uint64_t listeningMsToday = 0;
|
||||
std::uint64_t queueAdditionsToday = 0;
|
||||
std::uint64_t skipsToday = 0;
|
||||
std::uint64_t playsTotal = 0;
|
||||
std::uint64_t skipsTotal = 0;
|
||||
std::vector<RequesterDto> topRequesters;
|
||||
std::uint64_t youtubeCount = 0;
|
||||
std::uint64_t yandexCount = 0;
|
||||
std::uint64_t otherCount = 0;
|
||||
};
|
||||
|
||||
// ── Event-broadcast payloads ────────────────────────────────────────────
|
||||
|
||||
struct TrackBrief {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
@@ -53,6 +54,13 @@ namespace Echoion::Core
|
||||
void removeAuthenticatedClient(uint64_t clientId);
|
||||
[[nodiscard]] bool isClientAuthenticated(uint64_t clientId);
|
||||
|
||||
// The client's effective network address: the X-Echoion-Client-Ip
|
||||
// header set by the web server's /rpc bridge (trusted only from
|
||||
// loopback peers), else the socket's remote address. Used for
|
||||
// address-based autologin.
|
||||
[[nodiscard]] std::optional<std::string>
|
||||
getClientAddress(uint64_t clientId) const;
|
||||
|
||||
// Server introspection (for GetServerInfo / GetAuditLog).
|
||||
struct AuditEntry {
|
||||
uint64_t clientId = 0;
|
||||
@@ -74,6 +82,8 @@ namespace Echoion::Core
|
||||
private:
|
||||
|
||||
void acceptLoop();
|
||||
void doAccept();
|
||||
void onAccept(asio::ip::tcp::socket socket);
|
||||
void handleClient(
|
||||
std::shared_ptr<websocket::stream<asio::ip::tcp::socket>> ws);
|
||||
void processMessage(uint64_t clientId, const std::string& message);
|
||||
@@ -93,6 +103,8 @@ namespace Echoion::Core
|
||||
uint64_t,
|
||||
std::shared_ptr<websocket::stream<asio::ip::tcp::socket>>>
|
||||
clients_;
|
||||
// clientId -> effective network address (see getClientAddress).
|
||||
std::unordered_map<uint64_t, std::string> clientAddresses_;
|
||||
mutable std::mutex clientsMutex_;
|
||||
std::atomic<uint64_t> nextClientId_{1};
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <Types.hpp>
|
||||
#include <Void/Net/Http.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// Local HTTP CONNECT proxy that tunnels through a SOCKS5 upstream.
|
||||
//
|
||||
// FFmpeg has no SOCKS5 support at all — its http protocol only knows the
|
||||
// `http_proxy` option, which speaks HTTP CONNECT. To stream IP-locked
|
||||
// googlevideo URLs directly through a SOCKS5 proxy, the decoder is pointed
|
||||
// at 127.0.0.1:<port()> and every CONNECT is forwarded through the
|
||||
// configured SOCKS5 proxy (greeting/auth/CONNECT handshake, then a raw
|
||||
// byte pump in both directions).
|
||||
//
|
||||
// Only the two decoder slots stream concurrently, so a blocking
|
||||
// thread-per-connection design is deliberate: no io_context pump, no
|
||||
// async state machines.
|
||||
class Socks5HttpBridge
|
||||
{
|
||||
public:
|
||||
|
||||
Socks5HttpBridge() = default;
|
||||
~Socks5HttpBridge();
|
||||
|
||||
Socks5HttpBridge(const Socks5HttpBridge&) = delete;
|
||||
Socks5HttpBridge& operator=(const Socks5HttpBridge&) = delete;
|
||||
|
||||
// Bind 127.0.0.1:<ephemeral>, start the accept thread and return
|
||||
// the bound port. Restarts (against the new upstream) when already
|
||||
// running.
|
||||
Api::Result<uint16_t> start(const Void::Net::ProxyConfig& socks5);
|
||||
|
||||
// Close the acceptor and every live tunnel; joins all threads.
|
||||
void stop();
|
||||
|
||||
[[nodiscard]] bool running() const { return running_.load(); }
|
||||
[[nodiscard]] uint16_t port() const { return port_; }
|
||||
|
||||
// The SOCKS5 endpoint the bridge currently forwards to (empty when
|
||||
// stopped). Lets callers skip a restart when the config is
|
||||
// unchanged.
|
||||
[[nodiscard]] std::optional<Void::Net::ProxyConfig> upstream() const;
|
||||
|
||||
private:
|
||||
|
||||
struct Connection {
|
||||
boost::asio::ip::tcp::socket client;
|
||||
boost::asio::ip::tcp::socket upstream;
|
||||
std::atomic<bool> done{false};
|
||||
std::thread worker;
|
||||
|
||||
explicit Connection(boost::asio::io_context& io)
|
||||
: client(io), upstream(io)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
void acceptLoop();
|
||||
void serve(Connection& conn);
|
||||
// SOCKS5 greeting/auth/CONNECT for host:port on conn.upstream.
|
||||
// Throws std::runtime_error on any protocol failure.
|
||||
void socks5Connect(boost::asio::ip::tcp::socket& upstream,
|
||||
const std::string& host, uint16_t targetPort,
|
||||
const Void::Net::ProxyConfig& proxy);
|
||||
// Drop connections whose worker already finished (joins them).
|
||||
void pruneFinished();
|
||||
|
||||
boost::asio::io_context io_;
|
||||
std::optional<boost::asio::ip::tcp::acceptor> acceptor_;
|
||||
std::thread acceptThread_;
|
||||
uint16_t port_ = 0;
|
||||
std::atomic<bool> running_{false};
|
||||
|
||||
mutable std::mutex mutex_; // guards upstream_ and connections_
|
||||
std::optional<Void::Net::ProxyConfig> upstream_;
|
||||
std::vector<std::unique_ptr<Connection>> connections_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -81,10 +81,16 @@ namespace Echoion::Core
|
||||
[[nodiscard]] std::vector<SubscriptionManager::Subscriber>
|
||||
getSubscribers() const;
|
||||
|
||||
// Presence events from the plugin. onClientConnected returns true
|
||||
// when a subscribed user came online and playback should
|
||||
// Presence events from the plugin. onClientConnected resolves the
|
||||
// client once and hands the uid back so callers don't repeat the
|
||||
// (plugin round-trip) lookup: subscribedUid is set when the
|
||||
// client is a subscriber; mayAutoStart when playback should
|
||||
// auto-start if tracks are queued.
|
||||
bool onClientConnected(uint64_t clientId);
|
||||
struct ClientConnectResult {
|
||||
std::optional<std::string> subscribedUid;
|
||||
bool mayAutoStart = false;
|
||||
};
|
||||
ClientConnectResult onClientConnected(uint64_t clientId);
|
||||
void onClientDisconnected(uint64_t clientId);
|
||||
|
||||
private:
|
||||
|
||||
@@ -49,12 +49,25 @@ namespace Echoion::Core
|
||||
search(std::string_view query,
|
||||
std::optional<std::string> pageToken = std::nullopt);
|
||||
|
||||
// Search SoundCloud via yt-dlp (scsearch). Returns SoundCloud
|
||||
// tracks whose originalUrl is the permalink, streamable through the
|
||||
// ytdlp-direct source.
|
||||
[[nodiscard]] Api::Result<Api::SearchResult>
|
||||
searchSoundCloud(std::string_view query);
|
||||
|
||||
// Related tracks for radio autoplay: lists the YouTube "mix"
|
||||
// playlist (RD<videoId>) via yt-dlp --flat-playlist. Runs through
|
||||
// the proxy like every yt-dlp call, so it works under SOCKS5.
|
||||
[[nodiscard]] Api::Result<std::vector<Api::TrackInfo>>
|
||||
radioMix(const std::string& videoId, size_t limit = 10);
|
||||
|
||||
// Fetch music-video candidates for a random search query. Used as a
|
||||
// radio fallback when no unplayed related track can be found (or
|
||||
// there is no seed). Goes through yt-dlp/proxy like radioMix; the
|
||||
// returned list is shuffled so the caller can pick/filter freely.
|
||||
[[nodiscard]] Api::Result<std::vector<Api::TrackInfo>>
|
||||
randomMusicVideo(size_t limit = 10);
|
||||
|
||||
// Get video details including stream URLs using yt-dlp
|
||||
[[nodiscard]] Api::Result<Api::TrackInfo>
|
||||
getVideoInfo(std::string_view videoId);
|
||||
@@ -156,6 +169,13 @@ namespace Echoion::Core
|
||||
[[nodiscard]] Api::Result<Api::SearchResult>
|
||||
searchWithYtDlp(std::string_view query,
|
||||
const std::optional<std::string>& pageToken);
|
||||
// Shared yt-dlp search backend. `searchPrefix` is the yt-dlp search
|
||||
// selector (e.g. "ytsearch5", "scsearch5"); `source` tags the
|
||||
// resulting tracks and decides how originalUrl is built.
|
||||
[[nodiscard]] Api::Result<Api::SearchResult>
|
||||
searchWithYtDlpProvider(std::string_view query,
|
||||
std::string_view searchPrefix,
|
||||
Api::TrackSource source);
|
||||
|
||||
// Fetch video durations for search results (batch API call)
|
||||
void fetchVideoDurations(std::vector<Api::TrackInfo>& tracks,
|
||||
|
||||
@@ -50,8 +50,9 @@ namespace Echoion::Core
|
||||
// Get yt-dlp version
|
||||
[[nodiscard]] std::string getVersion() const;
|
||||
|
||||
// Force update yt-dlp to latest version
|
||||
Api::Result<void> update();
|
||||
// Force update yt-dlp to latest version; returns the verified
|
||||
// version string of the freshly installed binary.
|
||||
Api::Result<std::string> update();
|
||||
|
||||
// Execute yt-dlp with given arguments and return output
|
||||
// (synchronous)
|
||||
@@ -62,10 +63,6 @@ namespace Echoion::Core
|
||||
[[nodiscard]] std::future<YtDlpResult>
|
||||
executeAsync(const std::vector<std::string>& args);
|
||||
|
||||
// Execute multiple yt-dlp commands concurrently
|
||||
[[nodiscard]] std::vector<YtDlpResult> executeBatch(
|
||||
const std::vector<std::vector<std::string>>& argsList);
|
||||
|
||||
// Set cookie options for YouTube authentication
|
||||
void setCookiesPath(const std::string& path);
|
||||
void setCookiesFromBrowser(const std::string& browser);
|
||||
@@ -93,8 +90,8 @@ namespace Echoion::Core
|
||||
// Download yt-dlp from official source
|
||||
Api::Result<void> downloadYtDlp();
|
||||
|
||||
// Make executable executable (Unix only)
|
||||
Api::Result<void> makeExecutable();
|
||||
// Make the given file executable (Unix only)
|
||||
Api::Result<void> makeExecutable(const std::filesystem::path& path);
|
||||
|
||||
// Check if update is needed (older than 7 days)
|
||||
[[nodiscard]] bool shouldUpdate() const;
|
||||
@@ -135,8 +132,6 @@ namespace Echoion::Core
|
||||
std::unique_ptr<Void::Concurrency::ThreadPool> pool_;
|
||||
|
||||
// yt-dlp download URLs
|
||||
static constexpr std::string_view YTDLP_VERSION_URL =
|
||||
"https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest";
|
||||
static constexpr std::string_view YTDLP_DOWNLOAD_LINUX =
|
||||
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/"
|
||||
"yt-dlp";
|
||||
|
||||
@@ -20,17 +20,18 @@ namespace Echoion::Core
|
||||
{
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable.");
|
||||
ctx.reply(
|
||||
ctx.tr("The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(std::format(
|
||||
"Usage: {}announce <message>", ctx.prefix));
|
||||
ctx.reply(
|
||||
ctx.trf("Usage: {}announce <message>", ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t reached = manager->setAnnouncement(ctx.args);
|
||||
ctx.reply(std::format(
|
||||
ctx.reply(ctx.trf(
|
||||
"Announcement saved and delivered to {} online "
|
||||
"subscriber(s). Offline subscribers get it on their "
|
||||
"next connect.",
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ namespace Echoion::Core
|
||||
std::string arg(ctx.args);
|
||||
std::transform(arg.begin(), arg.end(), arg.begin(),
|
||||
[](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
return static_cast<char>(
|
||||
std::tolower(c));
|
||||
});
|
||||
if (arg == "on" || arg == "true" || arg == "1" ||
|
||||
arg == "enable") {
|
||||
@@ -45,17 +46,19 @@ namespace Echoion::Core
|
||||
manager->setAutoplay(enable);
|
||||
|
||||
if (enable) {
|
||||
ctx.reply(
|
||||
ctx.reply(ctx.tr(
|
||||
"\xf0\x9f\x93\xbb Autoplay is ON \xe2\x80\x94 I'll "
|
||||
"keep the music going with related tracks.");
|
||||
"keep the music going with related tracks."));
|
||||
} else {
|
||||
ctx.reply("\xf0\x9f\x93\xbb Autoplay is OFF.");
|
||||
ctx.reply(ctx.tr("\xf0\x9f\x93\xbb Autoplay is OFF."));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("AutoplayCommand", "{}",
|
||||
Void::Log::error(
|
||||
"AutoplayCommand", "{}",
|
||||
std::format("Autoplay command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,26 +16,28 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->clearQueue();
|
||||
if (!result) {
|
||||
Void::Log::error("ClearCommand", "{}",
|
||||
std::format("Clear command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't clear the queue. Please try again.");
|
||||
Void::Log::error("ClearCommand", "{}",
|
||||
std::format("Clear command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't clear the queue. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Queue cleared!");
|
||||
ctx.reply(ctx.tr("Queue cleared!"));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("ClearCommand", "{}",
|
||||
Void::Log::error(
|
||||
"ClearCommand", "{}",
|
||||
std::format("Clear command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
#include "echoion/core/i18n/Localization.hpp"
|
||||
#include <ConfigTypes.hpp>
|
||||
#include <Types.hpp>
|
||||
#include <Void/Service/Registry.hpp>
|
||||
@@ -136,8 +137,12 @@ namespace Echoion::Core
|
||||
// (non-owning; outlives the command). Populated by CommandManager.
|
||||
const Void::Service::ServiceRegistry* services = nullptr;
|
||||
|
||||
// Language the invoking user should be answered in. Resolved by
|
||||
// CommandManager (per-user kv override, else the config default).
|
||||
I18n::Language language = I18n::Language::English;
|
||||
|
||||
// Reply callback - set by CommandManager
|
||||
std::function<void(std::string_view)> replyCallback;
|
||||
std::function<void(std::string_view)> replyCallback = {};
|
||||
|
||||
// Helper to reply to the user
|
||||
void reply(std::string_view message) const
|
||||
@@ -147,6 +152,24 @@ namespace Echoion::Core
|
||||
}
|
||||
}
|
||||
|
||||
// Translate an English source string into the invoker's language.
|
||||
// Missing translations fall back to the English original.
|
||||
[[nodiscard]] std::string_view tr(std::string_view english) const
|
||||
{
|
||||
return I18n::translate(english, language);
|
||||
}
|
||||
|
||||
// Translate a std::format-style English template, then substitute
|
||||
// the arguments. The template is translated at runtime, so callers
|
||||
// use this instead of std::format for user-facing text.
|
||||
template <typename... Args>
|
||||
[[nodiscard]] std::string trf(std::string_view englishFmt,
|
||||
Args&&... args) const
|
||||
{
|
||||
return std::vformat(I18n::translate(englishFmt, language),
|
||||
std::make_format_args(args...));
|
||||
}
|
||||
|
||||
// Resolve a shared service by interface, or nullptr if the
|
||||
// registry is absent / the service was not provided.
|
||||
template <typename I>
|
||||
@@ -156,6 +179,49 @@ namespace Echoion::Core
|
||||
}
|
||||
};
|
||||
|
||||
// Format a duration as m:ss (or h:mm:ss past an hour). Shared by the
|
||||
// track-listing commands (!np, !queue) so their timestamps line up.
|
||||
inline std::string formatDuration(std::chrono::milliseconds duration)
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
|
||||
// A compact one-line playback status readout (volume / shuffle / repeat /
|
||||
// radio) shared by !help, !np and !list so all three show the same
|
||||
// at-a-glance state. Rendered as a Markdown blockquote line. Returns an
|
||||
// empty string when playback state is unavailable. Radio comes from
|
||||
// autoplayEnabled() since PlaybackState carries no autoplay field.
|
||||
inline std::string playbackStatusLine(const CommandContext& ctx)
|
||||
{
|
||||
auto mm = ctx.musicManager.lock();
|
||||
if (!mm) {
|
||||
return {};
|
||||
}
|
||||
auto st = mm->getPlaybackState();
|
||||
if (!st) {
|
||||
return {};
|
||||
}
|
||||
auto onOff = [&](bool b) -> std::string_view {
|
||||
return b ? ctx.tr("On") : ctx.tr("Off");
|
||||
};
|
||||
return ctx.trf(
|
||||
"> \xf0\x9f\x8e\x9a {} {}% \xc2\xb7 "
|
||||
"\xf0\x9f\x94\x80 {} {} \xc2\xb7 "
|
||||
"\xf0\x9f\x94\x81 {} {} \xc2\xb7 "
|
||||
"\xf0\x9f\x93\xbb {} {}",
|
||||
ctx.tr("Volume"), static_cast<int>(st->volume * 100),
|
||||
ctx.tr("Shuffle"), onOff(st->shuffle),
|
||||
ctx.tr("Repeat"), onOff(st->repeat),
|
||||
ctx.tr("Radio"), onOff(mm->autoplayEnabled()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Interface that all commands must implement.
|
||||
*/
|
||||
@@ -200,6 +266,16 @@ namespace Echoion::Core
|
||||
* @brief Returns whether this command requires admin privileges.
|
||||
*/
|
||||
virtual bool requiresAdmin() const { return false; }
|
||||
|
||||
/**
|
||||
* @brief Whether an over-long reply from this command should be
|
||||
* auto-paginated into a single message with a "!page" footer.
|
||||
*
|
||||
* Defaults to true. Commands that manage their own output shape
|
||||
* (help's collapsible sections, the page navigator itself) return
|
||||
* false so their replies are sent verbatim.
|
||||
*/
|
||||
virtual bool autoPaginate() const { return true; }
|
||||
};
|
||||
|
||||
using CommandPtr = std::shared_ptr<Command>;
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include "AutoplayCommand.hpp"
|
||||
#include "ClearCommand.hpp"
|
||||
#include "Command.hpp"
|
||||
#include "FavoriteCommand.hpp"
|
||||
#include "HistoryCommand.hpp"
|
||||
#include "LanguageCommand.hpp"
|
||||
#include "LyricsCommand.hpp"
|
||||
#include "MoveCommand.hpp"
|
||||
#include "NowPlayingCommand.hpp"
|
||||
#include "PauseCommand.hpp"
|
||||
@@ -21,18 +25,18 @@
|
||||
#include "SeekCommand.hpp"
|
||||
#include "SelectCommand.hpp"
|
||||
#include "ShuffleCommand.hpp"
|
||||
#include "FavoriteCommand.hpp"
|
||||
#include "HistoryCommand.hpp"
|
||||
#include "SkipCommand.hpp"
|
||||
#include "SoundCloudPlayCommand.hpp"
|
||||
#include "SoundCloudSearchCommand.hpp"
|
||||
#include "StatsCommand.hpp"
|
||||
#include "StopCommand.hpp"
|
||||
#include "YandexPlayCommand.hpp"
|
||||
#include "YandexSearchCommand.hpp"
|
||||
#include "YoutubePlayCommand.hpp"
|
||||
#include "YoutubeSearchCommand.hpp"
|
||||
#include "SubscribeCommand.hpp"
|
||||
#include "SubscribersCommand.hpp"
|
||||
#include "UnsubscribeAllCommand.hpp"
|
||||
#include "UnsubscribeCommand.hpp"
|
||||
#include "UnsubscribeIdCommand.hpp"
|
||||
#include "VolumeCommand.hpp"
|
||||
#include "YandexPlayCommand.hpp"
|
||||
#include "YandexSearchCommand.hpp"
|
||||
#include "YoutubePlayCommand.hpp"
|
||||
#include "YoutubeSearchCommand.hpp"
|
||||
@@ -22,13 +22,13 @@ namespace Echoion::Core
|
||||
auto manager = ctx.musicManager.lock();
|
||||
auto db = ctx.service<Api::Database>();
|
||||
if (!manager || !db) {
|
||||
ctx.reply("Favorites are unavailable.");
|
||||
ctx.reply(ctx.tr("Favorites are unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto uid = manager->clientUid(ctx.clientId);
|
||||
if (!uid) {
|
||||
ctx.reply("Couldn't identify you on the server.");
|
||||
ctx.reply(ctx.tr("Couldn't identify you on the server."));
|
||||
return;
|
||||
}
|
||||
const uint64_t userKey = fnv1a(*uid);
|
||||
@@ -44,7 +44,7 @@ namespace Echoion::Core
|
||||
} else if (sub == "remove" || sub == "rm") {
|
||||
removeFavorite(ctx, *db, userKey, rest);
|
||||
} else {
|
||||
ctx.reply(std::format(
|
||||
ctx.reply(ctx.trf(
|
||||
"Usage: {}fav add | list | play <n> | remove <n>",
|
||||
ctx.prefix));
|
||||
}
|
||||
@@ -117,11 +117,11 @@ namespace Echoion::Core
|
||||
{
|
||||
auto favorites = db.getFavorites(userKey);
|
||||
if (!favorites) {
|
||||
ctx.reply("Couldn't read your favorites.");
|
||||
ctx.reply(ctx.tr("Couldn't read your favorites."));
|
||||
return;
|
||||
}
|
||||
if (favorites->empty()) {
|
||||
ctx.reply(std::format(
|
||||
ctx.reply(ctx.trf(
|
||||
"You have no favorites yet. Save the current track "
|
||||
"with {}fav add",
|
||||
ctx.prefix));
|
||||
@@ -130,8 +130,8 @@ namespace Echoion::Core
|
||||
std::string msg = "Your favorites:";
|
||||
size_t index = 1;
|
||||
for (const auto& fav : *favorites) {
|
||||
msg += std::format("\n{}. {}", index++,
|
||||
trackLink(fav.track));
|
||||
msg +=
|
||||
std::format("\n{}. {}", index++, trackLink(fav.track));
|
||||
}
|
||||
ctx.reply(msg);
|
||||
}
|
||||
@@ -142,15 +142,14 @@ namespace Echoion::Core
|
||||
{
|
||||
auto current = manager.getCurrentTrack();
|
||||
if (!current || !current->has_value()) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
ctx.reply(ctx.tr("Nothing is playing right now."));
|
||||
return;
|
||||
}
|
||||
const auto& track = (*current)->track;
|
||||
if (db.addFavorite(userKey, track)) {
|
||||
ctx.reply(std::format("Added to favorites: {}",
|
||||
track.title));
|
||||
ctx.reply(ctx.trf("Added to favorites: {}", track.title));
|
||||
} else {
|
||||
ctx.reply("Couldn't save the favorite.");
|
||||
ctx.reply(ctx.tr("Couldn't save the favorite."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,22 +159,22 @@ namespace Echoion::Core
|
||||
{
|
||||
auto index = parseIndex(arg);
|
||||
if (!index) {
|
||||
ctx.reply("Usage: fav play <number> (see fav list)");
|
||||
ctx.reply(
|
||||
ctx.tr("Usage: fav play <number> (see fav list)"));
|
||||
return;
|
||||
}
|
||||
auto favorites = db.getFavorites(userKey);
|
||||
if (!favorites || *index > favorites->size()) {
|
||||
ctx.reply("No favorite with that number.");
|
||||
ctx.reply(ctx.tr("No favorite with that number."));
|
||||
return;
|
||||
}
|
||||
const auto& track = (*favorites)[*index - 1].track;
|
||||
auto result =
|
||||
manager.play(track.originalUrl, ctx.clientId);
|
||||
auto result = manager.play(track.originalUrl, ctx.clientId);
|
||||
if (result) {
|
||||
ctx.reply(*result);
|
||||
} else {
|
||||
ctx.reply(std::format("Couldn't play it: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.trf("Couldn't play it: {}",
|
||||
result.error().message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,20 +184,21 @@ namespace Echoion::Core
|
||||
{
|
||||
auto index = parseIndex(arg);
|
||||
if (!index) {
|
||||
ctx.reply("Usage: fav remove <number> (see fav list)");
|
||||
ctx.reply(
|
||||
ctx.tr("Usage: fav remove <number> (see fav list)"));
|
||||
return;
|
||||
}
|
||||
auto favorites = db.getFavorites(userKey);
|
||||
if (!favorites || *index > favorites->size()) {
|
||||
ctx.reply("No favorite with that number.");
|
||||
ctx.reply(ctx.tr("No favorite with that number."));
|
||||
return;
|
||||
}
|
||||
const auto& fav = (*favorites)[*index - 1];
|
||||
if (db.removeFavorite(userKey, fav.track.originalUrl)) {
|
||||
ctx.reply(std::format("Removed from favorites: {}",
|
||||
fav.track.title));
|
||||
ctx.reply(
|
||||
ctx.trf("Removed from favorites: {}", fav.track.title));
|
||||
} else {
|
||||
ctx.reply("Couldn't remove the favorite.");
|
||||
ctx.reply(ctx.tr("Couldn't remove the favorite."));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Echoion::Core
|
||||
{
|
||||
auto db = ctx.service<Api::Database>();
|
||||
if (!db) {
|
||||
ctx.reply("History is unavailable (no database).");
|
||||
ctx.reply(ctx.tr("History is unavailable (no database)."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ namespace Echoion::Core
|
||||
|
||||
auto recent = db->getRecentlyPlayed(0, limit);
|
||||
if (!recent) {
|
||||
ctx.reply("Couldn't read the playback history.");
|
||||
ctx.reply(ctx.tr("Couldn't read the playback history."));
|
||||
return;
|
||||
}
|
||||
if (recent->empty()) {
|
||||
ctx.reply("Nothing has been played yet.");
|
||||
ctx.reply(ctx.tr("Nothing has been played yet."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include "../MusicManager.hpp"
|
||||
#include "../i18n/Localization.hpp"
|
||||
#include "Command.hpp"
|
||||
#include <Database.hpp>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// !language [en|ru] — show or set the caller's reply language. The choice
|
||||
// is stored per user (keyed by the stable TS3 unique identifier) in
|
||||
// kv_store so it survives reconnects and restarts. With no argument it
|
||||
// reports the current language and the available options.
|
||||
class LanguageCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
std::string arg = trimmedLower(ctx.args);
|
||||
|
||||
if (arg.empty()) {
|
||||
ctx.reply(
|
||||
ctx.trf("Current language: {}. Available: en, ru. Use "
|
||||
"{}language <en|ru>.",
|
||||
I18n::languageName(ctx.language), ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
const bool isEn =
|
||||
arg == "en" || arg == "eng" || arg == "english";
|
||||
const bool isRu = arg == "ru" || arg == "rus" ||
|
||||
arg == "russian" ||
|
||||
arg == "\xd1\x80\xd1\x83\xd1\x81\xd1\x81"
|
||||
"\xd0\xba\xd0\xb8\xd0\xb9";
|
||||
if (!isEn && !isRu) {
|
||||
ctx.reply(ctx.tr("Unknown language. Choose 'en' or 'ru'."));
|
||||
return;
|
||||
}
|
||||
const I18n::Language newLang =
|
||||
isRu ? I18n::Language::Russian : I18n::Language::English;
|
||||
|
||||
auto manager = ctx.musicManager.lock();
|
||||
auto db = ctx.service<Api::Database>();
|
||||
if (!manager || !db) {
|
||||
ctx.reply(
|
||||
ctx.tr("Language settings are unavailable right now."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto uid = manager->clientUid(ctx.clientId);
|
||||
if (!uid || uid->empty()) {
|
||||
ctx.reply(ctx.tr("Couldn't identify you on the server."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto saved = db->setKv(
|
||||
"lang:" + *uid, std::string(I18n::languageCode(newLang)));
|
||||
if (!saved) {
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't save your language. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirm in the newly selected language.
|
||||
std::string name(I18n::languageName(newLang));
|
||||
ctx.reply(std::vformat(
|
||||
I18n::translate("\xe2\x9c\x85 Language set to {}.",
|
||||
newLang),
|
||||
std::make_format_args(name)));
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Sets your reply language (English or Russian).";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override { return "[en|ru]"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Utility;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"lang"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string trimmedLower(std::string_view in)
|
||||
{
|
||||
size_t b = in.find_first_not_of(" \t");
|
||||
if (b == std::string_view::npos) {
|
||||
return {};
|
||||
}
|
||||
size_t e = in.find_last_not_of(" \t");
|
||||
std::string out(in.substr(b, e - b + 1));
|
||||
std::transform(out.begin(), out.end(), out.begin(),
|
||||
[](unsigned char c) { return std::tolower(c); });
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/LyricsService.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// !lyrics — show the lyrics of the currently playing track (via lrclib).
|
||||
class LyricsCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto current = manager->getCurrentTrack();
|
||||
if (!current || !current->has_value()) {
|
||||
ctx.reply(ctx.trf("Nothing is currently playing. "
|
||||
"Add something with {}play !",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& track = current->value().track;
|
||||
|
||||
auto lyrics = ctx.service<LyricsService>();
|
||||
if (!lyrics) {
|
||||
ctx.reply(ctx.tr("Lyrics are unavailable right now."));
|
||||
return;
|
||||
}
|
||||
|
||||
long long durationSec =
|
||||
track.duration.has_value()
|
||||
? track.duration->count() / 1000
|
||||
: 0;
|
||||
auto result = lyrics->fetch(track.title, track.artist,
|
||||
track.album, durationSec);
|
||||
|
||||
if (!result.found || result.plain.empty()) {
|
||||
ctx.reply(ctx.trf("No lyrics found for {}.",
|
||||
trackLink(track)));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string msg = std::format(
|
||||
"\xf0\x9f\x8e\xa4 {}\n\n{}", trackLink(track),
|
||||
result.plain);
|
||||
ctx.reply(msg);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error(
|
||||
"LyricsCommand", "{}",
|
||||
std::format("Lyrics command exception: {}", e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Shows the lyrics of the current track.";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"ly"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -17,14 +17,15 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: move <from> <to>\nExample: move 5 1 "
|
||||
"(moves track 5 to position 1)");
|
||||
ctx.reply(
|
||||
ctx.tr("Usage: move <from> <to>\nExample: move 5 1 "
|
||||
"(moves track 5 to position 1)"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +34,8 @@ namespace Echoion::Core
|
||||
|
||||
auto spacePos = ctx.args.find(' ');
|
||||
if (spacePos == std::string::npos) {
|
||||
ctx.reply("Please provide both from and to positions.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Please provide both from and to positions."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,35 +48,40 @@ namespace Echoion::Core
|
||||
|
||||
if (result1.ec != std::errc() ||
|
||||
result2.ec != std::errc() || from == 0 || to == 0) {
|
||||
ctx.reply("Please provide valid position numbers "
|
||||
"(starting from 1).");
|
||||
ctx.reply(
|
||||
ctx.tr("Please provide valid position numbers "
|
||||
"(starting from 1)."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto moveResult = manager->moveInQueue(
|
||||
from - 1, to - 1); // Convert to 0-based
|
||||
if (!moveResult) {
|
||||
Void::Log::error("MoveCommand", "{}",
|
||||
Void::Log::error(
|
||||
"MoveCommand", "{}",
|
||||
std::format("Move command failed: {}",
|
||||
moveResult.error().message));
|
||||
|
||||
if (moveResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply("One of those positions doesn't exist in "
|
||||
"the queue.");
|
||||
ctx.reply(ctx.tr(
|
||||
"One of those positions doesn't exist in "
|
||||
"the queue."));
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't move that track. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't move that track. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(std::format(
|
||||
"Moved track from position {} to {}.", from, to));
|
||||
ctx.reply(ctx.trf("Moved track from position {} to {}.",
|
||||
from, to));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("MoveCommand", "{}",
|
||||
Void::Log::error(
|
||||
"MoveCommand", "{}",
|
||||
std::format("Move command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,24 +16,26 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto current = manager->getCurrentTrack();
|
||||
if (!current) {
|
||||
Void::Log::error("NowPlayingCommand", "{}",
|
||||
Void::Log::error(
|
||||
"NowPlayingCommand", "{}",
|
||||
std::format("NowPlaying command failed: {}",
|
||||
current.error().message));
|
||||
ctx.reply("Couldn't get current track information.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't get current track information."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current->has_value()) {
|
||||
ctx.reply(std::format("Nothing is currently playing. "
|
||||
"Add something with {}play !",
|
||||
ctx.prefix));
|
||||
ctx.reply(ctx.trf("Nothing is currently playing. "
|
||||
"Add something with {}play !",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,11 +72,21 @@ namespace Echoion::Core
|
||||
escapeMarkdown(track.addedBy));
|
||||
}
|
||||
|
||||
// Same at-a-glance status footer as !help and !list.
|
||||
if (std::string status = playbackStatusLine(ctx);
|
||||
!status.empty()) {
|
||||
msg += "\n\n";
|
||||
msg += status;
|
||||
}
|
||||
|
||||
ctx.reply(msg);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("NowPlayingCommand", "{}", std::format(
|
||||
"NowPlaying command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"NowPlayingCommand", "{}",
|
||||
std::format("NowPlaying command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,22 +104,6 @@ namespace Echoion::Core
|
||||
{
|
||||
return {"np", "current", "playing"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string
|
||||
formatDuration(std::chrono::milliseconds duration)
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -16,32 +16,34 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->pause();
|
||||
if (!result) {
|
||||
Void::Log::error("PauseCommand", "{}",
|
||||
std::format("Pause command failed: {}",
|
||||
result.error().message));
|
||||
Void::Log::error("PauseCommand", "{}",
|
||||
std::format("Pause command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
ctx.reply(ctx.tr("Nothing is playing right now."));
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't pause playback. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't pause playback. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback paused.");
|
||||
ctx.reply(ctx.tr("Playback paused."));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("PauseCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PauseCommand", "{}",
|
||||
std::format("Pause command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,17 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply("The music service is currently unavailable. "
|
||||
"Please try again later.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable. "
|
||||
"Please try again later."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(std::format(
|
||||
"Usage: {} <url or search query>\nExample: {} never "
|
||||
"gonna give you up",
|
||||
label(), label()));
|
||||
ctx.reply(ctx.trf("Usage: {} <url or search "
|
||||
"query>\nExample: {} never "
|
||||
"gonna give you up",
|
||||
label(), label()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,50 +40,57 @@ namespace Echoion::Core
|
||||
if (ctx.args.find("http") == 0) {
|
||||
auto result = manager->play(ctx.args, ctx.clientId);
|
||||
if (!result) {
|
||||
Void::Log::error("PlayCommand", "{}",
|
||||
std::format("Play URL failed '{}': {}", ctx.args,
|
||||
result.error().message));
|
||||
Void::Log::error(
|
||||
"PlayCommand", "{}",
|
||||
std::format("Play URL failed '{}': {}",
|
||||
ctx.args, result.error().message));
|
||||
|
||||
switch (result.error().code) {
|
||||
case Api::ErrorCode::NetworkError:
|
||||
ctx.reply("Couldn't connect to that URL. "
|
||||
"Please check and try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't connect to that URL. "
|
||||
"Please check and try again."));
|
||||
break;
|
||||
case Api::ErrorCode::InvalidUrl:
|
||||
ctx.reply(
|
||||
"That doesn't look like a valid URL.");
|
||||
ctx.reply(ctx.tr(
|
||||
"That doesn't look like a valid URL."));
|
||||
break;
|
||||
default:
|
||||
ctx.reply("Couldn't play that URL. Please "
|
||||
"try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't play that URL. Please "
|
||||
"try again."));
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(std::format("Added to queue: {}", *result));
|
||||
ctx.reply(ctx.trf("Added to queue: {}", *result));
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, search the chosen catalog(s).
|
||||
auto searchResult = manager->search(ctx.args, scope());
|
||||
if (!searchResult) {
|
||||
Void::Log::error("PlayCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PlayCommand", "{}",
|
||||
std::format("Search failed for '{}': {}", ctx.args,
|
||||
searchResult.error().message));
|
||||
|
||||
if (searchResult.error().code ==
|
||||
Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. "
|
||||
"Please check your connection.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't connect to search service. "
|
||||
"Please check your connection."));
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Search failed. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchResult->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
ctx.reply(ctx.tr(
|
||||
"No results found. Try different keywords."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,11 +100,12 @@ namespace Echoion::Core
|
||||
auto playResult =
|
||||
manager->queueTrack(track, ctx.clientId);
|
||||
if (!playResult) {
|
||||
Void::Log::error("PlayCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PlayCommand", "{}",
|
||||
std::format("Queue failed: {}",
|
||||
playResult.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't add that track. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't add that track. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,7 +114,7 @@ namespace Echoion::Core
|
||||
displayText = std::format("{} by {}", track.title,
|
||||
track.artist);
|
||||
}
|
||||
ctx.reply(std::format(
|
||||
ctx.reply(ctx.trf(
|
||||
"Added to queue: {}",
|
||||
markdownLink(displayText, trackLinkUrl(track))));
|
||||
return;
|
||||
@@ -115,9 +124,10 @@ namespace Echoion::Core
|
||||
manager->storePendingSearch(ctx.clientId,
|
||||
searchResult->tracks);
|
||||
|
||||
std::string msg = std::format(
|
||||
"Multiple results \xe2\x80\x94 use {}select <number>:\n\n",
|
||||
ctx.prefix);
|
||||
std::string msg =
|
||||
std::format("Multiple results \xe2\x80\x94 use "
|
||||
"{}select <number>:\n\n",
|
||||
ctx.prefix);
|
||||
for (size_t i = 0; i < searchResult->tracks.size() && i < 5;
|
||||
++i) {
|
||||
const auto& track = searchResult->tracks[i];
|
||||
@@ -139,10 +149,12 @@ namespace Echoion::Core
|
||||
ctx.reply(msg);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("PlayCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PlayCommand", "{}",
|
||||
std::format("Play command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong while trying to play. "
|
||||
"Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong while trying to play. "
|
||||
"Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,23 +26,25 @@ namespace Echoion::Core
|
||||
// List playlists
|
||||
auto playlists = manager->getPlaylists();
|
||||
if (!playlists) {
|
||||
Void::Log::error("PlaylistCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PlaylistCommand", "{}",
|
||||
std::format("Playlist list failed: {}",
|
||||
playlists.error().message));
|
||||
ctx.reply("Couldn't retrieve playlists.");
|
||||
ctx.reply(ctx.tr("Couldn't retrieve playlists."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (playlists->empty()) {
|
||||
ctx.reply("No playlists available.");
|
||||
ctx.reply(ctx.tr("No playlists available."));
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x81 Available playlists:\n";
|
||||
msg << ctx.tr(
|
||||
"\xf0\x9f\x93\x81 Available playlists:\n");
|
||||
for (const auto& pl : *playlists) {
|
||||
msg << std::format("- {} ({} tracks)\n", pl.name,
|
||||
pl.tracks.size());
|
||||
msg << ctx.trf("- {} ({} tracks)\n", pl.name,
|
||||
pl.tracks.size());
|
||||
}
|
||||
|
||||
ctx.reply(msg.str());
|
||||
@@ -51,29 +53,35 @@ namespace Echoion::Core
|
||||
auto result = manager->loadPlaylist(
|
||||
std::string(ctx.args), ctx.clientId);
|
||||
if (!result) {
|
||||
Void::Log::error("PlaylistCommand", "{}",
|
||||
Void::Log::error(
|
||||
"PlaylistCommand", "{}",
|
||||
std::format("Playlist load failed: {}",
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply("That playlist doesn't exist.");
|
||||
ctx.reply(
|
||||
ctx.tr("That playlist doesn't exist."));
|
||||
} else {
|
||||
ctx.reply("Couldn't load the playlist. Please "
|
||||
"try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't load the playlist. Please "
|
||||
"try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(std::format(
|
||||
ctx.reply(ctx.trf(
|
||||
"Loading playlist '{}'... Tracks will be added to "
|
||||
"the queue as they are resolved.",
|
||||
ctx.args));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("PlaylistCommand", "{}", std::format(
|
||||
"Playlist command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"PlaylistCommand", "{}",
|
||||
std::format("Playlist command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@ namespace Echoion::Core
|
||||
auto state = manager->getPlaybackState();
|
||||
|
||||
if (!queue) {
|
||||
Void::Log::error("QueueCommand", "{}", std::format(
|
||||
"Queue command failed: {}", queue.error().message));
|
||||
ctx.reply("Couldn't get queue information.");
|
||||
Void::Log::error("QueueCommand", "{}",
|
||||
std::format("Queue command failed: {}",
|
||||
queue.error().message));
|
||||
ctx.reply(ctx.tr("Couldn't get queue information."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,9 +65,16 @@ namespace Echoion::Core
|
||||
static_cast<int>(queue->size()));
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x9c **Queue** (Page " << page << "/"
|
||||
<< totalPages << ")\n";
|
||||
|
||||
// Same at-a-glance status footer as !help and !np. A
|
||||
// "Paused" marker is prepended since the queue view is
|
||||
// where a stopped playhead is most relevant.
|
||||
if (std::string status = playbackStatusLine(ctx);
|
||||
!status.empty()) {
|
||||
if (state && state->isPaused) {
|
||||
msg << ctx.tr("\xe2\x8f\xb8 Paused\n");
|
||||
}
|
||||
msg << status;
|
||||
}
|
||||
// Current track
|
||||
if (current && current->has_value()) {
|
||||
const auto& track = current->value();
|
||||
@@ -94,21 +102,20 @@ namespace Echoion::Core
|
||||
displayText = std::format(
|
||||
"{} by {}", trackInfo.title, trackInfo.artist);
|
||||
}
|
||||
msg << std::format(
|
||||
msg << ctx.trf(
|
||||
"\n**Now Playing:** {}{}\n",
|
||||
markdownLink(displayText,
|
||||
trackLinkUrl(trackInfo)),
|
||||
markdownLink(displayText, trackLinkUrl(trackInfo)),
|
||||
timeStr);
|
||||
}
|
||||
|
||||
// Queue
|
||||
if (queue->empty()) {
|
||||
msg << std::format(
|
||||
msg << ctx.trf(
|
||||
"\nThe queue is empty. Add songs with {}play !",
|
||||
ctx.prefix);
|
||||
} else {
|
||||
msg << std::format("\n**Up Next ({} tracks):**\n",
|
||||
queue->size());
|
||||
msg << ctx.trf("\n**Up Next ({} tracks):**\n",
|
||||
queue->size());
|
||||
for (int i = startIdx; i < endIdx; ++i) {
|
||||
const auto& entry = (*queue)[i];
|
||||
const auto& trackInfo = entry.track;
|
||||
@@ -118,52 +125,38 @@ namespace Echoion::Core
|
||||
std::format("{} by {}", trackInfo.title,
|
||||
trackInfo.artist);
|
||||
}
|
||||
msg << std::format(
|
||||
msg << ctx.trf(
|
||||
"{}. {}", i + 1,
|
||||
markdownLink(displayText,
|
||||
trackLinkUrl(trackInfo)));
|
||||
if (trackInfo.duration.has_value()) {
|
||||
msg << std::format(
|
||||
msg << ctx.trf(
|
||||
" {} {}", kDot,
|
||||
formatDuration(*trackInfo.duration));
|
||||
}
|
||||
if (!entry.addedBy.empty()) {
|
||||
msg << std::format(
|
||||
" (by {})", escapeMarkdown(entry.addedBy));
|
||||
msg << ctx.trf(" (by {})",
|
||||
escapeMarkdown(entry.addedBy));
|
||||
}
|
||||
msg << "\n";
|
||||
msg << ctx.tr("\n");
|
||||
}
|
||||
|
||||
if (totalPages > 1) {
|
||||
msg << std::format(
|
||||
"\nUse {}queue <page> to see more "
|
||||
"(page {} of {})",
|
||||
ctx.prefix, page, totalPages);
|
||||
msg << ctx.trf("\nUse {}queue <page> to see more "
|
||||
"(page {} of {})",
|
||||
ctx.prefix, page, totalPages);
|
||||
}
|
||||
}
|
||||
|
||||
// State indicators
|
||||
if (state) {
|
||||
msg << "\n\n";
|
||||
if (state->isPaused) {
|
||||
msg << "\xe2\x8f\xb8 Paused | ";
|
||||
}
|
||||
if (state->shuffle) {
|
||||
msg << "\xf0\x9f\x94\x80 Shuffle | ";
|
||||
}
|
||||
if (state->repeat) {
|
||||
msg << "\xf0\x9f\x94\x81 Repeat | ";
|
||||
}
|
||||
msg << std::format(
|
||||
"Volume: {}%",
|
||||
static_cast<int>(state->volume * 100));
|
||||
}
|
||||
|
||||
msg << ctx.tr("\xf0\x9f\x93\x9c **Queue** (Page ") << page
|
||||
<< "/" << totalPages << ctx.tr(")\n");
|
||||
ctx.reply(msg.str());
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("QueueCommand", "{}",
|
||||
Void::Log::error(
|
||||
"QueueCommand", "{}",
|
||||
std::format("Queue command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,22 +176,6 @@ namespace Echoion::Core
|
||||
{
|
||||
return {"q", "list"};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static std::string
|
||||
formatDuration(std::chrono::milliseconds duration)
|
||||
{
|
||||
auto totalSeconds = duration.count() / 1000;
|
||||
auto hours = totalSeconds / 3600;
|
||||
auto mins = (totalSeconds % 3600) / 60;
|
||||
auto secs = totalSeconds % 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return std::format("{}:{:02}:{:02}", hours, mins, secs);
|
||||
}
|
||||
return std::format("{}:{:02}", mins, secs);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -22,15 +22,17 @@ namespace Echoion::Core
|
||||
if (auto core = ctx.service<Api::ICoreInterface>()) {
|
||||
auto result = core->reloadConfig();
|
||||
if (result) {
|
||||
ctx.reply("✅ Configuration reloaded. For a full core "
|
||||
"reload, use the TS plugin menu.");
|
||||
ctx.reply(
|
||||
ctx.tr("✅ Configuration reloaded. For a full core "
|
||||
"reload, use the TS plugin menu."));
|
||||
} else {
|
||||
ctx.reply(std::string("❌ Config reload failed: ") +
|
||||
result.error().message);
|
||||
}
|
||||
} else {
|
||||
ctx.reply("Reload is handled by the plugin. Use the TS "
|
||||
"plugin menu to reload the core.");
|
||||
ctx.reply(
|
||||
ctx.tr("Reload is handled by the plugin. Use the TS "
|
||||
"plugin menu to reload the core."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,21 +17,27 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto core = ctx.service<Api::ICoreInterface>();
|
||||
if (!core) {
|
||||
ctx.reply("Config reload is unavailable right now.");
|
||||
ctx.reply(
|
||||
ctx.tr("Config reload is unavailable right now."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = core->reloadConfig();
|
||||
if (result) {
|
||||
ctx.reply("✅ Configuration reloaded from disk.");
|
||||
ctx.reply(
|
||||
ctx.tr("✅ Configuration reloaded from disk."));
|
||||
} else {
|
||||
ctx.reply(std::string("❌ Failed to reload config: ") +
|
||||
result.error().message);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("ReloadConfigCommand", "{}", std::format(
|
||||
"ReloadConfig command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"ReloadConfigCommand",
|
||||
"{}",
|
||||
std::format("ReloadConfig command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(
|
||||
std::format("Usage: remove <position>\nUse {}queue "
|
||||
"to see track positions.",
|
||||
ctx.prefix));
|
||||
ctx.trf("Usage: remove <position>\nUse {}queue "
|
||||
"to see track positions.",
|
||||
ctx.prefix));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,35 +36,40 @@ namespace Echoion::Core
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
position);
|
||||
if (result.ec != std::errc() || position == 0) {
|
||||
ctx.reply("Please provide a valid position number "
|
||||
"(starting from 1).");
|
||||
ctx.reply(
|
||||
ctx.tr("Please provide a valid position number "
|
||||
"(starting from 1)."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto remResult = manager->removeFromQueue(
|
||||
position - 1); // Convert to 0-based
|
||||
if (!remResult) {
|
||||
Void::Log::error("RemoveCommand", "{}",
|
||||
Void::Log::error(
|
||||
"RemoveCommand", "{}",
|
||||
std::format("Remove command failed: {}",
|
||||
remResult.error().message));
|
||||
|
||||
if (remResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply(
|
||||
"That position doesn't exist in the queue.");
|
||||
ctx.reply(ctx.tr(
|
||||
"That position doesn't exist in the queue."));
|
||||
} else {
|
||||
ctx.reply("Couldn't remove that track. Please try "
|
||||
"again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't remove that track. Please try "
|
||||
"again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(
|
||||
std::format("Removed track at position {}.", position));
|
||||
ctx.trf("Removed track at position {}.", position));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("RemoveCommand", "{}",
|
||||
Void::Log::error(
|
||||
"RemoveCommand", "{}",
|
||||
std::format("Remove command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,26 +16,31 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->toggleRepeat();
|
||||
if (!result) {
|
||||
Void::Log::error("RepeatCommand", "{}",
|
||||
Void::Log::error(
|
||||
"RepeatCommand", "{}",
|
||||
std::format("Repeat command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't toggle repeat. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't toggle repeat. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result ? "\xf0\x9f\x94\x81 Repeat is now ON."
|
||||
: "Repeat is now OFF.");
|
||||
ctx.reply(*result
|
||||
? ctx.tr("\xf0\x9f\x94\x81 Repeat is now ON.")
|
||||
: ctx.tr("Repeat is now OFF."));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("RepeatCommand", "{}",
|
||||
Void::Log::error(
|
||||
"RepeatCommand", "{}",
|
||||
std::format("Repeat command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,32 +16,36 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->resume();
|
||||
if (!result) {
|
||||
Void::Log::error("ResumeCommand", "{}",
|
||||
Void::Log::error(
|
||||
"ResumeCommand", "{}",
|
||||
std::format("Resume command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Playback isn't paused right now.");
|
||||
} else {
|
||||
ctx.reply(
|
||||
"Couldn't resume playback. Please try again.");
|
||||
ctx.tr("Playback isn't paused right now."));
|
||||
} else {
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't resume playback. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback resumed.");
|
||||
ctx.reply(ctx.tr("Playback resumed."));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("ResumeCommand", "{}",
|
||||
Void::Log::error(
|
||||
"ResumeCommand", "{}",
|
||||
std::format("Resume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,34 +20,38 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(std::format("Usage: {} <query>", label()));
|
||||
ctx.reply(ctx.trf("Usage: {} <query>", label()));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->search(ctx.args, scope());
|
||||
if (!result) {
|
||||
Void::Log::error("SearchCommand", "{}",
|
||||
Void::Log::error(
|
||||
"SearchCommand", "{}",
|
||||
std::format("Search failed for '{}': {}", ctx.args,
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::NetworkError) {
|
||||
ctx.reply("Couldn't connect to search service. "
|
||||
"Please check your connection.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't connect to search service. "
|
||||
"Please check your connection."));
|
||||
} else {
|
||||
ctx.reply("Search failed. Please try again later.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Search failed. Please try again later."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result->tracks.empty()) {
|
||||
ctx.reply("No results found. Try different keywords.");
|
||||
ctx.reply(ctx.tr(
|
||||
"No results found. Try different keywords."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +59,8 @@ namespace Echoion::Core
|
||||
manager->storePendingSearch(ctx.clientId, result->tracks);
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "Search results for \"" << ctx.args << "\":\n\n";
|
||||
msg << ctx.tr("Search results for \"") << ctx.args
|
||||
<< ctx.tr("\":\n\n");
|
||||
|
||||
for (size_t i = 0; i < result->tracks.size() && i < 5;
|
||||
++i) {
|
||||
@@ -67,26 +72,27 @@ namespace Echoion::Core
|
||||
}
|
||||
// [escaped title](url) · duration (no [] around the
|
||||
// duration: TeamSpeak parses [..] as a link reference).
|
||||
msg << std::format(
|
||||
msg << ctx.trf(
|
||||
"{}. {}", i + 1,
|
||||
markdownLink(displayText, trackLinkUrl(track)));
|
||||
if (track.duration.has_value()) {
|
||||
msg << " " << kDot << " "
|
||||
<< formatDuration(*track.duration);
|
||||
}
|
||||
msg << "\n";
|
||||
msg << ctx.tr("\n");
|
||||
}
|
||||
|
||||
msg << std::format(
|
||||
"\nUse {}select <number> to play a result.",
|
||||
ctx.prefix);
|
||||
msg << ctx.trf("\nUse {}select <number> to play a result.",
|
||||
ctx.prefix);
|
||||
|
||||
ctx.reply(msg.str());
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SearchCommand", "{}",
|
||||
Void::Log::error(
|
||||
"SearchCommand", "{}",
|
||||
std::format("Search command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,16 +18,16 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply(
|
||||
ctx.reply(ctx.tr(
|
||||
"Usage: seek <+/-seconds>\nExamples:\n seek +30 "
|
||||
"(skip forward 30s)\n seek -10 (skip back 10s)\n "
|
||||
"seek 60 (jump to 1 minute mark)");
|
||||
"seek 60 (jump to 1 minute mark)"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ namespace Echoion::Core
|
||||
auto parseResult = std::from_chars(
|
||||
arg.data(), arg.data() + arg.size(), seconds);
|
||||
if (parseResult.ec != std::errc() || seconds < 0) {
|
||||
ctx.reply(
|
||||
ctx.reply(ctx.tr(
|
||||
"Please provide a valid number of "
|
||||
"seconds.\nExamples: seek +30, seek -10, seek 60");
|
||||
"seconds.\nExamples: seek +30, seek -10, seek 60"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace Echoion::Core
|
||||
// Get current position from playback state
|
||||
auto state = manager->getPlaybackState();
|
||||
if (!state) {
|
||||
ctx.reply(
|
||||
"Unable to get current playback position.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Unable to get current playback position."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,32 +94,37 @@ namespace Echoion::Core
|
||||
|
||||
auto result = manager->seek(targetPosition);
|
||||
if (!result) {
|
||||
Void::Log::error("SeekCommand", "{}", std::format("Seek command failed: {}",
|
||||
result.error().message));
|
||||
Void::Log::error("SeekCommand", "{}",
|
||||
std::format("Seek command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code ==
|
||||
Api::ErrorCode::InvalidArgument) {
|
||||
ctx.reply("Nothing is playing right now.");
|
||||
ctx.reply(ctx.tr("Nothing is playing right now."));
|
||||
} else if (result.error().code ==
|
||||
Api::ErrorCode::NotSupported) {
|
||||
ctx.reply("This track doesn't support seeking.");
|
||||
ctx.reply(
|
||||
ctx.tr("This track doesn't support seeking."));
|
||||
} else {
|
||||
ctx.reply("Couldn't seek. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't seek. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (relative) {
|
||||
ctx.reply(std::format(
|
||||
"Seeked {} from current position.", positionStr));
|
||||
ctx.reply(ctx.trf("Seeked {} from current position.",
|
||||
positionStr));
|
||||
} else {
|
||||
ctx.reply(
|
||||
std::format("Seeked to position {}.", positionStr));
|
||||
ctx.trf("Seeked to position {}.", positionStr));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SeekCommand", "{}",
|
||||
Void::Log::error(
|
||||
"SeekCommand", "{}",
|
||||
std::format("Seek command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,15 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: select <number>\nSelect a track from "
|
||||
"your last search results.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Usage: select <number>\nSelect a track from "
|
||||
"your last search results."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,8 +36,8 @@ namespace Echoion::Core
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
index);
|
||||
if (result.ec != std::errc() || index == 0) {
|
||||
ctx.reply(
|
||||
"Please provide a valid number (1, 2, 3, etc.).");
|
||||
ctx.reply(ctx.tr(
|
||||
"Please provide a valid number (1, 2, 3, etc.)."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,19 +46,23 @@ namespace Echoion::Core
|
||||
ctx.clientId, index, invokerName);
|
||||
|
||||
if (!selectResult) {
|
||||
Void::Log::error("SelectCommand", "{}", std::format(
|
||||
"Select failed for client {} index {}: {}",
|
||||
ctx.clientId, index, selectResult.error().message));
|
||||
Void::Log::error(
|
||||
"SelectCommand", "{}",
|
||||
std::format(
|
||||
"Select failed for client {} index {}: {}",
|
||||
ctx.clientId, index,
|
||||
selectResult.error().message));
|
||||
|
||||
if (selectResult.error().code ==
|
||||
Api::ErrorCode::NotFound) {
|
||||
ctx.reply(std::format(
|
||||
"No search results found. Use {}play "
|
||||
"<query> to search first.",
|
||||
ctx.prefix));
|
||||
ctx.reply(
|
||||
ctx.trf("No search results found. Use {}play "
|
||||
"<query> to search first.",
|
||||
ctx.prefix));
|
||||
} else {
|
||||
ctx.reply("Couldn't select that track. Please try "
|
||||
"again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't select that track. Please try "
|
||||
"again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -65,9 +70,11 @@ namespace Echoion::Core
|
||||
ctx.reply(*selectResult);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SelectCommand", "{}",
|
||||
Void::Log::error(
|
||||
"SelectCommand", "{}",
|
||||
std::format("Select command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,29 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually shuffle the queue (not just toggle mode)
|
||||
manager->shuffleQueue();
|
||||
if (auto result = manager->shuffleQueue(); !result) {
|
||||
Void::Log::warn(
|
||||
"ShuffleCommand", "{}",
|
||||
std::format("Shuffle failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.tr(
|
||||
"Something went wrong. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("\xf0\x9f\x94\x80 Queue shuffled!");
|
||||
ctx.reply(ctx.tr("\xf0\x9f\x94\x80 Queue shuffled!"));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("ShuffleCommand", "{}",
|
||||
Void::Log::error(
|
||||
"ShuffleCommand", "{}",
|
||||
std::format("Shuffle command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,35 +29,39 @@ namespace Echoion::Core
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
count);
|
||||
if (result.ec != std::errc() || count == 0) {
|
||||
ctx.reply(
|
||||
"Please provide a valid number (1 or more).");
|
||||
ctx.reply(ctx.tr(
|
||||
"Please provide a valid number (1 or more)."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto result = manager->skip(count);
|
||||
if (!result) {
|
||||
Void::Log::error("SkipCommand", "{}", std::format("Skip command failed: {}",
|
||||
result.error().message));
|
||||
Void::Log::error("SkipCommand", "{}",
|
||||
std::format("Skip command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply(
|
||||
"No more tracks in the queue to skip to.");
|
||||
ctx.reply(ctx.tr(
|
||||
"No more tracks in the queue to skip to."));
|
||||
} else {
|
||||
ctx.reply("Couldn't skip. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Couldn't skip. Please try again."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
ctx.reply("Skipped to next track.");
|
||||
ctx.reply(ctx.tr("Skipped to next track."));
|
||||
} else {
|
||||
ctx.reply(std::format("Skipped {} tracks.", count));
|
||||
ctx.reply(ctx.trf("Skipped {} tracks.", count));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SkipCommand", "{}",
|
||||
Void::Log::error(
|
||||
"SkipCommand", "{}",
|
||||
std::format("Skip command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "PlayCommand.hpp"
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// !psc / !playsc — play from SoundCloud only (URL or search).
|
||||
class SoundCloudPlayCommand : public PlayCommandBase
|
||||
{
|
||||
public:
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Plays from SoundCloud only (URL or search).";
|
||||
}
|
||||
std::string_view getUsage() const override
|
||||
{
|
||||
return "<url or search query>";
|
||||
}
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"playsc"};
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MusicManager::SearchScope scope() const override
|
||||
{
|
||||
return MusicManager::SearchScope::SoundCloud;
|
||||
}
|
||||
std::string_view label() const override { return "psc"; }
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "SearchCommand.hpp"
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// !soundcloud / !sc — search SoundCloud only.
|
||||
class SoundCloudSearchCommand : public SearchCommandBase
|
||||
{
|
||||
public:
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Search SoundCloud only for tracks.";
|
||||
}
|
||||
std::string_view getUsage() const override { return "<query>"; }
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"sc", "scloud"};
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MusicManager::SearchScope scope() const override
|
||||
{
|
||||
return MusicManager::SearchScope::SoundCloud;
|
||||
}
|
||||
std::string_view label() const override { return "soundcloud"; }
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
@@ -16,18 +16,18 @@ namespace Echoion::Core
|
||||
{
|
||||
auto db = ctx.service<Api::Database>();
|
||||
if (!db) {
|
||||
ctx.reply("Statistics are unavailable (no database).");
|
||||
ctx.reply(
|
||||
ctx.tr("Statistics are unavailable (no database)."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto stats = db->getStatistics(0);
|
||||
if (!stats) {
|
||||
ctx.reply("Couldn't read playback statistics.");
|
||||
ctx.reply(ctx.tr("Couldn't read playback statistics."));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto totalMinutes =
|
||||
stats->totalPlaytimeMs / 1000 / 60;
|
||||
const auto totalMinutes = stats->totalPlaytimeMs / 1000 / 60;
|
||||
std::string msg = std::format(
|
||||
"\xf0\x9f\x93\x8a Plays: {} {} Unique tracks: {} {} "
|
||||
"Playtime: {}h {}m",
|
||||
|
||||
@@ -16,24 +16,28 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->stop();
|
||||
if (!result) {
|
||||
Void::Log::error("StopCommand", "{}", std::format("Stop command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't stop playback. Please try again.");
|
||||
Void::Log::error("StopCommand", "{}",
|
||||
std::format("Stop command failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't stop playback. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("Playback stopped and queue cleared.");
|
||||
ctx.reply(ctx.tr("Playback stopped and queue cleared."));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("StopCommand", "{}",
|
||||
Void::Log::error(
|
||||
"StopCommand", "{}",
|
||||
std::format("Stop command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,24 +16,31 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->subscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
Void::Log::error("SubscribeCommand", "{}", std::format("Subscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply("Couldn't subscribe you. Please try again.");
|
||||
Void::Log::error("SubscribeCommand",
|
||||
"{}",
|
||||
std::format("Subscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't subscribe you. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SubscribeCommand", "{}", std::format(
|
||||
"Subscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"SubscribeCommand",
|
||||
"{}",
|
||||
std::format("Subscribe command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include <sstream>
|
||||
@@ -19,8 +19,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace Echoion::Core
|
||||
auto onlineUids = manager->getOnlineSubscriberUids();
|
||||
|
||||
if (subscribers.empty()) {
|
||||
ctx.reply(
|
||||
"No subscribers. Use !subscribe to receive audio.");
|
||||
ctx.reply(ctx.tr("No subscribers. Use !subscribe to "
|
||||
"receive audio."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,45 +46,48 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
std::stringstream msg;
|
||||
msg << "\xf0\x9f\x93\x8b **Subscribed Users** ("
|
||||
<< subscribers.size() << " total)\n";
|
||||
msg << "\xf0\x9f\x9f\xa2 Online: " << online.size()
|
||||
<< " | \xe2\x9a\xaa Offline: " << offline.size()
|
||||
<< "\n\n";
|
||||
msg << ctx.tr("\xf0\x9f\x93\x8b **Subscribed Users** (")
|
||||
<< subscribers.size() << ctx.tr(" total)\n");
|
||||
msg << ctx.tr("\xf0\x9f\x9f\xa2 Online: ") << online.size()
|
||||
<< ctx.tr(" | \xe2\x9a\xaa Offline: ") << offline.size()
|
||||
<< ctx.tr("\n\n");
|
||||
|
||||
// Online subscribers
|
||||
if (!online.empty()) {
|
||||
msg << "**\xf0\x9f\x9f\xa2 Online:**\n";
|
||||
msg << ctx.tr("**\xf0\x9f\x9f\xa2 Online:**\n");
|
||||
for (size_t i = 0; i < online.size(); ++i) {
|
||||
const auto& sub = online[i];
|
||||
msg << std::format("{}. **{}**\n", i + 1,
|
||||
sub.nickname);
|
||||
msg << std::format(" UID: `{}`\n", sub.uid);
|
||||
msg << ctx.trf("{}. **{}**\n", i + 1, sub.nickname);
|
||||
msg << ctx.trf(" UID: `{}`\n", sub.uid);
|
||||
}
|
||||
msg << "\n";
|
||||
msg << ctx.tr("\n");
|
||||
}
|
||||
|
||||
// Offline subscribers
|
||||
if (!offline.empty()) {
|
||||
msg << "**\xe2\x9a\xaa Offline:**\n";
|
||||
msg << ctx.tr("**\xe2\x9a\xaa Offline:**\n");
|
||||
for (size_t i = 0; i < offline.size(); ++i) {
|
||||
const auto& sub = offline[i];
|
||||
msg << std::format("{}. **{}**\n", i + 1,
|
||||
sub.nickname);
|
||||
msg << std::format(" UID: `{}`\n", sub.uid);
|
||||
msg << ctx.trf("{}. **{}**\n", i + 1, sub.nickname);
|
||||
msg << ctx.trf(" UID: `{}`\n", sub.uid);
|
||||
}
|
||||
msg << "\n";
|
||||
msg << ctx.tr("\n");
|
||||
}
|
||||
|
||||
msg << "Use `!unsubscribeid <uid>` to remove a specific "
|
||||
"subscriber.\n";
|
||||
msg << "Use `!unsubscribeall` to remove all subscribers.";
|
||||
msg << ctx.tr(
|
||||
"Use `!unsubscribeid <uid>` to remove a specific "
|
||||
"subscriber.\n");
|
||||
msg << ctx.tr(
|
||||
"Use `!unsubscribeall` to remove all subscribers.");
|
||||
|
||||
ctx.reply(msg.str());
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SubscribersCommand", "{}", std::format(
|
||||
"Subscribers command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"SubscribersCommand", "{}",
|
||||
std::format("Subscribers command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core
|
||||
@@ -17,27 +17,31 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->clearAllSubscriptions();
|
||||
|
||||
if (!result) {
|
||||
Void::Log::error("UnsubscribeAllCommand", "{}",
|
||||
Void::Log::error(
|
||||
"UnsubscribeAllCommand", "{}",
|
||||
std::format("Unsubscribe all failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't clear subscriptions. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't clear subscriptions. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("UnsubscribeAllCommand", "{}", std::format(
|
||||
"Unsubscribeall command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"UnsubscribeAllCommand", "{}",
|
||||
std::format("Unsubscribeall command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,25 +16,31 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->unsubscribe(ctx.clientId);
|
||||
if (!result) {
|
||||
Void::Log::error("UnsubscribeCommand", "{}", std::format("Unsubscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't unsubscribe you. Please try again.");
|
||||
Void::Log::error("UnsubscribeCommand",
|
||||
"{}",
|
||||
std::format("Unsubscribe failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't unsubscribe you. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("UnsubscribeCommand", "{}", std::format(
|
||||
"Unsubscribe command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"UnsubscribeCommand",
|
||||
"{}",
|
||||
std::format("Unsubscribe command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include "echoion/core/MusicManager.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core
|
||||
@@ -17,14 +17,15 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Please provide a user UID. Use !subscribers "
|
||||
"to see UIDs.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Please provide a user UID. Use !subscribers "
|
||||
"to see UIDs."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,19 +33,23 @@ namespace Echoion::Core
|
||||
auto result = manager->unsubscribeByUid(uid);
|
||||
|
||||
if (!result) {
|
||||
Void::Log::error("UnsubscribeIdCommand", "{}",
|
||||
Void::Log::error(
|
||||
"UnsubscribeIdCommand", "{}",
|
||||
std::format("Unsubscribe by ID failed: {}",
|
||||
result.error().message));
|
||||
ctx.reply(
|
||||
"Couldn't unsubscribe user. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't unsubscribe user. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*result);
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("UnsubscribeIdCommand", "{}", std::format(
|
||||
"Unsubscribeid command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
Void::Log::error(
|
||||
"UnsubscribeIdCommand", "{}",
|
||||
std::format("Unsubscribeid command exception: {}",
|
||||
e.what()));
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Echoion::Core
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
ctx.reply(ctx.tr(
|
||||
"The music service is currently unavailable."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace Echoion::Core
|
||||
// Show current volume
|
||||
auto state = manager->getPlaybackState();
|
||||
if (state) {
|
||||
ctx.reply(std::format(
|
||||
"Current volume: {}%",
|
||||
static_cast<int>(state->volume * 100)));
|
||||
ctx.reply(
|
||||
ctx.trf("Current volume: {}%",
|
||||
static_cast<int>(state->volume * 100)));
|
||||
} else {
|
||||
ctx.reply("Unable to get current volume.");
|
||||
ctx.reply(ctx.tr("Unable to get current volume."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -42,22 +42,25 @@ namespace Echoion::Core
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
volumePercent);
|
||||
if (result.ec != std::errc()) {
|
||||
ctx.reply("Please provide a valid number (0-100).");
|
||||
ctx.reply(
|
||||
ctx.tr("Please provide a valid number (0-100)."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (volumePercent < 0 || volumePercent > 100) {
|
||||
ctx.reply("Volume must be between 0 and 100.");
|
||||
ctx.reply(ctx.tr("Volume must be between 0 and 100."));
|
||||
return;
|
||||
}
|
||||
|
||||
float volume = volumePercent / 100.0f;
|
||||
auto volResult = manager->setVolume(volume);
|
||||
if (!volResult) {
|
||||
Void::Log::error("VolumeCommand", "{}",
|
||||
Void::Log::error(
|
||||
"VolumeCommand", "{}",
|
||||
std::format("Volume command failed: {}",
|
||||
volResult.error().message));
|
||||
ctx.reply("Couldn't change volume. Please try again.");
|
||||
ctx.reply(ctx.tr(
|
||||
"Couldn't change volume. Please try again."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,12 +74,14 @@ namespace Echoion::Core
|
||||
: "\xe2\x96\x91"; // Full block / Light shade
|
||||
}
|
||||
|
||||
ctx.reply(std::format(
|
||||
"Volume: {}% {}", volumePercent, indicator));
|
||||
ctx.reply(
|
||||
ctx.trf("Volume: {}% {}", volumePercent, indicator));
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("VolumeCommand", "{}",
|
||||
Void::Log::error(
|
||||
"VolumeCommand", "{}",
|
||||
std::format("Volume command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
ctx.reply(
|
||||
ctx.tr("Something went wrong. Please try again."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace Echoion::Core::I18n
|
||||
{
|
||||
|
||||
// Languages the bot can reply in. English is the source language: every
|
||||
// English string in the code is a valid translation key, so English never
|
||||
// needs a table entry.
|
||||
enum class Language { English, Russian };
|
||||
|
||||
// Parse a language code ("en"/"ru", case-insensitive). Unknown codes fall
|
||||
// back to English so a bad config/kv value never breaks replies.
|
||||
Language parseLanguage(std::string_view code);
|
||||
|
||||
// The canonical code ("en"/"ru") — used as the kv_store / config value.
|
||||
std::string_view languageCode(Language lang);
|
||||
|
||||
// Human-readable, self-referential name ("English" / "Русский").
|
||||
std::string_view languageName(Language lang);
|
||||
|
||||
// Translate an English source string to `lang`. Returns the original string
|
||||
// unchanged when `lang` is English or no translation is registered, so a
|
||||
// missing entry degrades gracefully to English rather than to an empty
|
||||
// message.
|
||||
std::string_view translate(std::string_view english, Language lang);
|
||||
|
||||
} // namespace Echoion::Core::I18n
|
||||
@@ -63,9 +63,9 @@ namespace Echoion::Core
|
||||
virtual void onLocalFileDone(const std::string& path) = 0;
|
||||
// A track failed to resolve or open (before the engine advanced
|
||||
// past it). Called on the engine thread.
|
||||
virtual void
|
||||
onPlaybackError(const Api::Error& error,
|
||||
const std::optional<Api::QueueEntry>& entry) = 0;
|
||||
virtual void onPlaybackError(
|
||||
const Api::Error& error,
|
||||
const std::optional<Api::QueueEntry>& entry) = 0;
|
||||
};
|
||||
|
||||
// Real-time playback engine with gapless track transitions.
|
||||
@@ -86,9 +86,13 @@ namespace Echoion::Core
|
||||
static constexpr int CHUNK_MS = 20;
|
||||
static constexpr size_t SHORTS_PER_CHUNK =
|
||||
(SAMPLE_RATE * CHANNELS * CHUNK_MS) / 1000;
|
||||
static constexpr auto PREFETCH_THRESHOLD =
|
||||
std::chrono::seconds(15);
|
||||
static constexpr auto PREFETCH_THRESHOLD = std::chrono::seconds(15);
|
||||
static constexpr int MAX_CONSECUTIVE_FAILURES = 5;
|
||||
// Grace while a download-to-file retry is in flight. Must cover
|
||||
// YouTubeClient::downloadAudioToFile's 180s wait — the normal
|
||||
// resolve grace (bot.trackTimeout, ~10s) would skip the track
|
||||
// long before the download lands.
|
||||
static constexpr int64_t DOWNLOAD_GRACE_MS = 200'000;
|
||||
|
||||
// How long the engine emits silence waiting for a late resolve
|
||||
// before it gives up on the track and advances. Configurable via
|
||||
@@ -119,8 +123,8 @@ namespace Echoion::Core
|
||||
explicit PlaybackEngine(IPlaybackHost& host);
|
||||
~PlaybackEngine();
|
||||
|
||||
Api::Result<void> initialize(
|
||||
const std::optional<Void::Net::ProxyConfig>& proxy);
|
||||
Api::Result<void>
|
||||
initialize(const std::optional<Void::Net::ProxyConfig>& proxy);
|
||||
void shutdown();
|
||||
|
||||
void setProxyConfig(
|
||||
@@ -171,10 +175,14 @@ namespace Echoion::Core
|
||||
std::string url;
|
||||
bool isLocalFile = false;
|
||||
};
|
||||
struct CmdStart {};
|
||||
struct CmdPause {};
|
||||
struct CmdResume {};
|
||||
struct CmdStop {};
|
||||
struct CmdStart {
|
||||
};
|
||||
struct CmdPause {
|
||||
};
|
||||
struct CmdResume {
|
||||
};
|
||||
struct CmdStop {
|
||||
};
|
||||
struct CmdSkip {
|
||||
uint32_t count = 1;
|
||||
};
|
||||
@@ -188,8 +196,8 @@ namespace Echoion::Core
|
||||
bool paused = false;
|
||||
};
|
||||
using Command =
|
||||
std::variant<CmdPlayNow, CmdStart, CmdPause, CmdResume,
|
||||
CmdStop, CmdSkip, CmdSeek, CmdRestore>;
|
||||
std::variant<CmdPlayNow, CmdStart, CmdPause, CmdResume, CmdStop,
|
||||
CmdSkip, CmdSeek, CmdRestore>;
|
||||
|
||||
void post(Command cmd);
|
||||
|
||||
@@ -202,10 +210,10 @@ namespace Echoion::Core
|
||||
|
||||
struct DecoderSlot {
|
||||
enum class State {
|
||||
Idle, // nothing assigned
|
||||
Idle, // nothing assigned
|
||||
Resolving, // resolveFuture in flight
|
||||
Warming, // decoder open, pre-filling its queue
|
||||
Active, // currently feeding the ring buffer
|
||||
Active, // currently feeding the ring buffer
|
||||
};
|
||||
|
||||
State state = State::Idle;
|
||||
@@ -268,7 +276,9 @@ namespace Echoion::Core
|
||||
void clearFade()
|
||||
{
|
||||
fadeTail_.clear();
|
||||
fadePos_ = 0;
|
||||
fadeTailPos_ = 0;
|
||||
fadeEnvPos_ = 0;
|
||||
fadeIncomingStarved_ = false;
|
||||
}
|
||||
// AGC gain for one chunk (updates the internal RMS/gain state).
|
||||
[[nodiscard]] float agcGainFor(std::size_t samples);
|
||||
@@ -302,8 +312,15 @@ namespace Echoion::Core
|
||||
|
||||
// Crossfade state (engine thread only): the outgoing track's
|
||||
// remaining PCM, mixed into the incoming track equal-power.
|
||||
// The tail cursor and the envelope advance independently: the
|
||||
// tail plays continuously, while the envelope only progresses as
|
||||
// incoming audio is actually delivered — so a network-starved
|
||||
// incoming stream stretches the fade instead of being chopped
|
||||
// against a racing envelope.
|
||||
std::vector<short> fadeTail_;
|
||||
std::size_t fadePos_ = 0;
|
||||
std::size_t fadeTailPos_ = 0;
|
||||
std::size_t fadeEnvPos_ = 0;
|
||||
bool fadeIncomingStarved_ = false;
|
||||
|
||||
// AGC state (engine thread only): EMA of mean-square level and
|
||||
// the current smoothed gain in dB.
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Echoion::Core
|
||||
PlaybackState playback;
|
||||
bool hasPlayback =
|
||||
false; // Flag to indicate if playback state is valid
|
||||
bool autoplay = false; // Radio mode on/off (persisted for restart)
|
||||
std::vector<QueueEntryState> queue;
|
||||
std::vector<SessionState> sessions;
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core::Util
|
||||
{
|
||||
|
||||
// Split `text` into pages no larger than `limit` bytes each, breaking on
|
||||
// line boundaries where possible and hard-splitting over-long lines on a
|
||||
// UTF-8 code-point boundary. Every returned page is <= `limit` bytes, so a
|
||||
// caller can append a short footer and still stay under the transport's
|
||||
// single-message cap. Returns a single element when `text` already fits.
|
||||
std::vector<std::string> paginate(std::string_view text, std::size_t limit);
|
||||
|
||||
} // namespace Echoion::Core::Util
|
||||
Reference in new issue
Block a user