Пример #1
0
 def test_start_missing_callbacks(self):
     bot = toby.Bot("", "")
     with self.assertRaises(toby.CallbackError):
         bot.start()
     bot.set_on_message = on_message
     with self.assertRaises(toby.CallbackError):
         bot.start()
Пример #2
0
 def test_not_connected_hooks_off(self):
     bot = toby.Bot("", "")
     bot.set_on_connect = on_connect
     bot.set_on_message = on_message
     with self.assertRaises(toby.ConnectionError):
         bot.hooks_off('ack')
Пример #3
0
 def test_not_connected_remove_socket(self):
     bot = toby.Bot("", "")
     bot.set_on_connect = on_connect
     bot.set_on_message = on_message
     with self.assertRaises(toby.ConnectionError):
         bot.remove_socket('targetid', 'ack')
Пример #4
0
 def test_not_connected_create_socket(self):
     bot = toby.Bot("", "")
     bot.set_on_connect = on_connect
     bot.set_on_message = on_message
     with self.assertRaises(toby.ConnectionError):
         bot.create_socket(False, 'ack')
Пример #5
0
 def test_not_connected_unfollow(self):
     bot = toby.Bot("", "")
     bot.set_on_connect = on_connect
     bot.set_on_message = on_message
     with self.assertRaises(toby.ConnectionError):
         bot.unfollow([])
Пример #6
0
 def test_not_connected_send(self):
     bot = toby.Bot("", "")
     bot.set_on_connect = on_connect
     bot.set_on_message = on_message
     with self.assertRaises(toby.ConnectionError):
         bot.send(toby.Message("asdf"))
Пример #7
0
import toby

bot = toby.Bot("python", "python")


def on_disconnect():
    print "disconnected"


def on_connect():
    print "connected"
    bot.info("info")
    #bot.create_bot("", "", "create-bot")
    #bot.create_socket(False, "create-socket")
    #bot.send(toby.Message("", {"hello":"world"}, ["toby"], "python"))
    #bot.follow(["python"])
    #bot.unfollow(["python"])


def on_message(message):
    #print "MESSAGE: " + message
    #toby.send("got your message #bot1")
    print message


bot.set_on_connect(on_connect)
bot.set_on_disconnect(on_disconnect)
bot.set_on_message(on_message)
bot.start()