Skip to content

Commit

Permalink
0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
skrphenix committed May 15, 2022
1 parent ef1f62c commit dc6ffdf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package/btns_menus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
License: MIT
"""

__version__ = "0.2.3"
__version__ = "0.2.4"
__author__ = "P. Sai keerthan Reddy"
11 changes: 8 additions & 3 deletions package/btns_menus/builds/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import discord
import threading
import asyncio
from typing import *

from asyncio.coroutines import iscoroutinefunction
from typing import Any, Union, Callable, Optional
from discord import utils

DEFAULT_TIMEOUT: Union[int, float] = 180.0
Expand Down Expand Up @@ -138,7 +140,6 @@ async def predicate_permsChecker(interaction: discord.Interaction, method: str,
raise MissingPerms(missing_)
else:
await send_error_msg(interaction, error_msg)

if method == "is_author":
if user == context:
return True
Expand Down Expand Up @@ -167,10 +168,14 @@ def __init__(self, func: Callable):
self.args = args
self.kwargs = kwargs
self.result = None

super().__init__()

def run(self):
self.result = asyncio.run(self.func(*self.args, **self.kwargs))
if iscoroutinefunction(self.func):
self.result = asyncio.run(self.func(*self.args, **self.kwargs))
else:
self.result = self.func(*self.args, **self.kwargs)

thread = RunThread(target)
thread.start()
Expand Down
17 changes: 13 additions & 4 deletions package/btns_menus/builds/button_.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self,
url: Optional[str] = None,
emoji: Optional[Union[str, discord.Emoji, discord.PartialEmoji]] = None,
row: Optional[int] = None,
content: Optional[str] = None,
response: Optional[Union[str, discord.Embed]] = None,
rewrite: bool = False,
ephemeral: bool = False,
Expand All @@ -33,7 +34,8 @@ def __init__(self,
:param url: Onclick Redirects to the given url
:param emoji: Emoji for the Button
:param row: Places the Button in given Row
:param response: Sends the message (str, embed) in user channel
:param content: content of the message
:param response: Sends the message (str/ embed) in user channel
:param rewrite: It is used to send the message by editing the original message rather than sending a new one
:param ephemeral: It is used to send the message where it's only visible to interacted user or to all
:param delete_msg: Deletes the original message
Expand All @@ -44,6 +46,11 @@ def __init__(self,
:returns: Button
"""

if response is None:
if content is not None:
response = content
content = None

