def test_parks_direction_command(self): response = swansonbot.botResponses("!! park_directions ca redwood") shortened = response[:24] print("shortened", shortened) self.assertEquals( response, "Here's the directions to Redwood National and State Parks: Redwood National and State Parks is located in northernmost coastal California - almost on the Oregon border. The parks are about 60-miles long, with four visitor centers from north to south.\n\nWe are a six to seven-hour drive (325 miles) north of San Francisco, a six-hour drive (330 miles) south of Portland, OR and a four-hour drive (170 miles) west of Redding, CA." )
def on_new_message(data): botRes = bot.botResponses(data['message']) if botRes != "": models.addMessage(data['roomID'], data['userID'], data['message']) models.addMessage(data['roomID'], bot.botID, botRes) else: wrapped = links.getWrappedMessage(data['message']) models.addMessage(data['roomID'], data['userID'], wrapped) all_messages = models.getChatMessages(1) # print(json.dumps(all_messages, indent=4)) connectedList = list(users_connected.values()) connectedCount = len(connectedList) socketio.emit('all messages', { 'messages': all_messages, 'connected users': connectedList, 'numberOfUsers': connectedCount }, broadcast=True) print('message forwarded')
def on_logout(data): logoutID = data['userID'] user = models.getUserByID(data['userID']) name = user['username'] welcome_message = bot.botResponses( ("!! say Everyone! " + name + " is leaving, probably going back to...Eagleton.")) models.addMessage(1, bot.botID, welcome_message) if logoutID in users_connected: del users_connected[logoutID] all_messages = models.getChatMessages(1) connectedList = list(users_connected.values()) numberOfUsers = len(connectedList) socketio.emit('someone left', { 'messages': all_messages, 'connected_users': connectedList, 'numberOfUsers': numberOfUsers }, broadcast=True) socketio.emit('i left', {'isLoggedIn': 0}, room=data['userID']) leave_room(data['userID'])
def test_help_message(self): response = swansonbot.botResponses("!! help") self.assertEquals( response, "Try one of these commands: about, \n say (i'll repeat something), \n neigh, \n notknope, \n park_info [State abreviation] [name] \n park_directions [State abreviation] [name]" )
def test_not_command(self): response = swansonbot.botResponses('treat yo self') self.assertEquals(response, "")
def test_parks_command(self): response = swansonbot.botResponses("!! park_info ca redwood") shortened = response[:16] print(shortened) expected = "Here's some info" self.assertEquals(shortened, expected)
def test_knope_command(self): response = swansonbot.botResponses("!! notknope") self.assertEquals(response, "Leslie Knope 2012!")
def test_ls_command(self): response = swansonbot.botResponses("!! neigh") self.assertEquals( response, "Here's a wiki for poor lil' sebastian. <a href='http://parksandrecreation.wikia.com/wiki/Li'l_Sebastian'>Info</a>" )
def test_say_command(self): response = swansonbot.botResponses("!! say i want all the bacon") self.assertEquals(response, "i want all the bacon")
def test_unrecognized_command(self): response = swansonbot.botResponses("!! eagleton") self.assertEquals( response, "I'm not sure what you're trying to say...You must be from Eagleton." )
def on_login_complete(data): # print("inside fb login") if data['fb_user_token']: loggedInFrom = 'Facebook' response = requests.get( 'https://graph.facebook.com/v2.8/me?fields=id%2Cname%2Cpicture&access_token=' + data['fb_user_token']) json = response.json() name = json['name'] link = json['picture']['data']['url'] elif data['google_user_token']: loggedInFrom = 'Google' response = requests.get( 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' + data['google_user_token']) json = response.json() name = (json['given_name'] + " " + json['family_name']) link = json['picture'] welcome_message = bot.botResponses( ("!! say Everyone! " + name + " has finally come to the great city of Pawnee!!")) models.addMessage(1, bot.botID, welcome_message) all_messages = models.getChatMessages(1) if models.userExists(link): user = models.getUser(link) key = user['userID'] join_room(key) print("*************************user*************", user) if key not in users_connected: users_connected[key] = user connectedList = list(users_connected.values()) print("*************************connectedList*************", connectedList) print(len(connectedList)) connectedCount = len(users_connected) socketio.emit('login success', { "isLoggedIn": 1, 'loggedInFrom': loggedInFrom, 'user': user, 'messages': all_messages, 'connected_users': connectedList, 'numberOfUsers': connectedCount }, broadcast=True, room=key) else: new_user = models.addUser(name, link) nu_ = models.getUserByID(new_user.userID) key = nu_['userID'] join_room(key) print("*************************user*************", nu_) if key not in users_connected: users_connected[key] = nu_ connectedList = list(users_connected.values()) connectedCount = len(users_connected) socketio.emit('login success', { "isLoggedIn": 1, 'loggedInFrom': loggedInFrom, 'user': nu_, 'messages': all_messages, 'connected_users': connectedList, 'numberOfUsers': connectedCount }, broadcast=True, room=key)