From 9b073e477d0577cac12d6e48c9f69462bdec0cb1 Mon Sep 17 00:00:00 2001 From: exquo <62397152+exquo@users.noreply.github.com> Date: Wed, 15 Jul 2020 18:35:00 +0000 Subject: [PATCH] Add `:addContact` command Allow adding (individual) contacts to the contact list. Closes #61 --- scli | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scli b/scli index aa18f21..09fe516 100755 --- a/scli +++ b/scli @@ -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), ] @@ -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()