Skip to content

Commit

Permalink
Add :addContact command
Browse files Browse the repository at this point in the history
Allow adding (individual) contacts to the contact list.
Closes isamert#61
  • Loading branch information
exquo committed Jul 17, 2020
1 parent 4ae35c7 commit 9b073e4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scli
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ class Commands:
(['toggleNotifications', 'n'], self.toggle_notifications),
(['toggleAutohide', 'h'], self.toggle_autohide),
(['renameContact'], self.rename_contact),
(['addContact'], self.add_contact),
(['reload'], self.reload),
(['quit', 'q'], self.quit),
]
Expand Down Expand Up @@ -708,12 +709,27 @@ class Commands:
number, new_name = args.split(' ', 1)
if not is_number(number):
raise ValueError
if self.state.signal.get_contact(number) is None:
self.state.set_error(f":renameContact Error: no current contact with number {number} found")
return
except ValueError:
number = self.state.current_contact.get('number')
new_name = args

self.state.signal.rename_contact(number, new_name, lambda *i: self.reload())

def add_contact(self, args):
# :addContact +NUMBER [Contact Name]
try:
number, name = args.split(maxsplit=1)
except ValueError:
number, name = args, ""
if not is_number(number):
self.state.set_error(f':addContact "{number}": not a valid number')
return
self.state.signal.rename_contact(number, name, lambda *i: self.reload())


def reload(self):
self.state.reload()

Expand Down

0 comments on commit 9b073e4

Please sign in to comment.