Prevent an IndexError from occuring (#5430)

* Prevent an IndexError from occuring

If an page value is negative it doesn't properly loop around to the end.

* Update menus.py

* I'm smart 👍
This commit is contained in:
Kowlin 2022-04-16 23:05:57 +02:00 committed by GitHub
parent 22df591db2
commit 60b495091a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -155,7 +155,7 @@ async def next_page(
Function for showing next page which is suitable Function for showing next page which is suitable
for use in ``controls`` mapping that is passed to `menu()`. for use in ``controls`` mapping that is passed to `menu()`.
""" """
if page == len(pages) - 1: if page >= len(pages) - 1:
page = 0 # Loop around to the first item page = 0 # Loop around to the first item
else: else:
page = page + 1 page = page + 1
@ -175,7 +175,7 @@ async def prev_page(
Function for showing previous page which is suitable Function for showing previous page which is suitable
for use in ``controls`` mapping that is passed to `menu()`. for use in ``controls`` mapping that is passed to `menu()`.
""" """
if page == 0: if page <= 0:
page = len(pages) - 1 # Loop around to the last item page = len(pages) - 1 # Loop around to the last item
else: else:
page = page - 1 page = page - 1