-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatBot
More file actions
100 lines (96 loc) · 2.96 KB
/
Copy pathChatBot
File metadata and controls
100 lines (96 loc) · 2.96 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- c++ -*- */
///////////////////////////////////////////
// Chat Bot
// -------------------------------------
// file : ChatBot
// author : Ben Kietzman
// begin : 2018-01-12
// copyright : Ben Kietzman
// email : ben@kietzman.org
///////////////////////////////////////////
/*! \file ChatBot
* \brief ChatBot Class
*/
#ifndef _COMMON_CHAT_BOT_
#define _COMMON_CHAT_BOT_
// {{{ includes
#include <cerrno>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <netdb.h>
#include <openssl/err.h>
#include <openssl/md5.h>
#include <openssl/ssl.h>
#include <poll.h>
#include <sstream>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
#include "Json"
#include "Utility"
// }}}
extern "C++"
{
namespace common
{
// {{{ ChatBot
class ChatBot
{
private:
bool m_bConnected;
bool m_bDebug;
bool m_bQuit;
bool m_bSecure;
int m_fdSocket;
list<string> m_rooms;
list<Json *> m_messages;
string m_strBuffer[2];
string m_strUser;
void (*m_pMessage)(Json *);
SSL *m_ssl;
SSL_CTX *m_ctx;
Utility *m_pUtility;
void analyze(Json *ptMessage);
protected:
map<string, string> m_formArguments;
string m_strFormAction;
string m_strFormFooter;
string m_strFormHeader;
public:
ChatBot();
~ChatBot();
bool close(string &strError);
void close();
bool connect(const string strServer, const string strPort, const string strUser, const string strPassword, const string strName, string &strError);
void disconnect();
string form(const string strIdent, const string strForm, const string strHeader = "", const string strFooter = "");
string form(const string strIdent, const string strForm, map<string, string> arguments, const string strHeader = "", const string strFooter = "");
string ident(const string strUser);
void join(const string strRoom);
void message(const string strTarget, const string strMessage, const string strText = "");
void part(const string strRoom);
void ping();
bool process(int nTimeout, string &strError);
void putMessage(Json *ptMessage);
void putMessage(const string strFunction, Json *ptMessage = NULL);
void quit();
list<string> rooms();
void secure(const bool bSecure = true);
void setArguments(map<string, string> arguments);
void setDebug(const bool bDebug);
void setForm(const string strAction, const string strHeader = "", const string strFooter = "");
void setForm(const string strAction, map<string, string> arguments, const string strHeader = "", const string strFooter = "");
void setFormArguments(map<string, string> arguments);
void setFormFooter(const string strFooter);
void setFormHeader(const string strHeader);
void setMessage(void (*pMessage)(Json *));
};
// }}}
}
}
#endif