diff --git a/rtv/page.py b/rtv/page.py index d55b511..3b846da 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -251,6 +251,29 @@ class BasePage(object): else: show_notification(self.stdscr, ['Welcome {}'.format(username)]) + @BaseController.register('d') + def delete(self): + """ + Delete a submission or comment. + """ + data = self.content.get(self.nav.absolute_index) + if data['author'] == self.reddit.user.name: + prompt = 'Are you sure you want to delete this? (y/n):' + char = self.prompt_input(prompt) + if char == 'y': + try: + data['object'].delete() + show_notification(self.stdscr, ['Deleted']) + except praw.errors.APIException as e: + show_notification(self.stdscr, [e.message]) + else: + time.sleep(0.5) + self.refresh_content() + else: + show_notification(self.stdscr, ['Delete cancelled']) + else: + show_notification(self.stdscr, ['You can\'t delete this']) + def logout(self): "Prompt to log out of the user's account."