sparkle/libs/api/Message.hpp
2025-01-25 13:22:59 +05:00

41 lines
1.7 KiB
C++

#ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_
#include <includes.hpp>
#include <net.hpp>
class Message {
private:
nlohmann::json data;
WebSocket& web;
NetworkManager& req;
public:
Message(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
std::string send(const std::string& id, const nlohmann::json& msg) {
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + id + "/messages", msg.dump());
}
std::string getMessages(const std::string& id, const std::string& count, const std::string& before = "") {
if (before.empty()) {
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?limit=" + count);
} else {
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?before=" + before + "&limit=" + count);
}
return "";
}
std::string deleteMessage(const std::string& channel_id, const std::string& message_id) {
return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id);
}
nlohmann::json pack(const nlohmann::json& key, const std::string& value) const {
return { { key, value } };
}
struct Api {
nlohmann::json data;
NetworkManager& req;
Api(const nlohmann::json& json = "") : data(json), req(NetworkManager::getInstance()) {};
unsigned latency() const {
return req.getLatency();
}
};
std::string str() const {
return std::string(data);
}
};
#endif