Disallow posting to /r/all, /r/front. Use subreddit instead of name
This commit is contained in:
@@ -60,5 +60,5 @@ SUBMISSION_FILE = """
|
|||||||
# The first line will be interpreted as the title
|
# The first line will be interpreted as the title
|
||||||
# Following lines will be interpreted as the content
|
# Following lines will be interpreted as the content
|
||||||
#
|
#
|
||||||
# Posting to /r/{name}
|
# Posting to {name}
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -95,20 +95,20 @@ class SubredditPage(BasePage):
|
|||||||
def post_submission(self):
|
def post_submission(self):
|
||||||
# Abort if user isn't logged in
|
# Abort if user isn't logged in
|
||||||
if not self.reddit.is_logged_in():
|
if not self.reddit.is_logged_in():
|
||||||
show_notification(self.stdscr, ["Login to reply"])
|
show_notification(self.stdscr, ['Login to reply'])
|
||||||
return
|
return
|
||||||
|
|
||||||
name = self.content.name
|
subreddit = self.reddit.get_subreddit(self.content.name)
|
||||||
if '+' in name:
|
|
||||||
show_notification(self.stdscr, ['Can\'t post to a multireddit'])
|
|
||||||
return
|
|
||||||
|
|
||||||
name = name.strip(' /') # Strip leading and trailing backslashes
|
# Make sure it is a valid subreddit for submission
|
||||||
if name.startswith('r/'):
|
sub = str(subreddit)
|
||||||
name = name[2:]
|
if '+' in sub or sub == '/r/all' or sub == '/r/front':
|
||||||
|
message = 'Can\'t post to {0}'.format(sub)
|
||||||
|
show_notification(self.stdscr, [message])
|
||||||
|
return
|
||||||
|
|
||||||
# Open the submission window
|
# Open the submission window
|
||||||
submission_info = SUBMISSION_FILE.format(name=name)
|
submission_info = SUBMISSION_FILE.format(name=sub)
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
submission_text = open_editor(submission_info)
|
submission_text = open_editor(submission_info)
|
||||||
curses.doupdate()
|
curses.doupdate()
|
||||||
@@ -119,7 +119,7 @@ class SubredditPage(BasePage):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
title, content = submission_text.split('\n', 1)
|
title, content = submission_text.split('\n', 1)
|
||||||
self.reddit.submit(name, title, text=content)
|
self.reddit.submit(subreddit, title, text=content)
|
||||||
except praw.errors.APIException as e:
|
except praw.errors.APIException as e:
|
||||||
show_notification(self.stdscr, [e.message])
|
show_notification(self.stdscr, [e.message])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user