Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
added python 3.6 < support
Browse files Browse the repository at this point in the history
  • Loading branch information
kuso-senpai committed Aug 31, 2021
1 parent 3f836dc commit 0bd05dc
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/

# Changelog

- <details>
<summary>4.1.0</summary>

## **Added**
- py 3.6 < support
> You should be able to use this package with python 3.6 or newer
## **Fixed**
- print
> Forgot to remove print statements💀
</details>

- <details>
<summary>4.0.4</summary>

Expand Down
2 changes: 1 addition & 1 deletion discord_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@


__title__ = "discord-ui"
__version__ = "4.0.4"
__version__ = "4.1.0"
7 changes: 5 additions & 2 deletions discord_ui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import inspect
import asyncio
import contextlib
from typing import Coroutine, Dict, List, Literal, Tuple, Union
from typing import Coroutine, Dict, List, Tuple, Union
try:
from typing import Literal
except:
from typing_extensions import Literal

logging = setup_logger(__name__)

Expand Down Expand Up @@ -1140,7 +1144,6 @@ async def _on_response(self, msg):
if data["type"] != 3:
return

print(data)
guild = None
if data.get("guild_id") is not None:
guild = cache_data(data["guild_id"], AdditionalType.GUILD, data, self._discord._connection)
Expand Down
6 changes: 5 additions & 1 deletion discord_ui/cogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import asyncio
import datetime
import inspect
from typing import Literal, Optional, Union
from typing import Optional, Union
try:
from typing import Literal
except:
from typing_extensions import Literal

class WrongListener(errors.CheckFailure):
"""Exception raised when a listening component received a component event that doesn't meet the check conditions
Expand Down
33 changes: 18 additions & 15 deletions discord_ui/receive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from discord.ext.commands import Bot
from .errors import InvalidEvent, OutOfValidRange, WrongType
from .slash.errors import AlreadyDeferred, EphemeralDeletion
from .slash.types import ContextCommand, SlashCommand, SlashPermission, SlashSubcommand
Expand All @@ -11,7 +10,11 @@
from discord.errors import HTTPException
from discord.state import ConnectionState

import typing
from typing import List, Union, Dict
try:
from typing import Literal
except:
from typing_extensions import Literal

logging = setup_logger("discord-ui")

Expand All @@ -31,7 +34,7 @@ def __init__(self, state, data, user=MISSING, message=None) -> None:
self._original_payload: dict = data

if user is not MISSING:
self.author: typing.Union[discord.Member, discord.User] = user
self.author: Union[discord.Member, discord.User] = user
"""The user who created the interaction"""
self.application_id: int = data["application_id"]
"""The ID of the bot application"""
Expand Down Expand Up @@ -59,7 +62,7 @@ def guild(self) -> discord.Guild:
"""
return self._state._get_guild(self.guild_id)
@property
def channel(self) -> typing.Union[discord.TextChannel, discord.DMChannel]:
def channel(self) -> Union[discord.TextChannel, discord.DMChannel]:
"""The channel where the interaction was created
:type: :class:`discord.TextChannel` | :class:`discord.DMChannel`
Expand Down Expand Up @@ -94,7 +97,7 @@ async def defer(self, hidden=False):

async def respond(self, content=MISSING, *, tts=False, embed=MISSING, embeds=MISSING, file=MISSING, files=MISSING, nonce=MISSING,
allowed_mentions=MISSING, mention_author=MISSING, components=MISSING, delete_after=MISSING, hidden=False,
ninja_mode=False) -> typing.Union['Message', 'EphemeralMessage']:
ninja_mode=False) -> Union['Message', 'EphemeralMessage']:
"""Responds to the interaction
Parameters
Expand Down Expand Up @@ -202,7 +205,7 @@ async def respond(self, content=MISSING, *, tts=False, embed=MISSING, embeds=MIS
return msg

async def send(self, content=None, *, tts=False, embed=MISSING, embeds=MISSING, file=MISSING, files=MISSING, nonce=MISSING,
allowed_mentions=MISSING, mention_author=MISSING, components=MISSING, hidden=False) -> typing.Union['Message', 'EphemeralMessage']:
allowed_mentions=MISSING, mention_author=MISSING, components=MISSING, hidden=False) -> Union['Message', 'EphemeralMessage']:
"""Sends a message to the interaction using a webhook
Parameters
Expand Down Expand Up @@ -272,7 +275,7 @@ def __init__(self, data, user, s, msg, client) -> None:
self._json = s.to_dict()
self.bot: Bot = client
#region selected_values
self.selected_values: typing.List[SelectOption] = []
self.selected_values: List[SelectOption] = []
"""The list of values which were selected"""
for val in data["data"]["values"]:
for x in self.options:
Expand Down Expand Up @@ -303,7 +306,7 @@ def __init__(self, client, command: SlashCommand, data, user, args = None, guild
"""The channel where the slash command was used"""
self.guild_ids = guild_ids
"""The ids of the guilds where the command is available"""
self.args: typing.Dict[str, typing.Union[str, int, bool, discord.Member, discord.TextChannel, discord.Role, float]] = args
self.args: Dict[str, Union[str, int, bool, discord.Member, discord.TextChannel, discord.Role, float]] = args
"""The options that were received"""
self.permissions: SlashPermission = guild_permissions.get(self.guild_id)
"""The permissions for the guild"""
Expand All @@ -319,9 +322,9 @@ def __init__(self, client, command: ContextCommand, data, user, param, guild_ids
ContextCommand.__init__(self, None, "EMPTY", guild_ids=guild_ids, guild_permissions=guild_permissions)
self.bot: Bot = client
self._json = command.to_dict()
self.guild_ids: typing.List[int] = guild_ids
self.guild_ids: List[int] = guild_ids
"""The guild_ids where the command is available"""
self.param: typing.Union[Message, discord.Member, discord.User] = param
self.param: Union[Message, discord.Member, discord.User] = param
"""The parameter that was received"""
self.permissions: SlashPermission = guild_permissions.get(self.guild_id)
"""The permissions for the guild"""
Expand Down Expand Up @@ -367,7 +370,7 @@ def __init__(self, *, state, channel, data):

self._state: ConnectionState = None
super().__init__(state=state, channel=channel, data=data)
self.components: typing.List[typing.Union[Button, LinkButton, SelectMenu]] = []
self.components: List[Union[Button, LinkButton, SelectMenu]] = []
"""The components in the message
:type: List[]:class:`~Button` | :class:`~LinkButton` | :class:`SelectMenu`]
Expand All @@ -377,7 +380,7 @@ def __init__(self, *, state, channel, data):

