Files
EchoionApi/include/echoion/api/interfaces/PluginInterface.hpp
faumaray caac928923 update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:44:29 +03:00

214 lines
7.2 KiB
C++

#pragma once
#include "PluginTypes.hpp"
#include "Types.hpp"
#include <expected>
#include <filesystem>
#include <functional>
#include <future>
#include <memory>
#include <span>
#include <string>
#include <vector>
namespace Echoion::Api
{
// Forward declarations
class IPluginInterface;
using PluginInterfacePtr = std::shared_ptr<IPluginInterface>;
// Plugin interface that the Core will use
// MINIMAL VERSION - only depends on Types.hpp and PluginTypes.hpp
// NO dependencies on TrackTypes, ConfigTypes, RpcTypes, etc.
class IPluginInterface
{
public:
virtual ~IPluginInterface() = default;
// Lifecycle
virtual Result<void> initialize() = 0;
virtual Result<void> shutdown() = 0;
// Client operations
[[nodiscard]] virtual Result<std::vector<ClientInfo>>
getClients() = 0;
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
getClient(uint64_t clientId) = 0;
// Network address of a client as reported by TeamSpeak
// (CONNECTION_CLIENT_IP). Requires the bot to hold the
// b_client_remoteaddress_view permission; hosts that cannot
// resolve the address return nullopt.
[[nodiscard]] virtual Result<std::optional<std::string>>
getClientIp(uint64_t /*clientId*/)
{
return std::optional<std::string>{};
}
// Local filesystem path of the client's avatar image as cached
// by the TeamSpeak client (getAvatar). The cache is only
// populated for clients the TS client has seen; nullopt when the
// client has no avatar or it is not (yet) downloaded.
[[nodiscard]] virtual Result<std::optional<std::string>>
getClientAvatarPath(uint64_t /*clientId*/)
{
return std::optional<std::string>{};
}
// The client's myTeamSpeak avatar URL, if set. Modern clients store
// their avatar as a public HTTPS URL (CLIENT_MYTS_AVATAR, formatted
// "<version>,<url>") rather than the legacy file-transfer avatar.
// Returns the bare URL, or nullopt when unset/legacy.
[[nodiscard]] virtual Result<std::optional<std::string>>
getClientAvatarUrl(uint64_t /*clientId*/)
{
return std::optional<std::string>{};
}
// Actively fetch a client's avatar from the server into `destDir`
// (used when it isn't in the TS client's own cache — e.g. the
// client is not in view). Returns the local path once the file is
// present; returns nullopt when the client has no avatar or the
// download was just triggered and hasn't finished yet (a later
// call returns the path). Downloads run asynchronously.
[[nodiscard]] virtual Result<std::optional<std::string>>
requestClientAvatar(uint64_t /*clientId*/,
const std::string& /*destDir*/)
{
return std::optional<std::string>{};
}
virtual Result<void> moveClient(uint64_t clientId,
uint64_t channelId) = 0;
virtual Result<void> kickClient(uint64_t clientId,
const std::string& reason) = 0;
virtual Result<void>
kickClientFromChannel(uint64_t /*clientId*/,
const std::string& /*reason*/)
{
return fail(ErrorCode::NotSupported,
"channel kick is not supported by this host");
}
virtual Result<void> banClient(uint64_t /*clientId*/,
uint64_t /*durationSeconds*/,
const std::string& /*reason*/)
{
return fail(ErrorCode::NotSupported,
"bans are not supported by this host");
}
[[nodiscard]] virtual Result<std::vector<BanInfo>> getBans()
{
return fail(ErrorCode::NotSupported,
"ban listing is not supported by this host");
}
virtual Result<void> unban(uint64_t /*banId*/)
{
return fail(ErrorCode::NotSupported,
"unban is not supported by this host");
}
// Channel operations
[[nodiscard]] virtual Result<std::vector<ChannelInfo>>
getChannels() const = 0;
[[nodiscard]] virtual Result<std::optional<ChannelInfo>>
getChannel(uint64_t channelId) const = 0;
virtual Result<uint64_t>
createChannel(const ChannelCreateOptions& /*options*/)
{
return fail(ErrorCode::NotSupported,
"channel creation is not supported by this host");
}
virtual Result<void>
editChannel(uint64_t /*channelId*/,
const ChannelEditOptions& /*options*/)
{
return fail(ErrorCode::NotSupported,
"channel editing is not supported by this host");
}
virtual Result<void> reorderChannel(uint64_t /*channelId*/,
uint64_t /*parentId*/,
uint64_t /*orderAfterId*/)
{
return fail(ErrorCode::NotSupported,
"channel reordering is not supported by this host");
}
virtual Result<void> deleteChannel(uint64_t /*channelId*/,
bool /*force*/)
{
return fail(ErrorCode::NotSupported,
"channel deletion is not supported by this host");
}
// Server-group administration. Membership changes use TeamSpeak's
// stable client database id, not the connection-scoped client id.
[[nodiscard]] virtual Result<std::vector<ServerGroupInfo>>
getServerGroups()
{
return fail(ErrorCode::NotSupported,
"server groups are not supported by this host");
}
virtual Result<void>
addClientToServerGroup(uint64_t /*groupId*/,
uint64_t /*clientDatabaseId*/)
{
return fail(
ErrorCode::NotSupported,
"server-group membership is not supported by this host");
}
virtual Result<void>
removeClientFromServerGroup(uint64_t /*groupId*/,
uint64_t /*clientDatabaseId*/)
{
return fail(
ErrorCode::NotSupported,
"server-group membership is not supported by this host");
}
[[nodiscard]] virtual Result<ServerInfo> getTeamSpeakServerInfo()
{
return fail(ErrorCode::NotSupported,
"server information is not supported by this host");
}
// Messaging
virtual Result<void>
sendTextMessage(uint64_t targetId,
const std::string& message) = 0;
virtual Result<void>
sendChannelMessage(uint64_t channelId,
const std::string& message) = 0;
virtual Result<void>
sendServerMessage(const std::string& message) = 0;
// Audio
virtual Result<void>
sendAudioData(const std::span<const short>& data) = 0;
virtual Result<void>
setWhisperList(const std::vector<uint64_t>& clientIds) = 0;
// Server connection
// ServerConfig is defined in PluginTypes.hpp (self-contained)
virtual Result<void>
connectToServer(const ServerConfig& config) = 0;
virtual Result<void> disconnectFromServer() = 0;
[[nodiscard]] virtual bool isConnected() const = 0;
virtual Result<void> reconnect() = 0;
// Event subscription
virtual void
registerEventCallback(const EventCallback& callback) = 0;
virtual void
unregisterEventCallback(const EventCallback& callback) = 0;
// Host-owned control plane. Keep this generic JSON operation at the
// very end of the ABI so updater/service operations can evolve
// without shifting existing vtable entries. Hosts that do not
// expose a control plane retain the previous behavior through this
// default.
[[nodiscard]] virtual Result<std::string>
hostControl(const std::string& /*method*/,
const std::string& /*requestJson*/)
{
return fail(ErrorCode::NotSupported,
"host control is not supported by this host");
}
};
} // namespace Echoion::Api