-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRCBot.h
91 lines (73 loc) · 2.68 KB
/
IRCBot.h
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
#ifndef IRCBOT_H_
#define IRCBOT_H_
#include <string>
#include <list>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include "socketwrapper.h"
using namespace std;
struct BotFunctArgs
{
string buf;
string msgChannel;
string msgNick;
string trigger;
string arg;
vector<string> args;
};
class IrcBot
{
public:
IrcBot(const string &host, const int &port, const list<string> &channel, const string &nick, const string &usr, const string &owner, const string &trigger);
virtual ~IrcBot();
virtual void registerFunctions() = 0;
bool quit;
bool error;
void start();
// protected:
const string channelWhitelist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-#";
Socket net_client;
bool connected, joined;
unordered_map<string,unordered_set<string>> nicks;
list<string> channels;
string nick;
string usr;
string my_owner;
string trigger;
unordered_set<string> admins;
string nick_command;
string usr_command;
string awaiting_names;
string names_channel;
unordered_map<string,vector<string>> notes;
unordered_map<string,function<void(IrcBot*, BotFunctArgs&)>> triggerFunctions;
unordered_map<string,function<void(IrcBot*, BotFunctArgs&)>> deactivatedFunctions;
void registerFunction(const string &name, function<void(IrcBot*, BotFunctArgs&)> funct);
bool activateFunction(const string &name);
bool deactivateFunction(const string &name);
char * timeNow();
string getNick(const string &buf);
string getChannel(const string &buf);
vector<string> splitString(const string &s, const string &delimiters);
vector<string> splitString(const string &s, const string &delimiters, int n);
string getArgument(const string &buf, const string &command);
vector<string> getArguments(const string &buf, const string &command, const string &delimiters);
vector<string> getArguments(const string &buf, const string &command, const string &delimiters, int argc);
void sendData(const string &buf);
void sendAction(const string &msg, const string &channel);
void sendMessage(const string &msg, const string &msgTarget);
void sendNotice(const string &msg, const string &nick);
void msgHandle(const string &buf, const string &msgChannel, const string &msgNick);
virtual void extraHandle(const string &buf, const string &msgChannel, const string &msgNick) = 0;
bool checkWhitelist(const string &buffer, const string &charstring);
void addAdmin(const string &name);
void removeAdmin(const string &name);
bool isAdmin(const string &msgNick);
bool isMod(const string &msgNick, const string &msgChannel);
int checkChannelName(const string &channel);
int join(const string &channel);
int leave(const string &channel);
};
#endif