sparkle/libs/api/Message.hpp

32 lines
1.4 KiB
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_
2025-01-15 13:34:41 +05:00
#include <includes.h>
#include <net.h>
2024-12-31 02:20:56 +05:00
class Message {
private:
2025-01-20 16:07:42 +05:00
nlohmann::json data;
2024-12-31 02:20:56 +05:00
WebSocket& web;
NetworkManager& req;
public:
2025-01-20 16:07:42 +05:00
Message(const nlohmann::json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
std::string send(const std::string& id, const nlohmann::json& msg) {
std::cout << id << msg << std::endl;
2025-01-19 04:35:20 +05:00
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + id + "/messages", msg.dump());
2024-12-31 02:20:56 +05:00
}
2025-01-20 16:07:42 +05:00
std::string getMessages(const std::string& id, const std::string& count, const std::string& before = "") {
2025-01-13 14:40:21 +05:00
if (before.empty()) {
2025-01-19 04:35:20 +05:00
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?limit=" + count);
2025-01-13 14:40:21 +05:00
}
else {
2025-01-19 04:35:20 +05:00
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/channels/" + id + "/messages?before=" + before + "&limit=" + count);
2025-01-13 14:40:21 +05:00
}
2025-01-19 04:35:20 +05:00
return "";
2025-01-13 14:40:21 +05:00
}
2025-01-20 16:07:42 +05:00
std::string deleteMessage(const std::string& channel_id, const std::string& message_id) {
2025-01-19 04:35:20 +05:00
return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id);
2025-01-13 14:40:21 +05:00
}
2025-01-20 16:07:42 +05:00
nlohmann::json pack(const nlohmann::json& key, const std::string& value) const {
return {{ key, value }};
2025-01-20 03:09:27 +05:00
}
2024-12-31 02:20:56 +05:00
};
#endif