-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
125 lines (92 loc) · 3.9 KB
/
Copy pathmain.cpp
File metadata and controls
125 lines (92 loc) · 3.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <atomic>
#include <chrono>
#include <list>
#include <signal.h>
#include <string>
#include <boost/make_shared.hpp>
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
#include "CommandHandler.hpp"
#include "ConfigurationManager.hpp"
#include "HighlightHandler.hpp"
#include "IrcConnector.hpp"
#include "OperationManager.hpp"
#include "PingResponder.hpp"
#include "PythonOperation.hpp"
#include "SqlConnector.hpp"
std::atomic<bool> running_s(true);
void signal_handler(int /*signal*/)
{
running_s = false;
}
int main(int argc, char ** argv) {
Py_Initialize();
signal (SIGINT, signal_handler);
signal (SIGTERM, signal_handler);
std::string const nick = "boatzzzz";
std::string const server = "irc.rizon.net";
size_t const port = 7000;
boost::shared_ptr<ircbot::SqlConnector> sqlConnector =
boost::make_shared<ircbot::SqlConnector>("/home/meatwad/.ircbot.db");
boost::shared_ptr<ircbot::IrcConnector> connector =
boost::make_shared<ircbot::IrcConnector>();
boost::shared_ptr<ircbot::ConfigurationManager> configManager =
boost::make_shared<ircbot::ConfigurationManager>(connector, sqlConnector);
boost::shared_ptr<ircbot::OperationManager> operationManager =
boost::make_shared<ircbot::OperationManager>(connector);
operationManager->addOperation(
"CommandHandler",
boost::make_shared<ircbot::CommandHandler>(
ircbot::CommandHandler(connector, sqlConnector, configManager, operationManager)));
operationManager->addOperation(
"PingResponder",
boost::make_shared<ircbot::PingResponder>(
ircbot::PingResponder(connector, sqlConnector, configManager)));
try {
boost::python::object mainModule = boost::python::import("__main__");
boost::python::object mainNamespace = mainModule.attr("__dict__");
boost::python::object derivedModule = boost::python::import("derived.pyircbot");
mainNamespace["irc_connector"] = connector;
mainNamespace["sql_connector"] = sqlConnector;
mainNamespace["config_manager"] = configManager;
boost::python::object ignored = boost::python::exec("import python \n"
"sql_recorder = python.SqlRecorder(irc_connector, sql_connector, config_manager) \n"
"h = python.HelloResponder(irc_connector, sql_connector, config_manager) \n"
"bots = python.BotResponder(irc_connector, sql_connector, config_manager) \n",
mainNamespace);
boost::shared_ptr<ircbot::PythonOperation> helloHandler =
boost::python::extract<boost::shared_ptr<ircbot::PythonOperation>>(mainNamespace["h"]);
operationManager->addOperation(
"HelloHandler",
helloHandler);
boost::shared_ptr<ircbot::PythonOperation> sqlRecorder =
boost::python::extract<boost::shared_ptr<ircbot::PythonOperation>>(mainNamespace["sql_recorder"]);
operationManager->addOperation(
"SqlRecorder",
sqlRecorder);
boost::shared_ptr<ircbot::PythonOperation> botResponder =
boost::python::extract<boost::shared_ptr<ircbot::PythonOperation>>(mainNamespace["bots"]);
operationManager->addOperation(
"BotResponder",
botResponder);
connector->connect(server, port);
operationManager->start();
configManager->configureBot();
while (running_s) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
connector->quit();
operationManager->stop();
operationManager->join();
} catch (boost::python::error_already_set const &) {
PyErr_Print();
}
}
#if 0
// TODO read in python file or something nice to initialize python variables
#include <fstream>
#include <sstream>
std::ifstream password_file("/home/meatwad/.ircbot.password");
std::stringstream password_buffer;
password_buffer << password_file.rdbuf();
#endif