-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lithiumox-codam/epoll
Epoll and remove the unused bool return values for commands
- Loading branch information
Showing
43 changed files
with
1,283 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ | |
.cache | ||
compile_commands.json | ||
ircserv | ||
ircbot | ||
.env | ||
|
||
# Subject File | ||
subject.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "bot/include/openai-cpp"] | ||
path = bot/include/openai-cpp | ||
url = https://github.com/olrea/openai-cpp.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
NAME := ircbot | ||
NICKNAME := BOT | ||
|
||
# Directories | ||
HDR_DIR := include | ||
LIB_DIR := lib | ||
SRC_DIR := src | ||
OBJ_DIR := build | ||
|
||
# Compiler flags | ||
CC := c++ | ||
CFLAGS := -Wall -Werror -Wextra -std=c++20 -I./$(HDR_DIR) -I $(LIB_DIR) | ||
|
||
ifdef DEBUG | ||
CFLAGS += -g -fsanitize=address | ||
endif | ||
|
||
# Linker flags | ||
LDFLAGS := -lcurl | ||
|
||
# Includes | ||
HDR := $(shell find $(HDR_DIR) -name '*.hpp') | ||
|
||
# Files | ||
SRC := $(shell find $(SRC_DIR) -name '*.cpp') | ||
OBJ := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC)) | ||
|
||
# Colours | ||
GREEN := \033[32;1m | ||
YELLOW := \033[33;1m | ||
RED := \033[31;1m | ||
BOLD := \033[1m | ||
RESET := \033[0m | ||
|
||
# Rules | ||
all: ${NAME} | ||
|
||
$(NAME): $(OBJ) | ||
@ printf "%b%s%b" "$(YELLOW)$(BOLD)" "Compiling $(NICKNAME)..." "$(RESET)" | ||
@ $(CC) $(OBJ) $(LDFLAGS) -o $(NAME) | ||
@ printf "\t\t%b%s%b\n" "$(GREEN)$(BOLD)" "[OK]" "$(RESET)" | ||
|
||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(HDR) | ||
@ mkdir -p $(dir $@) | ||
@ $(CC) $(CFLAGS) -c $< -o $@ -I $(HDR_DIR) | ||
|
||
open: $(NAME) | ||
@ ./$(NAME) 8080 | ||
|
||
clean: | ||
@ echo "$(RED)$(BOLD)Cleaning $(NICKNAME)...$(RESET)" | ||
@ rm -rf $(OBJ_DIR) | ||
|
||
fclean: | ||
@ echo "$(RED)$(BOLD)Fully cleaning $(NICKNAME)...$(RESET)" | ||
@ rm -rf $(OBJ_DIR) | ||
@ rm -rf ${NAME} | ||
|
||
re: fclean ${NAME} | ||
|
||
format: | ||
@ clang-format -i $(SRC) $(HDR) | ||
|
||
run: all | ||
@ ./$(NAME) localhost 6667 | ||
|
||
bear: fclean | ||
@ bear -- make | ||
|
||
.PHONY: all clean fclean re open format run bear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
class Bot { | ||
private: | ||
string in_buffer; | ||
string out_buffer; | ||
|
||
public: | ||
Bot(); | ||
Bot &operator=(const Bot &other); | ||
Bot(const Bot &other); | ||
~Bot(); | ||
|
||
// Server functions | ||
void readFromServer(void); | ||
void sendToServer(void); | ||
void addToBuffer(const string &data); | ||
void join(void); | ||
|
||
// Bot functions | ||
void parse(void); | ||
} ; | ||
|
||
string getGPTResponse(const string &nick, const string &message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <inttypes.h> | ||
#include <sys/epoll.h> | ||
#include <array> | ||
|
||
using namespace std; | ||
|
||
#define MAXEVENTS 10 | ||
|
||
class EpollClass { | ||
private: | ||
int fd; | ||
|
||
public: | ||
EpollClass(); | ||
EpollClass &operator=(const EpollClass &other); | ||
EpollClass(const EpollClass &other); | ||
~EpollClass(); | ||
|
||
// Event list | ||
array<struct epoll_event, MAXEVENTS> events; | ||
|
||
// Functions | ||
void add(int socket_fd) const; | ||
void change(int socket_fd, uint32_t events); | ||
void remove(int socket_fd) const; | ||
void wait(); | ||
} ; |
Submodule openai-cpp
added at
9554a4
Oops, something went wrong.