Skip to content

Commit

Permalink
Fixed Utility Cog error (Issue #161). Resolved issue with ListPaginat…
Browse files Browse the repository at this point in the history
…or constructor being updated with a footer arg but the calls to ListPaginator within utility.py not containing new arg. Moved footer creation to within ListPaginator and added footer_icon as an arg so different icons can be passed.
  • Loading branch information
DSSzymanski committed Oct 20, 2021
1 parent 556b825 commit a6973a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 1 addition & 3 deletions bot/cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ async def google(self, ctx, *, query):
page_embed.url = result.url

page_embed.set_thumbnail(url=result.image_url)
# TODO should be handled by paginator..
page_embed.set_footer(text=f"Page {page_number}/{len(results)}", icon_url=google_icon)

page_list.append(page_embed)
page_number += 1

paginator = ListPaginator(ctx, page_list)
paginator = ListPaginator(ctx, page_list, footer_icon=google_icon)
await paginator.start()

@commands.command(aliases=["sof", "stack"])
Expand Down
14 changes: 10 additions & 4 deletions bot/utils/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from asyncio import TimeoutError

from discord.abc import Messageable
from discord import ClientUser, User, Member, HTTPException
from discord import ClientUser, User, Member, HTTPException, Embed
from discord.ext import commands

from bot.utils.embed_handler import info
Expand Down Expand Up @@ -224,19 +224,25 @@ async def update_message(self):
class ListPaginator:
"""Constructs a Paginator when provided a list of Embeds/Messages"""
def __init__(
self, ctx: commands.Context, page_list, footer,
self, ctx: commands.Context, page_list,
footer: bool = True,
footer_icon=Embed.Empty,
restart_button="⏮",
back_button="◀",
forward_button="⏭",
next_button="▶",
pause_button="⏸",
stop_button="⏹"
):
"""
:param footer: bool if paginator footer to be included.
:param footer_icon: string url for icon used in footer.
"""
self.pages = page_list
self.ctx = ctx
self.bot = ctx.bot
self.footer = footer

self.footer_icon = footer_icon
self.restart_button = restart_button
self.back_button = back_button
self.pause_button = pause_button
Expand Down Expand Up @@ -270,7 +276,7 @@ async def start(self):

if self.footer:
for index, page in enumerate(pages):
page.set_footer(text=f"Page {index+1}/{len(pages)}")
page.set_footer(text=f"Page {index+1}/{len(pages)}", icon_url=self.footer_icon)

embed = pages[0]

Expand Down

0 comments on commit a6973a6

Please sign in to comment.