diff options
Diffstat (limited to 'Swiftob/Commands.cpp')
-rw-r--r-- | Swiftob/Commands.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Swiftob/Commands.cpp b/Swiftob/Commands.cpp index 4e31212..9212aaf 100644 --- a/Swiftob/Commands.cpp +++ b/Swiftob/Commands.cpp @@ -1,43 +1,44 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiftob/Commands.h> -#include <Swiften/Base/foreach.h> #include <iostream> -#include <boost/bind.hpp> + #include <boost/algorithm/string.hpp> +#include <boost/bind.hpp> +#include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> typedef std::pair<std::string, Commands::Command*> NamedCommand; Commands::Commands(Users* users, Swift::Client* client, Storage* storage, MUCs* mucs) { users_ = users; client_ = client; mucs_ = mucs; storage_ = storage; resetCommands(); } Commands::~Commands() { clearCommands(); } void Commands::clearCommands() { foreach (NamedCommand command, commands_) { delete command.second; } commands_.clear(); } void Commands::resetCommands() { clearCommands(); registerCommand("quit", Owner, "Quit the bot", boost::bind(&Commands::handleQuitCommand, this, _1, _2, _3)); registerCommand("help", Anyone, "Get help", boost::bind(&Commands::handleHelpCommand, this, _1, _2, _3)); registerCommand("join", Owner, "Join a MUC", boost::bind(&Commands::handleJoinCommand, this, _1, _2, _3)); registerCommand("part", Owner, "Leave a MUC", boost::bind(&Commands::handlePartCommand, this, _1, _2, _3)); @@ -184,33 +185,33 @@ void Commands::handleHelpCommand(const std::string& /*command*/, const std::stri std::string result("Available commands:"); std::string bang = message->getType() == Swift::Message::Groupchat ? "\n!" : "\n"; foreach (NamedCommand pair, commands_) { if (roleIn(userRole, pair.second->getAllowedBy())) { result += bang + pair.first + " - " + pair.second->getDescription(); } } replyTo(message, result, true); } /** * \param outOfMUC Reply to the sender directly, don't spam MUCs with the reply */ void Commands::replyTo(Swift::Message::ref source, std::string replyBody, bool outOfMUC) { Swift::Message::ref reply(new Swift::Message()); Swift::Message::Type type = source->getType(); reply->setType(type); reply->setBody(type == Swift::Message::Groupchat ? source->getFrom().getResource() + ": " + replyBody : replyBody); Swift::JID to = source->getFrom(); if (type == Swift::Message::Groupchat) { if (outOfMUC) { reply->setType(Swift::Message::Chat); } else { to = to.toBare(); } } reply->setTo(to); if (client_->isAvailable()) { client_->sendMessage(reply); } else { - std::cout << "Dropping '" + reply->getBody() + "' -> " + reply->getTo().toString() + " on the floor due to missing connection." << std::endl; + std::cout << "Dropping '" + reply->getBody().get_value_or("") + "' -> " + reply->getTo().toString() + " on the floor due to missing connection." << std::endl; } } |