def _forget(text): ''' Forget Takes the text argument and attempts to delete any known references to it. -- @param text:str The key @return string ''' # Check if we don't already have this value try: key = LearnKey.get(LearnKey.name == text) key.delete_instance(recursive=True) return 'Ok, I have forgotten everything I know about \'{k}\''.format( k=text) except LearnKey.DoesNotExist: pass return 'I dont know anything about {k}'.format(k=text)
def _learn (text): ''' Learn Takes text, splits it on the first 'as' word and treats the 2 strings as k, v for storage. -- @param text:str The message with the k, v pair @return string ''' # k, v is split by the 'as' keyword request_key = text.split('as', 1)[0].strip() request_value = text.split('as', 1)[1].strip() # the key 'all' is reserved if request_key == 'all': return 'The key \'all\' is reserved. Please choose another' # Check if we don't already have this value try: values = LearnValue.select().join(LearnKey).where(LearnValue.value == request_value).get() # Return that we already know about this. return 'I already know about \'{value}\'. Checkout \'/show {key}\''.format( value = request_value, key = values.name.name ) except LearnValue.DoesNotExist: pass # Get or create the key if it does not already exist try: key = LearnKey.create(name = request_key) except peewee.IntegrityError: key = LearnKey.get(LearnKey.name == request_key) # Prepare the value, and save it with the key LearnValue.create( name = key, value = request_value ) return 'Ok, learnt that {k} is :{v}'.format( k = request_key, v = request_value )
def _learn(text): ''' Learn Takes text, splits it on the first 'as' word and treats the 2 strings as k, v for storage. -- @param text:str The message with the k, v pair @return string ''' # k, v is split by the 'as' keyword request_key = text.split('as', 1)[0].strip() request_value = text.split('as', 1)[1].strip() # the key 'all' is reserved if request_key == 'all': return 'The key \'all\' is reserved. Please choose another' # Check if we don't already have this value try: values = LearnValue.select().join(LearnKey).where( LearnValue.value == request_value).get() # Return that we already know about this. return 'I already know about \'{value}\'. Checkout \'/show {key}\''.format( value=request_value, key=values.name.name) except LearnValue.DoesNotExist: pass # Get or create the key if it does not already exist try: key = LearnKey.create(name=request_key) except peewee.IntegrityError: key = LearnKey.get(LearnKey.name == request_key) # Prepare the value, and save it with the key LearnValue.create(name=key, value=request_value) return 'Ok, learnt that {k} is :{v}'.format(k=request_key, v=request_value)
def _forget (text): ''' Forget Takes the text argument and attempts to delete any known references to it. -- @param text:str The key @return string ''' # Check if we don't already have this value try: key = LearnKey.get(LearnKey.name == text) key.delete_instance(recursive = True) return 'Ok, I have forgotten everything I know about \'{k}\''.format(k = text) except LearnKey.DoesNotExist: pass return 'I dont know anything about {k}'.format(k = text)
# Return that we already know about this. return 'I already know about \'{value}\'. Checkout \'/show {key}\''.format( value = request_value, key = values.name.name ) except LearnValue.DoesNotExist, e: pass # Get or create the key if it does not already exist try: key = LearnKey.create(name = request_key) except peewee.IntegrityError: key = LearnKey.get(LearnKey.name == request_key) # Prepare the value, and save it with the key stored_value = LearnValue.create( name = key, value = request_value ) return 'Ok, learnt that {k} is :{v}'.format( k = request_key, v = request_value ) def _forget(text): ''' Forget