This commit is contained in:
fluttershy 2025-01-15 13:34:41 +05:00
parent 2ba90a0861
commit bb50404ad5
15 changed files with 52 additions and 80 deletions

10
include/api.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef INCLUDE_API_H_
#define INCLUDE_API_H_
#include <api/Author.hpp>
#include <api/Message.hpp>
#include <api/Channel.hpp>
#include <api/Embed.hpp>
#include <api/Bot.hpp>
#include <api/User.hpp>
#include <api/Guild.hpp>
#endif

9
include/includes.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef INCLUDE_INCLUDES_H_
#define INCLUDE_INCLUDES_H_
#include <utils/types.hpp>
#include <utils/json.hpp>
#include <utils/logs.hpp>
#include <utils/enums.hpp>
#include <iostream>
#include <string>
#endif

5
include/net.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef INCLUDE_NET_H_
#define INCLUDE_NET_H_
#include <gateway/Websocket.hpp>
#include <tls/Network.hpp>
#endif

View File

@ -1,12 +1,8 @@
#ifndef API_AUTHOR_HPP_ #ifndef API_AUTHOR_HPP_
#define API_AUTHOR_HPP_ #define API_AUTHOR_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <api/Channel.hpp> #include <net.h>
#include <string> using std::string, std::cout, std::endl, nlohmann::json;
#include <iostream>
using std::string;
using std::cout;
using std::endl;
class Author { class Author {
private: private:
json data; json data;

View File

@ -1,12 +1,7 @@
#ifndef API_BOT_HPP_ #ifndef API_BOT_HPP_
#define API_BOT_HPP_ #define API_BOT_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <string> using std::string, std::cout, std::endl, nlohmann::json;
#include <iostream>
#include <tuple>
using std::string;
using std::cout;
using std::endl;
template<typename...Args> template<typename...Args>
class Bot { class Bot {
private: private:

View File

@ -1,14 +1,8 @@
#ifndef API_CHANNEL_HPP_ #ifndef API_CHANNEL_HPP_
#define API_CHANNEL_HPP_ #define API_CHANNEL_HPP_
#include <string> #include <includes.h>
#include <iostream> #include <net.h>
#include <tls/Network.hpp> using std::string, std::cout, std::endl, nlohmann::json;
#include <api/Author.hpp>
#include <gateway/Websocket.hpp>
#include <utils/types.hpp>
using std::string;
using std::cout;
using std::endl;
class Channel { class Channel {
private: private:
json data; json data;

View File

@ -1,11 +1,7 @@
#ifndef API_EMBED_HPP_ #ifndef API_EMBED_HPP_
#define API_EMBED_HPP_ #define API_EMBED_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <string> using std::string, std::cout, std::endl, nlohmann::json;
#include <iostream>
using std::string;
using std::cout;
using std::endl;
class EmbedBuilder { class EmbedBuilder {
private: private:
json embed = { json embed = {

View File

@ -1,12 +1,8 @@
#ifndef API_GUILD_HPP_ #ifndef API_GUILD_HPP_
#define API_GUILD_HPP_ #define API_GUILD_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <string> //#include <net.h>
#include <iostream> using std::string, std::cout, std::endl, nlohmann::json;
using std::string;
using std::cout;
using std::endl;
using json = nlohmann::json;
class Guild { class Guild {
private: private:
json data; json data;

View File

@ -1,12 +1,8 @@
#ifndef API_MESSAGE_HPP_ #ifndef API_MESSAGE_HPP_
#define API_MESSAGE_HPP_ #define API_MESSAGE_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <string> #include <net.h>
#include <tls/Network.hpp> using std::string, std::cout, std::endl, nlohmann::json;
#include <gateway/Websocket.hpp>
using std::string;
using std::cout;
using std::endl;
class Message { class Message {
private: private:
json data; json data;

View File

@ -1,14 +1,9 @@
#ifndef API_USER_HPP_ #ifndef API_USER_HPP_
#define API_USER_HPP_ #define API_USER_HPP_
#include <utils/types.hpp> #include <includes.h>
#include <string> #include <net.h>
#include <iostream>
#include <tls/Network.hpp>
#include <gateway/Websocket.hpp>
#include <vector> #include <vector>
using std::string; using std::string, std::cout, std::endl, nlohmann::json;
using std::cout;
using std::endl;
class User { class User {
private: private:
json data; json data;

View File

@ -1,15 +1,11 @@
#ifndef GATEWAY_WEBSOCKET_HPP_ #ifndef GATEWAY_WEBSOCKET_HPP_
#define GATEWAY_WEBSOCKET_HPP_ #define GATEWAY_WEBSOCKET_HPP_
#include <string> #include <includes.h>
#include <thread> #include <thread>
#include <iostream>
#include <chrono> #include <chrono>
#include <utils/types.hpp>
#include <ixwebsocket/IXNetSystem.h> #include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h> #include <ixwebsocket/IXWebSocket.h>
using json = nlohmann::json; using std::string, std::cout, std::endl, nlohmann::json;
using std::cout;
using std::endl;
using namespace std::chrono; using namespace std::chrono;
using namespace std::chrono_literals; using namespace std::chrono_literals;
class WebSocket { class WebSocket {

View File

@ -2,15 +2,12 @@
#define TLS_NETWORK_HPP_ #define TLS_NETWORK_HPP_
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <iostream> #include <includes.h>
#include <string>
#include <net/if.h> #include <net/if.h>
#include <netdb.h> #include <netdb.h>
#include <utils/types.hpp> #include <utils/types.hpp>
#include <gateway/Websocket.hpp> #include <gateway/Websocket.hpp>
using std::cout; using std::string, std::cout, std::endl, nlohmann::json;
using std::cerr;
using std::endl;
class NetworkManager { class NetworkManager {
private: private:
WebSocket& web; WebSocket& web;
@ -121,7 +118,7 @@ public:
#endif #endif
request += data; request += data;
if (SSL_write(ssl.get(), request.c_str(), request.length()) <= 0) { if (SSL_write(ssl.get(), request.c_str(), request.length()) <= 0) {
std::cerr << "Failed to send request" << std::endl; Logs::create(ERROR, NETWORK, "Failed to send request");
handleSSLInitErrors(); handleSSLInitErrors();
} }
Logs::create(INFO, NETWORK, "Request " + method + " " + path); Logs::create(INFO, NETWORK, "Request " + method + " " + path);

View File

@ -5,8 +5,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <ctime> #include <ctime>
using std::setfill; using std::setfill, std::setw;
using std::setw;
enum level { INFO, WARNING, ERROR }; enum level { INFO, WARNING, ERROR };
enum type { WEBSOCKET, NETWORK }; enum type { WEBSOCKET, NETWORK };
class Logs { class Logs {

View File

@ -6,8 +6,4 @@
#define g(x, y) (std::get<x>(y)) #define g(x, y) (std::get<x>(y))
#define ALL_INTENTS 131071 #define ALL_INTENTS 131071
#define RELEASE #define RELEASE
#include <utils/json.hpp>
#include <utils/logs.hpp>
#include <utils/enums.hpp>
using json = nlohmann::json;
#endif #endif

View File

@ -1,19 +1,11 @@
#include <api/Bot.hpp> #include <api.h>
#include <api/Channel.hpp> #include <includes.h>
#include <api/Message.hpp>
#include <api/Embed.hpp>
#include <api/Author.hpp>
#include <api/User.hpp>
#include <gateway/Websocket.hpp>
#include <tls/Network.hpp>
#include <utils/types.hpp>
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc != 3) return -1; if (argc != 3) return -1;
WebSocket* bot = &WebSocket::getInstance(argv[2], 131071); WebSocket* bot = &WebSocket::getInstance(argv[2], 131071);
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot<Message, User, Author>& msg) { bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot<Message, User, Author>& msg) {
if (!g(2, msg.net)->isBot()) { if (!g(2, msg.net)->isBot()) {
g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content()));
//cout << g(1, msg.net)->extract({ "content" }).get<string>() << endl;
} }
}); });
bot->start(); bot->start();