def processCommand(self, message, trigger, arguments): assert isinstance(message, Message.Message) assert isinstance(self._chatbot, ChatBot) arguments = arguments.strip() if len(arguments) == 0: return "Syntax: " + self.syntax if arguments.find(',') != -1: parts = arguments.split(',',1) person1 = self._chatbot.getUserUniqueId(parts[0].strip(), message.medium_alias) if person1 is None: return "Sorry, I don't know who '%s' is" % parts[0].strip() person1nick = self._chatbot.getUserNick(person1, message.medium_alias) person1_missing_str = person1nick+" is" person1_nonint = person1nick+"'s" person2 = self._chatbot.getUserUniqueId(parts[1].strip(), message.medium_alias) if person2 is None: return "Sorry, I don't know who '%s' is" % parts[1].strip() person2nick = self._chatbot.getUserNick(person2, message.medium_alias) person2_missing_str = person2nick+" is" person2_nonint = person2nick+"'s" else: person1 = self._chatbot.getUniqueIdForSender(message) if person1 is None: return "Sorry, I don't know who you are" person1nick = "you" person1_missing_str = "you are" person1_nonint = "your" person2 = self._chatbot.getUserUniqueId(arguments, message.medium_alias) if person2 is None: return "Sorry, I don't know who '%s' is" % arguments person2nick = self._chatbot.getUserNick(person2, message.medium_alias) person2_missing_str = person2nick+" is" person2_nonint = person2nick+"'s" location1 = self._chatbot.getUserLocation(person1) if location1 is None: return "Sorry, I don't know where %s. I can be taught someone's location when they use #location ZIPCODE" % person1_missing_str if not isInt(location1): return "Sorry, I can only calculate distance between zips, and %s location is '%s'" % (person1_nonint, location1) location2 = self._chatbot.getUserLocation(person2) if location2 is None: return "Sorry, I don't know where %s. I can be taught someone's location when they use #location ZIPCODE" % person2_missing_str if not isInt(location2): return "Sorry, I can only calculate distance between zips, and %s location is '%s'" % (person2_nonint, location2) distance = getZipDistance(location1, location2) if distance is None or distance < 0: return "Sorry, I don't know the distance between %s and %s" % (person1nick, person2nick) return "The distance between %s and %s is %s miles" % (person1nick, person2nick, distance)
def processCommand(self, message, trigger, arguments): assert isinstance(message, Message.Message) assert isinstance(self._chatbot, ChatBot) lookup_type = None requestor = self._chatbot.getUniqueIdForSender(message) args = arguments.strip() if args == "": requestor_location = self._chatbot.getUserLocation(requestor) if requestor_location is None: return "Sorry, I don't know where you are. Use " + self.syntax lookup_location = requestor_location lookup_type = "REQUESTOR_LOCATION" woeid = None else: lookup_location = args lookup_type = "SPECIFIED_LOCATION" user_uniqid = self._chatbot.getUserUniqueId(lookup_location, message.medium_alias) user_location = self._chatbot.getUserLocation(user_uniqid) woeid = self.getWOEID(user_location) if woeid is None: woeid = self.getWOEID(lookup_location) if woeid is None: if lookup_location != args: return "Sorry, I thought you were in '%s' but I can't seem to find that location any more. Please use #location ZIPCODE" % (lookup_location) else: return "Sorry, I don't know where/who that is" else: lookup_location = user_location lookup_type = "OTHER_USER_NAME" weather = self.getWeather(woeid) if weather is None: return "Sorry, I know who/where '%s' is, but I don't know the weather there." % lookup_location if lookup_type == "SPECIFIED_LOCATION" and isInt(lookup_location): self._chatbot.storeUserLocation(requestor, lookup_location) if lookup_type == "OTHER_USER_NAME": prefix = "Weather for %s in %s: " % (self._chatbot.getUserNick(user_uniqid, message.medium_alias), weather[0]) else: prefix = "Weather in %s: " % weather[0] return prefix + weather[1]
def processCommand(self, message, trigger, arguments): assert isinstance(message, Message.Message) assert isinstance(self._chatbot, ChatBot) requestor = self._chatbot.getUniqueIdForSender(message) if requestor is None: return "Sorry, for some reason I don't know who you are" arguments = arguments.strip() if len(arguments) == 0: location = self._chatbot.getUserLocation(requestor) if location is None: return "I don't know where you are." return "I think you're in '%s'" % location if not isInt(arguments): return "Sorry, I only learn locations that are zipcodes. Try again with your zipcode." self._chatbot.storeUserLocation(requestor, arguments) return "Ok, I've learned that you're in '%s'" % arguments