-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,138 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,5 @@ dmypy.json | |
/Scripts/ | ||
/pyvenv.cfg | ||
/namebazaar_bot/nb.db | ||
/memefactory_bot/mf.db | ||
/users.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenIds","type":"uint256[]"},{"name":"_data","type":"bytes"}],"name":"safeTransferFromMulti","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_registry","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_tokenId","type":"uint256"},{"indexed":false,"name":"_timestamp","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":false,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import asyncio | ||
import textwrap | ||
import uuid | ||
from typing import Callable, Coroutine, List, Optional, Sequence, TYPE_CHECKING, Union | ||
import attrs | ||
from interactions.ext.paginators import Paginator, Page | ||
from interactions import ( | ||
Embed, | ||
ComponentContext, | ||
ActionRow, | ||
Button, | ||
ButtonStyle, | ||
spread_to_rows, | ||
ComponentCommand, | ||
BaseContext, | ||
Message, | ||
MISSING, | ||
Snowflake_Type, | ||
StringSelectMenu, | ||
StringSelectOption, | ||
Color, | ||
BrandColors, | ||
) | ||
from interactions.client.utils.serializer import export_converter | ||
from interactions.models.discord.emoji import process_emoji, PartialEmoji | ||
|
||
|
||
@attrs.define(eq=False, order=False, hash=False, kw_only=False) | ||
class AsyncPage(Page): | ||
async def to_embed(self) -> Embed: | ||
"""Process the page to an embed asynchronously.""" | ||
return Embed(description=f"{self.prefix}\n{self.content}\n{self.suffix}", title=self.title) | ||
|
||
|
||
@attrs.define(eq=False, order=False, hash=False, kw_only=False) | ||
class AsyncPaginator(Paginator): | ||
async def to_dict(self) -> dict: | ||
"""Convert this paginator into a dictionary for sending asynchronously.""" | ||
page = self.pages[self.page_index] | ||
|
||
if isinstance(page, Page): | ||
page = await page.to_embed() # Await the asynchronous to_embed() function | ||
if not page.title and self.default_title: | ||
page.title = self.default_title | ||
if not page.footer: | ||
page.set_footer(f"Page {self.page_index + 1}/{len(self.pages)}") | ||
if not page.color: | ||
page.color = self.default_color | ||
|
||
return { | ||
"embeds": [page.to_dict()], # Await the asynchronous to_dict() function | ||
"components": [c.to_dict() for c in self.create_components()], | ||
# Await each component's to_dict() function | ||
} | ||
|
||
async def _on_button(self, ctx: ComponentContext, *args, **kwargs) -> Optional[Message]: | ||
if ctx.author.id != self.author_id: | ||
return ( | ||
await ctx.send(self.wrong_user_message, ephemeral=True) | ||
if self.wrong_user_message | ||
else await ctx.defer(edit_origin=True) | ||
) | ||
if self._timeout_task: | ||
self._timeout_task.ping.set() | ||
match ctx.custom_id.split("|")[1]: | ||
case "first": | ||
self.page_index = 0 | ||
case "last": | ||
self.page_index = len(self.pages) - 1 | ||
case "next": | ||
if (self.page_index + 1) < len(self.pages): | ||
self.page_index += 1 | ||
case "back": | ||
if self.page_index >= 1: | ||
self.page_index -= 1 | ||
case "select": | ||
self.page_index = int(ctx.values[0]) | ||
case "callback": | ||
if self.callback: | ||
return await self.callback(ctx) | ||
|
||
await ctx.edit_origin(**await self.to_dict()) # Await the asynchronous to_dict() function | ||
return None | ||
|
||
async def send(self, ctx: BaseContext) -> Message: | ||
""" | ||
Send this paginator. | ||
Args: | ||
ctx: The context to send this paginator with | ||
Returns: | ||
The resulting message | ||
""" | ||
self._message = await ctx.send(**await self.to_dict()) | ||
self._author_id = ctx.author.id | ||
|
||
if self.timeout_interval > 1: | ||
self._timeout_task = Timeout(self) | ||
_ = asyncio.create_task(self._timeout_task()) | ||
|
||
return self._message | ||
|
||
async def reply(self, ctx: "PrefixedContext") -> Message: | ||
""" | ||
Reply this paginator to ctx. | ||
Args: | ||
ctx: The context to reply this paginator with | ||
Returns: | ||
The resulting message | ||
""" | ||
self._message = await ctx.reply(**await self.to_dict()) | ||
self._author_id = ctx.author.id | ||
|
||
if self.timeout_interval > 1: | ||
self._timeout_task = Timeout(self) | ||
_ = asyncio.create_task(self._timeout_task()) | ||
|
||
return self._message | ||
|
||
async def update(self) -> None: | ||
""" | ||
Update the paginator to the current state. | ||
Use this if you have programmatically changed the page_index | ||
""" | ||
await self._message.edit(**await self.to_dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.