Compare commits

...

3 Commits

Author SHA1 Message Date
blankie e5962cfdc3
General fixes 2022-08-24 21:42:40 +07:00
blankie c0d035fcb4
Handle having zero new posts 2022-08-24 21:41:05 +07:00
blankie 83ad790162
Fix spoiler check 2022-08-24 21:37:51 +07:00
2 changed files with 14 additions and 9 deletions

1
.gitignore vendored
View File

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

View File

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