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_
#define API_AUTHOR_HPP_
#include <utils/types.hpp>
#include <api/Channel.hpp>
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
#include <includes.h>
#include <net.h>
using std::string, std::cout, std::endl, nlohmann::json;
class Author {
private:
json data;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,21 +1,13 @@
#include <api/Bot.hpp>
#include <api/Channel.hpp>
#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>
#include <api.h>
#include <includes.h>
int main(int argc, char* argv[]) {
if (argc != 3) return -1;
WebSocket* bot = &WebSocket::getInstance(argv[2], 131071);
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot<Message, User, Author>& msg) {
if (!g(2, msg.net)->isBot()) {
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();
return 0;
}
}