This is my personal gitlab instance. Feel free to browse my stuff: https://gitlab.greeson.xyz/users/highsaltlevels/projects

Added extra check for empty giphy queries

David Greeson requested to merge empty-range-fix into master

Created by: HighSaltLevels

What/Why

Saltbot is not returning anything when giphy responds with no results for the request. Because of that, it makes it seem like Saltbot is unresponsive or degraded. This PR handles that issue and returns: Sorry, there were no gifs for that query :( instead.

What broke?

The traceback of the error is:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "/home/pi/SaltBot2.0/lib/controller.py", line 30, in on_message
    type_, resp = bot_cmd.commands[cmd](*args)
  File "/home/pi/SaltBot2.0/lib/commands.py", line 300, in gif
    idx = randint(0, giphy.num_gifs - 1) if idx == -1 else idx
  File "/usr/lib/python3.7/random.py", line 222, in randint
    return self.randrange(a, b+1)
  File "/usr/lib/python3.7/random.py", line 200, in randrange
    raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)

Since there were 0 results, there was an empty range to pick a random number from.

Merge request reports