From b6c1ba543c82f2a8e4d963ca08383ddebbdcca17 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 28 Dec 2015 10:44:56 +0100 Subject: [PATCH] Add support for .spectrum2 reconnect Slack command and show better error message when disconnected from 3rd-party network --- spectrum/src/frontends/slack/SlackSession.cpp | 11 ++++++++++- spectrum/src/frontends/slack/SlackUser.cpp | 2 +- tests/slack_jabber/bad_password.py | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/spectrum/src/frontends/slack/SlackSession.cpp b/spectrum/src/frontends/slack/SlackSession.cpp index a2a2a5a1..11a1fa7e 100644 --- a/spectrum/src/frontends/slack/SlackSession.cpp +++ b/spectrum/src/frontends/slack/SlackSession.cpp @@ -340,6 +340,14 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std:: msg += "```" + rooms + "```"; m_rtm->sendMessage(m_ownerChannel, msg); } + else if (args[1] == "reconnect") { + Swift::Presence::ref presence = Swift::Presence::create(); + presence->setFrom(Swift::JID("", m_uinfo.jid, "default")); + presence->setTo(m_component->getJID()); + presence->setType(Swift::Presence::Available); + presence->addPayload(boost::shared_ptr(new Swift::MUCPayload())); + m_component->getFrontend()->onPresenceReceived(presence); + } else if (args[1] == "help") { std::string msg; msg = "Following commands are supported:\\n"; @@ -347,7 +355,8 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std:: msg += "```.spectrum2 join.room <3rdPartyBotName> <#3rdPartyRoom> <3rdPartyServer> <#SlackChannel>``` Starts transport between 3rd-party room and Slack channel."; msg += "```.spectrum2 leave.room <#SlackChannel>``` Leaves the 3rd-party room connected with the given Slack channel."; msg += "```.spectrum2 list.rooms``` List all the transported rooms."; - msg += "```.spectrum2 register <3rdPartyNetworkAccount> <3rdPartyPassword> <#SlackChannel> Registers 3rd-party account for transportation."; + msg += "```.spectrum2 reconnect``` Reconnects to 3rd-party network manually in case of fatal error."; + msg += "```.spectrum2 register <3rdPartyNetworkAccount> <3rdPartyPassword> <#SlackChannel>``` Registers 3rd-party account for transportation."; m_rtm->sendMessage(m_ownerChannel, msg); } else { diff --git a/spectrum/src/frontends/slack/SlackUser.cpp b/spectrum/src/frontends/slack/SlackUser.cpp index 72ae306c..bfad825d 100644 --- a/spectrum/src/frontends/slack/SlackUser.cpp +++ b/spectrum/src/frontends/slack/SlackUser.cpp @@ -67,7 +67,7 @@ void SlackUser::disconnectUser(const std::string &error, Swift::SpectrumErrorPay } m_session->handleDisconnected(); - m_session->sendMessageToAll("Try using ```.spectrum2 reconnect``` to reconnect."); + m_session->sendMessageToAll("Maybe you have provided wrong 3rd-party network account information. In that case, you can use ```.spectrum2 register ...``` command again with corrected data. You can also try using ```.spectrum2 reconnect``` to reconnect."); static_cast(m_userManager)->moveTempSession(m_jid.toString(), m_session); m_session = NULL; } diff --git a/tests/slack_jabber/bad_password.py b/tests/slack_jabber/bad_password.py index 86ba3d53..1e0b82f3 100644 --- a/tests/slack_jabber/bad_password.py +++ b/tests/slack_jabber/bad_password.py @@ -24,9 +24,10 @@ class Responder(sleekxmpp.ClientXMPP): self.tests["abc_received"] = ["Test message received", False] def message(self, msg): - if msg['body'] == "Not Authorized" or msg['body'] == "Server may require plaintext authentication over an unencrypted stream": + if msg['body'] == "Not Authorized" or msg['body'] == "Server may require plaintext authentication over an unencrypted stream" + : self.tests["not_authorized"][1] = True - elif msg['body'].find("Try using") != -1: + elif msg['body'].find("try using") != -1: self.send_message(mto="spectrum2@spectrum2tests.xmpp.slack.com", mbody=".spectrum2 register client@localhost password #spectrum2_contactlist") self.tests["help_received"][1] = True elif msg['body'] == "You have successfully registered 3rd-party account. Spectrum 2 is now connecting to the 3rd-party network.":