2025-01-29 16:06:47 +05:00
|
|
|
#ifndef INTERFACE_MESSAGE_HPP_
|
|
|
|
#define INTERFACE_MESSAGE_HPP_
|
2025-01-25 13:22:59 +05:00
|
|
|
#include <includes.hpp>
|
2025-01-29 16:06:47 +05:00
|
|
|
#include <network.hpp>
|
2024-12-31 02:20:56 +05:00
|
|
|
class Message {
|
|
|
|
private:
|
2025-01-27 17:24:33 +05:00
|
|
|
const nlohmann::json& data;
|
2024-12-31 02:20:56 +05:00
|
|
|
WebSocket& web;
|
|
|
|
NetworkManager& req;
|
|
|
|
public:
|
2025-01-27 17:24:33 +05:00
|
|
|
Message(const nlohmann::json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
2025-01-25 11:24:56 +05:00
|
|
|
std::string send(const std::string& id, const nlohmann::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-25 11:24:56 +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-25 13:22:59 +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-25 11:24:56 +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-25 11:24:56 +05:00
|
|
|
nlohmann::json pack(const nlohmann::json& key, const std::string& value) const {
|
2025-01-25 13:22:59 +05:00
|
|
|
return { { key, value } };
|
2025-01-25 11:24:56 +05:00
|
|
|
}
|
|
|
|
struct Api {
|
2025-01-27 17:24:33 +05:00
|
|
|
const nlohmann::json& data;
|
2025-01-25 11:24:56 +05:00
|
|
|
NetworkManager& req;
|
2025-01-27 17:24:33 +05:00
|
|
|
Api(const nlohmann::json& json) : data(json), req(NetworkManager::getInstance()) {};
|
2025-01-25 11:24:56 +05:00
|
|
|
unsigned latency() const {
|
|
|
|
return req.getLatency();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
std::string str() const {
|
|
|
|
return std::string(data);
|
|
|
|
}
|
2024-12-31 02:20:56 +05:00
|
|
|
};
|
|
|
|
#endif
|