diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-07-21 18:15:37 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-07-21 18:56:03 (GMT) |
commit | 12024c66fe21c62b158552abe26b1bcfa142ffe8 (patch) | |
tree | cfedc6e34b147bbb05fedfd69eeaad27bd5eadbd /Swiftob/Commands.cpp | |
parent | 2a690f23a71f5f24550df112e0544b32826655db (diff) | |
download | swift-contrib-12024c66fe21c62b158552abe26b1bcfa142ffe8.zip swift-contrib-12024c66fe21c62b158552abe26b1bcfa142ffe8.tar.bz2 |
Allowing generic message listeners for Swiftob bots
Diffstat (limited to 'Swiftob/Commands.cpp')
-rw-r--r-- | Swiftob/Commands.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Swiftob/Commands.cpp b/Swiftob/Commands.cpp index cf24196..18f9fb0 100644 --- a/Swiftob/Commands.cpp +++ b/Swiftob/Commands.cpp @@ -41,6 +41,10 @@ void Commands::registerCommand(const std::string& name, RoleList roles, const st command->onReceived.connect(callback); } +void Commands::registerListener(ListenerCallback listener) { + listeners_.push_back(listener); +} + bool Commands::hasCommand(const std::string& name) { return commands_.find(name) != commands_.end(); } @@ -57,6 +61,12 @@ bool Commands::runCommand(const std::string& name, const std::string& params, Sw return false; } +void Commands::runListeners(Swift::Message::ref message) { + foreach (ListenerCallback listener, listeners_) { + listener(message); + } +} + bool Commands::roleIn(const Users::User::Role userRole, RoleList roleList) { switch (roleList) { case Owner : return userRole == Users::User::Owner; @@ -84,6 +94,7 @@ void Commands::handleRehashCommand(const std::string& /*command*/, const std::st replyTo(message, "Rehashing now."); std::cout << "Rehashing at the behest of " << message->getFrom().toString() << std::endl; resetCommands(); + listeners_.clear(); if (rehashError_.empty()) { replyTo(message, "Rehash complete"); } else { |