This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
sparkle/libs/api/Message.hpp
2025-01-20 03:09:27 +05:00

32 lines
1.3 KiB
C++

#ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_
#include <includes.h>
#include <net.h>
using std::string, std::cout, std::endl, nlohmann::json;
class Message {
private:
json data;
WebSocket& web;
NetworkManager& req;
public:
Message(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
string send(const string& id, const json& msg) {
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + id + "/messages", msg.dump());
}
string getMessages(const string& id, const string& count, const 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 "";
}
string deleteMessage(const string& channel_id, const string& message_id) {
return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id);
}
json pack(const json& pack) const {
return { pack };
}
};
#endif