@hook.command('note', 'notes', 'todo')
def note(text, conn, nick, db, notice):
 parts = text.split()
 if ((len(parts) == 1) and text.isdigit()):
  cmd = 'get'
  args = parts
 else:
  cmd = parts[0].lower()
  args = parts[1:]
 if (cmd in ['add', 'new']):
  if (not len(args)):
   return 'No text provided!'
  note_text = ' '.join(args)
  add_note(db, conn.name, nick, note_text)
  notice('Note added!')
  return
 elif (cmd in ['del', 'delete', 'remove']):
  if (not len(args)):
   return 'No note ID provided!'
  note_id = args[0]
  n = read_note(db, conn.name, nick, note_id)
  if (not n):
   notice('#{} is not a valid note ID.'.format(note_id))
   return
  delete_note(db, conn.name, nick, note_id)
  notice('Note #{} deleted!'.format(note_id))
  return
 elif (cmd == 'clear'):
  delete_all_notes(db, conn.name, nick)
  notice('All notes deleted!')
  return
 elif (cmd == 'get'):
  if (not len(args)):
   return 'No note ID provided!'
  note_id = args[0]
  n = read_note(db, conn.name, nick, note_id)
  if (not n):
   notice('{} is not a valid note ID.'.format(nick))
   return
  text = format_note(n)
  notice(text)
  return
 elif (cmd in ['share', 'show']):
  if (not len(args)):
   return 'No note ID provided!'
  note_id = args[0]
  n = read_note(db, conn.name, nick, note_id)
  if (not n):
   notice('{} is not a valid note ID.'.format(nick))
   return
  text = format_note(n)
  return text
 elif (cmd == 'list'):
  notes = read_all_notes(db, conn.name, nick)
  if (not notes):
   notice('You have no notes.'.format(nick))
   return
  notice('All notes for {}:'.format(nick))
  for n in notes:
   text = format_note(n)
   notice(text)
 elif (cmd == 'listall'):
  notes = read_all_notes(db, conn.name, nick, show_deleted=True)
  if (not notes):
   notice('You have no notes.'.format(nick))
   return
  notice('All notes for {}:'.format(nick))
  for n in notes:
   text = format_note(n)
   notice(text)
 else:
  notice('Unknown command: {}'.format(cmd))

@ hook . command ( 'note' , 'notes' , 'todo' ) def note ( text , conn , nick , db , notice ) : parts = text . split ( ) if ( ( len ( parts ) == 1 ) and text . isdigit ( ) ) : cmd = 'get' args = parts else : cmd = parts [ 0 ] . lower ( ) args = parts [ 1 : ] if ( cmd in [ 'add' , 'new' ] ) : if ( not len ( args ) ) : return 'No text provided!' note_text = ' ' . join ( args ) add_note ( db , conn . name , nick , note_text ) notice ( 'Note added!' ) return elif ( cmd in [ 'del' , 'delete' , 'remove' ] ) : if ( not len ( args ) ) : return 'No note ID provided!' note_id = args [ 0 ] n = read_note ( db , conn . name , nick , note_id ) if ( not n ) : notice ( '#{} is not a valid note ID.' . format ( note_id ) ) return delete_note ( db , conn . name , nick , note_id ) notice ( 'Note #{} deleted!' . format ( note_id ) ) return elif ( cmd == 'clear' ) : delete_all_notes ( db , conn . name , nick ) notice ( 'All notes deleted!' ) return elif ( cmd == 'get' ) : if ( not len ( args ) ) : return 'No note ID provided!' note_id = args [ 0 ] n = read_note ( db , conn . name , nick , note_id ) if ( not n ) : notice ( '{} is not a valid note ID.' . format ( nick ) ) return text = format_note ( n ) notice ( text ) return elif ( cmd in [ 'share' , 'show' ] ) : if ( not len ( args ) ) : return 'No note ID provided!' note_id = args [ 0 ] n = read_note ( db , conn . name , nick , note_id ) if ( not n ) : notice ( '{} is not a valid note ID.' . format ( nick ) ) return text = format_note ( n ) return text elif ( cmd == 'list' ) : notes = read_all_notes ( db , conn . name , nick ) if ( not notes ) : notice ( 'You have no notes.' . format ( nick ) ) return notice ( 'All notes for {}:' . format ( nick ) ) for n in notes : text = format_note ( n ) notice ( text ) elif ( cmd == 'listall' ) : notes = read_all_notes ( db , conn . name , nick , show_deleted = True ) if ( not notes ) : notice ( 'You have no notes.' . format ( nick ) ) return notice ( 'All notes for {}:' . format ( nick ) ) for n in notes : text = format_note ( n ) notice ( text ) else : notice ( 'Unknown command: {}' . format ( cmd ) )
notes: restful crud controller .