Commits

Kirill Morarenko committed 6e38955 Draft

minor tweaks

Comments (0)

Files changed (2)

include/jsonget.hpp

 			//std::cout << 4 << std::endl;
 		    }
                     else
-                        cb_(std::string("bad json: ") + reader.getFormatedErrorMessages(), root);
+                        cb_(std::string("bad json: ") + reader.getFormatedErrorMessages() + ". json: " + body, root);
                 }
             }
         private:
 		    	cb_(root.get("error", "").asString(), boost::ref(avatar_), boost::ref(root));
 		    }
 		    else
-		    	cb_(std::string("bad json: ") + reader.getFormatedErrorMessages(), boost::ref(avatar_), boost::ref(root));
+		    	cb_(std::string("bad json: ") + reader.getFormatedErrorMessages() + ". json: " + body, boost::ref(avatar_), boost::ref(root));
                 }
             }
         private:
 
 def onList(avatar, channels, error):
     print "onList error: '%s' on avatar %s. Channels: %s" % (error, avatar.name(), ", ".join("%s (%d)" % (v.name(), k) for k, v in channels.items()))
-    for name in [n for n in channels.values() if n]:
-        crg.joinChannel(avatar, name, onJoin, onChannelUpdate)
+    if not error:
+        for name in [n for n in channels.values() if n.name()]:
+            crg.joinChannel(avatar, name, onJoin, onChannelUpdate)
 
-    crg.receiveMessages(avatar, onMessage)
+        crg.receiveMessages(avatar, onMessage)
 
 g_channels = []
 def onJoin(avatar, channel, error):
-    print "on Join error: '%s', channel: %s, avatar: %s, users: %s" % (error, channel.name(), avatar.name(), ", ".join(channel.users()))
     global g_channels
     if not error:
         g_channels.append(channel)
+    else:
+        print "on Join error: '%s', channel: %s, avatar: %s, users: %s" % (error, channel.name(), avatar.name(), ", ".join(channel.users()))
+        if error.startswith("bad json"): #XXX
+            crg.joinChannel(avatar, channel, onJoin, onChannelUpdate)
     #crg.sendMessage(avatar, channel, crg.Message("тест"), onSent)
 
 def onChannelUpdate(avatar, channel):
     try:
-        print "updated channel %s, users: %s" % (channel.name(), ", ".join(channel.users()))
+        #print "updated channel %s, users: %s" % (channel.name(), ", ".join(channel.users()))
+        pass
     except:
         print traceback.format_exc()
 
 def onSent(avatar, channel, message, error):
-    print "onSent error: '%s', message: %s, channel: %s, avatar: %s" % (error, message.text(), channel.name(), avatar.name())
+    if error:
+        print "onSent error: '%s', message: %s, channel: %s, avatar: %s" % (error, message.text(), channel.name(), avatar.name())
 
 def cmdPing(avatar, channel, msg, **kwargs):
     crg.sendMessage(avatar, channel, crg.Message("pong", msg.sender() if channel.isPrivate() else ""), onSent)
             flag = "#"
 
         if chl.name() != "Викторина":
-            print "%s [%s/%s] %s: %s" % (flag, time.asctime(time.localtime(msg.time())), chl.name(), msg.sender(), msg.text())
+            print "%s [%s/%s] %s: %s" % (flag, time.asctime(time.localtime(msg.time() / 100)), chl.name(), msg.sender(), msg.text())
 
 
     except: