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>
|
|
|
|
using std::string, std::cout, std::endl, nlohmann::json;
|
2024-12-31 02:20:56 +05:00
|
|
|
class Message {
|
|
|
|
private:
|
|
|
|
json data;
|
|
|
|
WebSocket& web;
|
|
|
|
NetworkManager& req;
|
|
|
|
public:
|
2025-01-13 14:40:21 +05:00
|
|
|
Message(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
2024-12-31 02:20:56 +05:00
|
|
|
string send(const string& id, const json& msg) {
|
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-13 14:40:21 +05:00
|
|
|
string getMessages(const string& id, const string& count, const string& before = "") {
|
|
|
|
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
|
|
|
}
|
|
|
|
string deleteMessage(const string& channel_id, const 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
|
|
|
}
|
2024-12-31 02:20:56 +05:00
|
|
|
};
|
|
|
|
#endif
|