Compare commits

..

No commits in common. "e5962cfdc38b5132121e35dd2a016dcf92fc1b88" and "36f2805d6025035d55b53231c4f0185ad1326783" have entirely different histories.

2 changed files with 9 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
config.yaml config.yaml
redditbot.session* redditbot.session*
redditbot.json

View File

@ -104,7 +104,7 @@ async def main():
random_post = await subreddit.random() random_post = await subreddit.random()
cpid = cpp = None cpid = cpp = None
if random_post is None: if random_post is None:
async for submission in subreddit.hot(limit=None): async for submission in subreddit.hot():
if unique_id in give_ups: if unique_id in give_ups:
return return
cpid = getattr(submission, 'crosspost_parent', None) cpid = getattr(submission, 'crosspost_parent', None)
@ -123,7 +123,7 @@ async def main():
if not (nsfw and allow_nsfw): if not (nsfw and allow_nsfw):
nsfw = cpp.over_18 nsfw = cpp.over_18
if not (spoilers and allow_spoilers): if not (spoilers and allow_spoilers):
spoilers = cpp.spoiler nsfw = cpp.spoiler
if is_self and not allow_selfposts: if is_self and not allow_selfposts:
continue continue
if nsfw and not allow_nsfw: if nsfw and not allow_nsfw:
@ -132,9 +132,6 @@ async def main():
continue continue
random_post = submission random_post = submission
break break
if random_post is None:
return
cpid = getattr(random_post, 'crosspost_parent', None) cpid = getattr(random_post, 'crosspost_parent', None)
if cpid and getattr(random_post, 'crosspost_parent_list', None): if cpid and getattr(random_post, 'crosspost_parent_list', None):
cpid = cpid[3:] cpid = cpid[3:]
@ -152,7 +149,7 @@ async def main():
if not (nsfw and allow_nsfw): if not (nsfw and allow_nsfw):
nsfw = cpp.over_18 nsfw = cpp.over_18
if not (spoilers and allow_spoilers): if not (spoilers and allow_spoilers):
spoilers = cpp.spoiler nsfw = cpp.spoiler
if is_self and not allow_selfposts: if is_self and not allow_selfposts:
continue continue
if nsfw and not allow_nsfw: if nsfw and not allow_nsfw:
@ -168,23 +165,22 @@ async def main():
while True: while True:
unique_id = time.time() unique_id = time.time()
try: try:
result = await asyncio.wait_for(_get_submission(unique_id), timeout) random_post, cpp = await asyncio.wait_for(_get_submission(unique_id), timeout)
except asyncio.TimeoutError: except asyncio.TimeoutError:
give_ups.add(unique_id) give_ups.add(unique_id)
logging.error('%s timed out', chat) logging.error('%s timed out', chat)
return for i in bot_admins:
except Exception: await client.send_message(i, f'{chat} timed out')
break
except BaseException:
give_ups.add(unique_id) give_ups.add(unique_id)
logging.exception(chat) logging.exception(chat)
for i in bot_admins: for i in bot_admins:
await client.send_message(i, f'{chat}\n{traceback.format_exc()}') await client.send_message(i, f'{chat}\n{traceback.format_exc()}')
else: else:
if not result:
return
random_post, cpp = result
try: try:
await _actual_start_post(random_post, [chat], cpp, show_nsfw_warning, show_spoilers_warning) await _actual_start_post(random_post, [chat], cpp, show_nsfw_warning, show_spoilers_warning)
except Exception: except BaseException:
logging.exception(random_post.id) logging.exception(random_post.id)
for i in bot_admins: for i in bot_admins:
await client.send_message(i, f'{random_post.id}\n{traceback.format_exc()}', parse_mode=None) await client.send_message(i, f'{random_post.id}\n{traceback.format_exc()}', parse_mode=None)