summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-07-22 17:13:24 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-07-22 17:13:24 (GMT)
commitc3c24fd8fb8f91696b4e38e0f212a35a8e1fe137 (patch)
tree02145bdb8a0f059be43d58c3942c0050ebbae1a9 /Swiftob/Swiftob.cpp
parent053128df5c36b80c35e8ec5483125305f8fc86ea (diff)
downloadswift-contrib-c3c24fd8fb8f91696b4e38e0f212a35a8e1fe137.zip
swift-contrib-c3c24fd8fb8f91696b4e38e0f212a35a8e1fe137.tar.bz2
Allow nick changing and restart for Swiftob bots
Diffstat (limited to 'Swiftob/Swiftob.cpp')
-rw-r--r--Swiftob/Swiftob.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/Swiftob/Swiftob.cpp b/Swiftob/Swiftob.cpp
index 6f36b3d..1578e34 100644
--- a/Swiftob/Swiftob.cpp
+++ b/Swiftob/Swiftob.cpp
@@ -32,14 +32,14 @@ po::options_description Swiftob::getOptionsDescription() {
}
Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkFactories_(&eventLoop_), quitting_(false) {
- std::string path;
- path = options["path"].as<std::string>();
+ path_ = options["path"].as<std::string>();
client_ = new Swift::Client(Swift::JID(options["jid"].as<std::string>()), options["password"].as<std::string>(), &networkFactories_);
- storage_ = new Storage(boost::filesystem::path(path) / "settings.txt");
- mucs_ = new MUCs(client_, storage_);
- users_ = new Users(client_, mucs_);
- commands_ = new Commands(users_, client_, storage_, mucs_);
- lua_ = new LuaCommands(commands_, path, client_, networkFactories_.getTimerFactory(), mucs_);
+ storage_ = new Storage(boost::filesystem::path(path_) / "settings.txt");
+ mucs_ = NULL;
+ users_ = NULL;
+ commands_ = NULL;
+ lua_ = NULL;
+ init();
client_->onConnected.connect(boost::bind(&Swiftob::handleConnected, this));
client_->onDisconnected.connect(boost::bind(&Swiftob::handleDisconnected, this, _1));
client_->onMessageReceived.connect(boost::bind(&Swiftob::handleMessageReceived, this, _1));
@@ -54,6 +54,23 @@ Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkF
eventLoop_.run();
}
+void Swiftob::init() {
+ delete mucs_;
+ mucs_ = new MUCs(client_, storage_);
+ delete users_;
+ users_ = new Users(client_, mucs_);
+ delete commands_;
+ commands_ = new Commands(users_, client_, storage_, mucs_);
+ commands_->onRestartRequested.connect(boost::bind(&Swiftob::handleRestartRequested, this));
+ delete lua_;
+ lua_ = new LuaCommands(commands_, path_, client_, networkFactories_.getTimerFactory(), mucs_);
+}
+
+void Swiftob::handleRestartRequested() {
+ client_->disconnect();
+ init();
+}
+
void Swiftob::handleConnected() {
std::cout << "Connected" << std::endl;
if (options_.count("init") > 0) {}{ /* FIXME: Not ready for persistence yet*/