Skip to content

Commit

Permalink
Merge branch 'memefactory_bot'
Browse files Browse the repository at this point in the history
  • Loading branch information
madvas committed Jul 21, 2023
2 parents 05aaab7 + 7e330b3 commit 2e41693
Show file tree
Hide file tree
Showing 9 changed files with 1,138 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ dmypy.json
/Scripts/
/pyvenv.cfg
/namebazaar_bot/nb.db
/memefactory_bot/mf.db
/users.db
1 change: 1 addition & 0 deletions abi/MemeToken.abi
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"}]
130 changes: 130 additions & 0 deletions async_paginator/async_paginator.py
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())
2 changes: 1 addition & 1 deletion db/user_address_db.py → db/user_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sqlite3

class UserAddressDB:
class UserDB:
def __init__(self, db_file):
self.db_file = db_file
self._create_tables()
Expand Down

0 comments on commit 2e41693

Please sign in to comment.