-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.cpp
More file actions
79 lines (72 loc) · 4.02 KB
/
Copy pathbot.cpp
File metadata and controls
79 lines (72 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bot.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: idabligi <idabligi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 14:26:11 by idabligi #+# #+# */
/* Updated: 2023/11/01 15:15:32 by idabligi ### ########.fr */
/* */
/* ************************************************************************** */
#include "Server.hpp"
void Server::getDate(int fd)
{
char buff[100];
std::string time;
std::time_t now_time_s = std::time(NULL);
std::tm *localtime = std::localtime(&now_time_s);
std::strftime(buff, sizeof(buff), "%d/%m/%Y---%H:%M:%S", localtime);
time = buff;
this->sendMessage(fd, ":BOT PRIVMSG " + this->list[fd].getNick() + " :" + "[" + time + "]" + "\r\n");
}
void Server::getHelp(int fd)
{
std::string man[20] = {"||----------------------------------------------------------------------------------||",
"||--------------------------------------MANUAL--------------------------------------||",
"||----------------------------------------------------------------------------------||",
"|| ||",
"|| ∗ Set UserName : USER + (your username) ||",
"|| ∗ Set NickName : NICK + (your nickname) ||",
"|| ∗ Join a channel : JOIN + #(channel name) ||",
"|| ∗ KICK - Eject a client from the channel ||",
"|| ∗ INVITE - Invite a client to a channel ||",
"|| ∗ TOPIC - Change or view the channel topic ||",
"|| ∗ MODE - Change the channel’s mode: ||",
"|| · i: Set/remove Invite-only channel ||",
"|| · t: Set/remove the restrictions of the TOPIC command to channel operators ||",
"|| · k: Set/remove the channel key (password) ||",
"|| · o: Give/take channel operator privilege ||",
"|| · l: Set/remove the user limit to channel ||",
"||__________________________________________________________________________________||",
};
for (int i = 0; i < 17; i++)
this->sendMessage(fd, ":BOT PRIVMSG " + this->list[fd].getNick() + " :" + man[i] + "\r\n");
}
void Server::bot(int fd, std::stringstream &iss)
{
int i;
std::string str;
std::string str2;
std::string check[] = {"DATE", "HELP"};
iss >> str;
iss >> str2;
if (!iss.eof())
return (this->sendMessage (fd, "421 " + str2 + " :Unknown command\r\n"));
for (i = 0; i < 3; i++)
{
if (str == check[i])
break ;
}
switch (i)
{
case 0:
getDate(fd);
break;
case 1:
getHelp(fd);
break;
default:
this->sendMessage (fd, "421 " + str + " :Unknown command\r\n");
}
}