# region attributes
@property
def buttons(self) -> typing.List[typing.Union[Button, LinkButton]]:
def buttons(self) -> List[Union[Button, LinkButton]]:
"""The button components in the message
:type: List[:class:`~Button` | :class:`~LinkButton`]
Expand All @@ -386,7 +389,7 @@ def buttons(self) -> typing.List[typing.Union[Button, LinkButton]]:
return [x for x in self.components if type(x) in [Button, LinkButton]]
return []
@property
def select_menus(self) -> typing.List[SelectMenu]:
def select_menus(self) -> List[SelectMenu]:
"""The select menus components in the message
:type: List[:class:`~SelectMenu`]
Expand Down Expand Up @@ -514,7 +517,7 @@ def action_rows(self):
:type: List[:class:`~Button` | :class:`LinkButton` | :class:`SelectMenu`]
"""
rows: typing.List[typing.List[typing.Union[Button, LinkButton, SelectMenu]]] = []
rows: List[List[Union[Button, LinkButton, SelectMenu]]] = []

c_row = []
i = 0
Expand All @@ -528,7 +531,7 @@ def action_rows(self):
rows.append(c_row)
return rows

async def wait_for(self, event_name: typing.Literal["select", "button"], client, custom_id=MISSING, by=MISSING, check=lambda component: True, timeout=None) -> typing.Union[PressedButton, SelectedMenu]:
async def wait_for(self, event_name: Literal["select", "button"], client, custom_id=MISSING, by=MISSING, check=lambda component: True, timeout=None) -> Union[PressedButton, SelectedMenu]:
"""Waits for a message component to be invoked in this message
Parameters
Expand Down
1 change: 0 additions & 1 deletion discord_ui/slash/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ def name(self) -> str:
return self._json["name"]
@name.setter
def name(self, value):
print(value)
if value in [None, MISSING]:
raise InvalidArgument("You have to specify a name")
if type(value) is not str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_readme():
long_description_content_type="text/markdown",
url="https://github.com/discord-py-ui/discord-ui",
packages=setuptools.find_packages(),
python_requires='>=3.9' if 'READTHEDOCS' not in os.environ else None,
python_requires='>=3.6',
classifiers=[
"Programming Language :: Python :: 3"
]
Expand Down

0 comments on commit 0bd05dc

Please sign in to comment.