sparkle/libs/api/Message.hpp
2025-01-13 14:40:21 +05:00

35 lines
1.2 KiB
C++

#ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_
#include <utils/types.hpp>
#include <string>
#include <exception>
#include <iostream>
#include <tls/Network.hpp>
#include <gateway/Websocket.hpp>
using std::string;
using std::cout;
using std::endl;
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("POST", dapi + "/channels/" + id + "/messages", msg.dump());
}
string getMessages(const string& id, const string& count, const string& before = "") {
if (before.empty()) {
return req.request("GET", dapi + "/channels/" + id + "/messages?limit=" + count);
}
else {
return req.request("GET", dapi + "/channels/" + id + "/messages?before=" + before + "&limit=" + count);
}
return "pizda";
}
string deleteMessage(const string& channel_id, const string& message_id) {
return req.request("DELETE", dapi + "/channels/" + channel_id + "/messages/" + message_id);
}
};
#endif