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

Commit cc4c4bb

Browse files
committed
fixed LinkButton + removed decompressing + other
1 parent 54ea3fc commit cc4c4bb

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
176176

177177
# Changelog
178178

179+
- <details>
180+
<summary>4.3.7</summary>
181+
182+
## **Changed**
183+
- SlashOption
184+
> Required is now ``True`` by default
185+
186+
## **Fixed**
187+
- `AttributeError: 'LinkButton' object has no attribute 'component_type'`
188+
189+
## **Removed**
190+
- decompressing
191+
> The lib now doesn't decompress byte data anymore, which means everything before the dpy commit `848d752` doesn't work with this lib
192+
> [message reference](https://discord.com/channels/336642139381301249/381965829857738772/879980113742143548) in discordpy discord server
193+
194+
</details>
195+
179196
- <details>
180197
<summary>4.3.6</summary>
181198

discord_ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@
4646

4747

4848
__title__ = "discord-ui"
49-
__version__ = "4.3.6"
49+
__version__ = "4.3.7"

discord_ui/client.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ def __init__(self, client, parse_method = ParseMethod.AUTO, auto_sync=True, dele
9696
Slash(client)
9797
```
9898
"""
99-
self._buffer = bytearray()
100-
self._zlib = zlib.decompressobj()
99+
# disable decompressing
100+
# self._buffer = bytearray()
101+
# self._zlib = zlib.decompressobj()
101102

102103
self.ready = False
103104
self.parse_method: int = parse_method
@@ -148,18 +149,19 @@ async def on_connect():
148149

149150
async def _on_slash_response(self, msg):
150151
if discord.__version__.startswith("2"):
151-
if isinstance(msg, bytes):
152-
try:
153-
self._buffer.extend(msg)
154-
if len(msg) < 4 or msg[-4:] != b'\x00\x00\xff\xff':
155-
return
156-
msg = self._zlib.decompress(self._buffer)
157-
msg = msg.decode('utf-8')
158-
self._buffer = bytearray()
159-
except:
160-
return
161-
if isinstance(msg, str):
162-
msg = json.loads(msg)
152+
# comment decompressing out in canse it is needed in the future for some reason
153+
# if isinstance(msg, bytes):
154+
# try:
155+
# self._buffer.extend(msg)
156+
# if len(msg) < 4 or msg[-4:] != b'\x00\x00\xff\xff':
157+
# return
158+
# msg = self._zlib.decompress(self._buffer)
159+
# msg = msg.decode('utf-8')
160+
# self._buffer = bytearray()
161+
# except:
162+
# return
163+
if isinstance(msg, str):
164+
msg = json.loads(msg)
163165

164166
if msg["t"] != "INTERACTION_CREATE":
165167
return
@@ -1268,8 +1270,9 @@ def __init__(self, client: com.Bot, override_dpy=True, auto_defer=False):
12681270
if override_dpy:
12691271
override_it()
12701272

1271-
self._buffer = bytearray()
1272-
self._zlib = zlib.decompressobj()
1273+
# disable decompressing
1274+
# self._buffer = bytearray()
1275+
# self._zlib = zlib.decompressobj()
12731276

12741277
self.auto_defer: Tuple[bool, bool] = (auto_defer, False) if isinstance(auto_defer, bool) else auto_defer
12751278
self.listening_components: Dict[str, List[ListeningComponent]] = {}
@@ -1303,14 +1306,15 @@ def remove_cog_override(*args, **kwargs):
13031306

13041307
async def _on_component_response(self, msg):
13051308
if discord.__version__.startswith("2"):
1306-
if isinstance(msg, bytes):
1307-
self._buffer.extend(msg)
1308-
1309-
if len(msg) < 4 or msg[-4:] != b'\x00\x00\xff\xff':
1310-
return
1311-
msg = self._zlib.decompress(self._buffer)
1312-
msg = msg.decode('utf-8')
1313-
self._buffer = bytearray()
1309+
# disable deecompressing
1310+
# if isinstance(msg, bytes):
1311+
# self._buffer.extend(msg)
1312+
1313+
# if len(msg) < 4 or msg[-4:] != b'\x00\x00\xff\xff':
1314+
# return
1315+
# msg = self._zlib.decompress(self._buffer)
1316+
# msg = msg.decode('utf-8')
1317+
# self._buffer = bytearray()
13141318
if isinstance(msg, str):
13151319
msg = json.loads(msg)
13161320

discord_ui/components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def to_dict(self) -> dict:
365365
payload["placeholder"] = self.placeholder
366366
return payload
367367

368-
class BaseButton():
368+
class BaseButton(Component):
369369
def __init__(self, label, color, emoji, new_line, disabled) -> None:
370370
Component.__init__(self, ComponentType.Button)
371371
if label is None and emoji is None:
@@ -555,7 +555,7 @@ def __init__(self, url, label="\u200b", emoji=None, new_line=False, disabled=Fal
555555
LinkButton("https://discord.com/", "press me (if you can)!", emoji="😀", disabled=True)
556556
```
557557
"""
558-
BaseButton.__init__(self, label, ButtonStyles.url, emoji, new_line, disabled)
558+
BaseButton.__init__(self, label, ButtonStyles.url, emoji, new_line, disabled)
559559
self._url = None
560560
self.url = url
561561

discord_ui/slash/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SlashOption():
2424
description: :class:`str`, optional
2525
1-100 character description of the command; default name
2626
required: :class:`bool`, optional
27-
If the parameter is required or optional; default False
27+
If the parameter is required or optional; default True
2828
choices: List[:class:`dict`], optional
2929
Choices for string and int types for the user to pick from; default None
3030
Choices should be formated like this: ``[{"name": "name of the choice", "value": "the real value"}, ...]``
@@ -36,7 +36,7 @@ class SlashOption():
3636
options: List[:class:`~SlashOption`]
3737
This parameter is only for subcommands to work, you shouldn't need to use that, unless you know what you're doing
3838
"""
39-
def __init__(self, argument_type, name, description=None, required=False, choices=None, options=None) -> None:
39+
def __init__(self, argument_type, name, description=None, required=True, choices=None, options=None) -> None:
4040
"""
4141
Creates a new option for a slash command
4242
@@ -49,7 +49,7 @@ def __init__(self, argument_type, name, description=None, required=False, choice
4949
self.argument_type = argument_type
5050
self.name = name
5151
self.description = _or(description, self.name)
52-
self.required = _default([], required)
52+
self.required = required
5353
self.options = _default([], options)
5454
self.choices = _default([], choices)
5555
def __repr__(self) -> str:

0 commit comments

Comments
 (0)