/
BotAction.cpp
68 lines (58 loc) · 1.47 KB
/
BotAction.cpp
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
#include "BotAction.h"
#include <vector>
#include <map>
#include <string>
#include <iostream>
std::string BotAction::defaultHelpText()
{
return "Sorry, help is not available for this command!";
}
void BotAction::registerSession(const gloox::JID& jid)
{
std::map<std::string, void*> a;
sessData.insert(
std::pair<std::string, std::map<std::string, void*>>(jid.bare(), a));
}
void BotAction::unregisterSession(const gloox::JID& jid)
{
if(sessionRegistered(jid))
sessData.erase(jid.bare());
}
void BotAction::deleteSessionData(user jid, std::string key)
{
if(keyExists(jid, key))
{
void* ptr = getSessionData(jid, key);
delete ptr;
ptr = 0;
sessData[jid.bare()].erase(key);
}
}
bool BotAction::keyExists(const gloox::JID& jid, std::string key)
{
std::map<std::string, void*>::iterator it;
it = sessData[jid.bare()].find(key);
return (it != sessData[jid.bare()].end());
}
void BotAction::autoSessionRegister(const gloox::JID& jid)
{
if(!sessionRegistered(jid))
{
std::cout << "New session registered" << std::endl;
registerSession(jid);
}
}
void* BotAction::getSessionData(const gloox::JID& jid, std::string key)
{
return sessData[jid.bare()][key];
}
void BotAction::setSessionData(const gloox::JID& jid, std::string key, void* val)
{
sessData[jid.bare()][key] = val;
}
bool BotAction::sessionRegistered(const gloox::JID& jid)
{
std::map<std::string, std::map<std::string, void*>>::iterator it;
it = sessData.find(jid.bare());
return (it != sessData.end());
}