check if formatdata func is coroutine func
This commit is contained in:
parent
08ba995520
commit
45f519535a
29
src/utils.py
29
src/utils.py
@ -1,5 +1,6 @@
|
||||
"""A collection of utility functions that can be used in various places."""
|
||||
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import logging
|
||||
import async_timeout
|
||||
@ -137,6 +138,10 @@ class PaginationView(View):
|
||||
|
||||
@button(emoji="◀️", style=ButtonStyle.blurple)
|
||||
async def backward(self, inter: Interaction, button: Button):
|
||||
"""
|
||||
Action the backwards button.
|
||||
"""
|
||||
|
||||
self.index -= 1
|
||||
await inter.response.defer()
|
||||
self.inter = inter
|
||||
@ -144,6 +149,10 @@ class PaginationView(View):
|
||||
|
||||
@button(emoji="▶️", style=ButtonStyle.blurple)
|
||||
async def forward(self, inter: Interaction, button: Button):
|
||||
"""
|
||||
Action the forwards button.
|
||||
"""
|
||||
|
||||
self.index += 1
|
||||
await inter.response.defer()
|
||||
self.inter = inter
|
||||
@ -151,6 +160,12 @@ class PaginationView(View):
|
||||
|
||||
@button(emoji="⏭️", style=ButtonStyle.blurple)
|
||||
async def start_or_end(self, inter: Interaction, button: Button):
|
||||
"""
|
||||
Action the start and end button.
|
||||
This button becomes return to start if at end, otherwise skip to end.
|
||||
"""
|
||||
|
||||
# Determine if should skip to start or end
|
||||
if self.index <= self.maxpage // 2:
|
||||
self.index = self.maxpage
|
||||
else:
|
||||
@ -161,6 +176,10 @@ class PaginationView(View):
|
||||
await self.navigate()
|
||||
|
||||
async def navigate(self):
|
||||
"""
|
||||
Acts as an update method for the entire instance.
|
||||
"""
|
||||
|
||||
log.debug("navigating to page: %s", self.index)
|
||||
|
||||
self.update_buttons()
|
||||
@ -168,13 +187,21 @@ class PaginationView(View):
|
||||
await self.inter.edit_original_response(embed=paged_embed, view=self)
|
||||
|
||||
async def create_paged_embed(self) -> Embed:
|
||||
"""
|
||||
Returns a copy of the known embed, but with data from the current page.
|
||||
"""
|
||||
|
||||
embed = self.embed.copy()
|
||||
data, total_results = await self.getdata(self.index)
|
||||
self.maxpage = self.calc_total_pages(total_results, self.pagesize)
|
||||
|
||||
for i, item in enumerate(data):
|
||||
i = self.calc_dataitem_index(i)
|
||||
key, value = self.formatdata(i, item)
|
||||
if asyncio.iscoroutinefunction(self.formatdata):
|
||||
key, value = await self.formatdata(i, item)
|
||||
else:
|
||||
key, value = self.formatdata(i, item)
|
||||
|
||||
embed.add_field(name=key, value=value, inline=False)
|
||||
|
||||
if not total_results:
|
||||
|
Loading…
x
Reference in New Issue
Block a user