smacademic / project-bdf

project-bdf created by GitHub Classroom
2 stars 0 forks source link

Replies longer than Reddit's character limit are attempted to be posted #75

Closed afig closed 5 years ago

afig commented 5 years ago

Describe the bug Reddit has a limit of 10 000 characters in a comment. In some cases, the bot may reach this limit when transcribing an image that contains many characters, or when transcribing a comment with many images.

To Reproduce Steps to reproduce the behavior:

  1. Have the bot process a comment that contains an image with more than 10 000 characters (like this one)
  2. The bot crashes as a result of an API error from Reddit saying that the body of the reply is too long.

Expected behavior The bot should not attempt to post a reply that is longer than 10 000 characters. It should instead trim the comment to 10 000 characters, or split the comment up into multiple comments.

Screenshots/Logs

Traceback (most recent call last):
  File "c:\Users\afig2\.vscode\extensions\ms-python.python-2019.3.6558\pythonFiles\ptvsd_launcher.py", line 45, in <module>
    main(ptvsdArgs)
  File "c:\Users\afig2\.vscode\extensions\ms-python.python-2019.3.6558\pythonFiles\lib\python\ptvsd\__main__.py", line 391, in main
    run()
  File "c:\Users\afig2\.vscode\extensions\ms-python.python-2019.3.6558\pythonFiles\lib\python\ptvsd\__main__.py", line 272, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\afig2\Documents\GitHub\project-bdf\src\TextifyBot.py", line 177, in <module>
    processUsernameMentions(bot)
  File "c:\Users\afig2\Documents\GitHub\project-bdf\src\TextifyBot.py", line 36, in processUsernameMentions
    processMention(newMsg)
  File "c:\Users\afig2\Documents\GitHub\project-bdf\src\TextifyBot.py", line 64, in processMention
    mention.reply(arrayToString(result))
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\models\reddit\mixins\replyable.py", line 26, in reply
    return self._reddit.post(API_PATH['comment'], data=data)[0]
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\reddit.py", line 483, in post
    return self._objector.objectify(data)
  File "C:\Users\afig2\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\objector.py", line 149, in objectify
    raise APIException(*errors[0])
praw.exceptions.APIException: TOO_LONG: 'this is too long (max: 10000)' on field 'text'

Project information Noticed start of M6 during stress testing. Existed since bot started posting to Reddit.

Additional context N/A