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() # 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, e: pass
def _show(text): ''' Learn Takes the text argument and attempts to show any known references to it. -- @param text:str The key @return string ''' # Check if we have this value values = [v.value for v in LearnValue.select().join(LearnKey).where(LearnKey.name == text)] if len(values) > 0: return '\'{k}\' is: {v}'.format( k = text, v = ', '.join(values) ) return 'I have no idea what you are talking about.'
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 _show (text): ''' Learn Takes the text argument and attempts to show any known references to it. -- @param text:str The key @return string ''' # Check if we should show all the keys # that we know of if text == 'all': if (LearnKey.select().count()) <= 0: return 'I currently don\'t know anything.' response = ' I currently know about:\n\n' for k in LearnKey.select(): response += '(#{id}) {key}\n'.format( id = k.id, key = k.name) return response # Check if we have this value values = [v.value for v in LearnValue.select().join(LearnKey).where(LearnKey.name == text)] if len(values) > 0: return '\'{k}\' is: {v}'.format( k = text, v = ', '.join(values) ) return 'I have no idea what you are talking about.'
def _show(text): ''' Learn Takes the text argument and attempts to show any known references to it. -- @param text:str The key @return string ''' # Check if we should show all the keys # that we know of if text == 'all': if (LearnKey.select().count()) <= 0: return 'I currently don\'t know anything.' response = ' I currently know about:\n\n' for k in LearnKey.select(): response += '(#{id}) {key}\n'.format(id=k.id, key=k.name) return response # Check if we have this value values = [ v.value for v in LearnValue.select().join(LearnKey).where( LearnKey.name == text) ] if len(values) > 0: return '\'{k}\' is: {v}'.format(k=text, v=', '.join(values)) return 'I have no idea what you are talking about.'
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 Takes the text argument and attempts to delete any known references to it. --