1 parent
d146f11f02
commit
5c036d91fb
72 files changed
+5875
-1243
No files matched your search
@@ -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."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user