@@ -24,10 +24,13 @@ void ThreeDSDiscordClient::onServer(SleepyDiscord::Server server) {
2424 addServer (server);
2525}
2626
27- void ThreeDSDiscordClient::switchServer () {
27+ void ThreeDSDiscordClient::switchServer (int displacement ) {
2828 if (servers.size () == 0 ) return ;
2929 // change current server
30- if (servers.size () <= ++currentServerHandle)
30+ currentServerHandle += displacement;
31+ if (100 < currentServerHandle)
32+ currentServerHandle = servers.size () - 1 ;
33+ else if (servers.size () <= currentServerHandle)
3134 currentServerHandle = 0 ;
3235 isCurrentChannelHandleValid = false ;
3336 printf (" Switched Server to %s.\n " , getCurrentServer ().name .c_str ());
@@ -69,15 +72,15 @@ void ThreeDSDiscordClient::switchChannel() {
6972}
7073
7174void ThreeDSDiscordClient::loadMessages () {
72- if (servers.size () == 0 ) return ;
75+ if (servers.size () == 0 || isCurrentChannelHandleValid == false ) return ;
7376 std::vector<SleepyDiscord::Message> messages = getMessages (getCurrentChannel ().id , limit, " " , 8 );
7477 for (std::vector<SleepyDiscord::Message>::reverse_iterator i = messages.rbegin (), end = messages.rend (); i != end; ++i) {
7578 addNewMessage (*i);
7679 }
7780}
7881
7982void ThreeDSDiscordClient::launchKeyboardAndSentMessage () {
80- if (servers.size () == 0 ) return ;
83+ if (servers.size () == 0 || isCurrentChannelHandleValid == false ) return ;
8184 // tell discord that we are typing
8285 if (sendTyping (getCurrentChannel ().id ) == false ) // error check
8386 return ;
@@ -114,8 +117,9 @@ void ThreeDSDiscordClient::launchKeyboardAndSentMessage() {
114117
115118void ThreeDSDiscordClient::onReady (std::string * jsonMessage) {
116119 printf (" ready\n " );
117- if (! isBot ()) {
120+ if (isBot () == false && servers. size () == 0 ) {
118121 std::vector<SleepyDiscord::Server> servers = getServers ();
122+ // you should some error checking here
119123 for (SleepyDiscord::Server server : servers) {
120124 addServer (server);
121125 }
0 commit comments