Changeset - b6c1ba543c82
[Not reviewed]
0 3 0
Jan Kaluza - 10 years ago 2015-12-28 10:44:56
jkaluza@redhat.com
Add support for .spectrum2 reconnect Slack command and show better error message when disconnected from 3rd-party network
3 files changed with 14 insertions and 4 deletions:
0 comments (0 inline, 0 general)
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -337,20 +337,29 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std::
 
		m_storageBackend->getUserSetting(m_uinfo.id, "rooms", type, rooms);
 

	
 
		std::string msg = "Spectrum 2 is configured for following channels:\\n";
 
		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<Swift::Payload>(new Swift::MUCPayload()));
 
		m_component->getFrontend()->onPresenceReceived(presence);
 
	}
 
	else if (args[1] == "help") {
 
		std::string msg;
 
		msg =  "Following commands are supported:\\n";
 
		msg += "```.spectrum2 help``` Shows this help message.\\n";
 
		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 {
 
		m_rtm->sendMessage(m_ownerChannel, "Unknown command. Use `.spectrum2 help` for help.");
 
	}
 
}
spectrum/src/frontends/slack/SlackUser.cpp
Show inline comments
 
@@ -64,13 +64,13 @@ void SlackUser::disconnectUser(const std::string &error, Swift::SpectrumErrorPay
 
	}
 
	else {
 
		m_session->sendMessageToAll("Disconnected from 3rd-party network for unknown reason.");
 
	}
 

	
 
	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<SlackUserManager *>(m_userManager)->moveTempSession(m_jid.toString(), m_session);
 
	m_session = NULL;
 
}
 

	
 

	
 
}
tests/slack_jabber/bad_password.py
Show inline comments
 
@@ -21,15 +21,16 @@ class Responder(sleekxmpp.ClientXMPP):
 
		self.tests["not_authorized"] = ["'Not Authorized' received", False]
 
		self.tests["help_received"] = ["Help received", False]
 
		self.tests["register_received"] = ["Password changed", False]
 
		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.":
 
			self.tests["register_received"][1] = True
 
		elif msg['body'] == "abc":
 
			self.tests["abc_received"][1] = True
0 comments (0 inline, 0 general)