self.kwargs = {
"author": author,
"label": label,
Expand All @@ -53,6 +60,7 @@ def __init__(self,
"url": url,
"emoji": emoji,
"row": row,
"content": content,
"response": response,
"rewrite": rewrite,
"ephemeral": ephemeral,
Expand Down Expand Up @@ -281,7 +289,7 @@ def is_any_user(self, *users: Union[str, int], error_msg: Union[str, discord.Emb


class Btn(ui.Button):
def __init__(self, root: ClassVar, button: SButton):
def __init__(self, root: Callable, button: SButton):
self.root = root
self.btn = button
self.btn_args = self.btn.args
Expand Down Expand Up @@ -326,12 +334,13 @@ async def callback(self, interaction: discord.Interaction):
view_ = btn_.view()
if self.btn_args['rewrite']:
if is_embed(resp):
await interaction.message.edit(content="", embed=resp, view=view_)
await interaction.message.edit(content=self.btn_args['content'] or "", embed=resp, view=view_)
else:
await interaction.message.edit(content=resp, embed=None, view=view_)
else:
await interaction.message.edit(view=view_)
if is_embed(resp):
await interaction.response.send_message(content="", embed=resp, ephemeral=emph_)
await interaction.response.send_message(content=self.btn_args['content'] or "",
embed=resp, ephemeral=emph_)
else:
await interaction.response.send_message(content=resp, ephemeral=emph_)
22 changes: 16 additions & 6 deletions package/btns_menus/builds/menu_.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, *,
options: List[SelectOption] = None,
disabled: bool = False,
row: Optional[int] = None,
content: Optional[str] = None,
response: Optional[Union[str, discord.Embed]] = None,
rewrite: bool = False,
ephemeral: bool = False,
Expand All @@ -33,6 +34,7 @@ def __init__(self, *,
:param options: Options which are shown in DropMenu and can be selected by interacted user
:param disabled: It is used to enable/disable the DropMenu, i.e. Preventing user from using it
:param row: Places the DropMenu in given Row
:param content: content of the message
:param response: Sends the message (str, embed) in user channel
:param rewrite: It is used to send the message by editing the original message rather than sending a new one
:param ephemeral: It is used to send the message where it's only visible to interacted user or to all
Expand All @@ -43,6 +45,11 @@ def __init__(self, *,
:returns: DropMenu
"""

if response is None:
if content is not None:
response = content
content = None

self.kwargs = {
"author": author,
"custom_id": custom_id,
Expand All @@ -52,6 +59,7 @@ def __init__(self, *,
"options": options,
"disabled": disabled,
"row": row,
"content": content,
"response": response,
"rewrite": rewrite,
"ephemeral": ephemeral,
Expand All @@ -64,7 +72,7 @@ def __init__(self, *,
}

self.after_: Optional[dict] = None
self.selected_values: Optional[str, List] = None
self.selected_values: Optional[Union[str, List]] = None
self.interaction: Optional[discord.Interaction] = None

def update_one(self, details, option: str):
Expand Down Expand Up @@ -339,7 +347,7 @@ def is_any_user(self, *users: Union[str, int], error_msg: Union[str, discord.Emb


class Menu(ui.Select):
def __init__(self, root: ClassVar, menu: SDropMenu):
def __init__(self, root: Callable, menu: SDropMenu):
self.root = root
self.menu = menu
self.menu_args = menu.args
Expand Down Expand Up @@ -410,15 +418,15 @@ async def callback(self, interaction: discord.Interaction):
if is_embed(resp_):
resp_.description = SDropMenu.convert_resp(
resp_.description, self.values)
await interaction.message.edit(content=' ', embed=resp_, view=view_)
await interaction.message.edit(content=self.menu_args['content'] or '', embed=resp_, view=view_)
else:
resp_ = SDropMenu.convert_resp(resp_, self.values)
await interaction.message.edit(content=resp_, embed=None, view=view_)
else:
if is_embed(resp):
resp.description = SDropMenu.convert_resp(
resp.description, self.values)
await interaction.message.edit(content=' ', embed=resp, view=view_)
await interaction.message.edit(content=self.menu_args['content'] or '', embed=resp, view=view_)
else:
resp = SDropMenu.convert_resp(resp, self.values)
await interaction.message.edit(content=resp, embed=None, view=view_)
Expand All @@ -428,15 +436,17 @@ async def callback(self, interaction: discord.Interaction):
if is_embed(resp_):
resp_.description = SDropMenu.convert_resp(
resp_.description, self.values)
await interaction.response.send_message(embed=resp_, ephemeral=emph_)
await interaction.response.send_message(content=self.menu_args['content'], embed=resp_,
ephemeral=emph_)
else:
resp_ = SDropMenu.convert_resp(resp_, self.values)
await interaction.response.send_message(content=resp_, ephemeral=emph_)
else:
if is_embed(resp):
resp.description = SDropMenu.convert_resp(
resp.description, self.values)
await interaction.response.send_message(content=' ', embed=resp, ephemeral=emph_)
await interaction.response.send_message(content=self.menu_args['content'] or '',
embed=resp, ephemeral=emph_)
else:
resp = SDropMenu.convert_resp(resp, self.values)
await interaction.response.send_message(content=resp, ephemeral=emph_)
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import re
import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

with open("package/btns_menus/__init__.py") as f:
search_v = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE)

if search_v is not None:
version = search_v.group(1)
else:
raise RuntimeError("Error occurred while installing !\n"
"go to https://github.com/Modern-Realm/discord_btns_menus for more info ...")

setuptools.setup(
name="discord-btns-menus",
version="0.2.3",
version=version,
author="P. Sai Keerthan Reddy",
author_email="[email protected]",
description="A responsive package for Buttons, DropMenus, Combinations and Paginator",
Expand Down

0 comments on commit dc6ffdf

Please sign in to comment.