Skip to content

Commit 67a08bd

Browse files
committed
2.10.1 bug fixes
1 parent 48fab02 commit 67a08bd

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

docs/source/changelog.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Changelog
55

66
.. |POTENT_BREAK_CH| replace:: **[Potentially breaking change]**
77

8+
.. |UNRELEASED| replace:: **[Not yet released]**
9+
810
------------------------
911
Info
1012
------------------------
@@ -28,9 +30,23 @@ Glossary
2830
The change could break functionality from previous versions but only if it
2931
was used in a certain way.
3032

31-
----------------------
33+
|UNRELEASED|
34+
Documented changes are not yet available to use.
35+
36+
---------------------
3237
Releases
33-
----------------------
38+
---------------------
39+
40+
|UNRELEASED| v2.10.1
41+
=======================
42+
- Fixed files in DirectMESSAGE.
43+
- Fixed file paths over remote not having the full patch when returned back.
44+
- Fixed files not having full path in the logs.
45+
- Added :py:attr:`daf.dtypes.FILE.fullpath` to support the previous fix.
46+
- Fixed exception when adding messages inside AutoGUILD, when one of the cached guilds fails initialization.
47+
- Fixed serialization for :class:`discord.VoiceChannel`, which included slowmode_delay,
48+
even though the attribute doesn't exist in the VoiceChannel.
49+
3450

3551
v2.10
3652
====================

src/daf/convert.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ def import_class(path: str):
127127
},
128128
discord.Guild: {
129129
"attrs": ["name", "id"]
130+
},
131+
discord.TextChannel: {
132+
"attrs": ["name", "id", "slowmode_delay"],
133+
},
134+
discord.VoiceChannel: {
135+
"attrs": ["name", "id"],
130136
}
131137
}
132138
"""
@@ -155,12 +161,6 @@ def import_class(path: str):
155161
- "custom_decoder": A function that accepts the JSON compatible object. It must return the original Python object.
156162
"""
157163

158-
159-
for cls in {discord.TextChannel, discord.VoiceChannel}:
160-
attrs = {"attrs": ["name", "id", "slowmode_delay"]}
161-
CONVERSION_ATTRS[cls] = attrs
162-
163-
164164
# Guilds
165165
CONVERSION_ATTRS[guild.GUILD] = {
166166
"attrs": attributes.get_all_slots(guild.GUILD),

src/daf/dtypes.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
you can send using the xxxMESSAGE objects.
44
"""
55
from typing import Any, Callable, Coroutine, Union, Optional
6+
from os.path import basename
67
from typeguard import typechecked
78
import importlib.util as iu
89
import io
@@ -163,7 +164,7 @@ class FILE:
163164
ValueError
164165
The ``data`` parameter is of incorrect format.
165166
"""
166-
__slots__ = ("_filename", "_data")
167+
__slots__ = ("_filename", "_basename", "_data")
167168

168169
def __init__(self, filename: str, data: Optional[Union[bytes, str]] = None):
169170
if data is None:
@@ -174,9 +175,10 @@ def __init__(self, filename: str, data: Optional[Union[bytes, str]] = None):
174175
data = bytes.fromhex(data)
175176

176177
self._filename = filename
178+
self._basename = basename(filename)
177179
self._data = data
178180

179-
def __str__(self) -> str:
181+
def __repr__(self) -> str:
180182
return f"FILE(filename={self._filename})"
181183

182184
@property
@@ -187,6 +189,11 @@ def stream(self) -> io.BytesIO:
187189
@property
188190
def filename(self) -> str:
189191
"The name of the file"
192+
return self._basename
193+
194+
@property
195+
def fullpath(self) -> str:
196+
"The full path to the file"
190197
return self._filename
191198

192199
@property
@@ -207,7 +214,7 @@ def to_dict(self):
207214
"""
208215
return {
209216
"type:": "File",
210-
"filename": self._filename
217+
"filename": self.fullpath
211218
}
212219

213220

src/daf/guild.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
regarding the guild and also defines a USER class from the
44
_BaseGUILD class.
55
"""
6+
from contextlib import suppress
67
from typing import Any, Coroutine, Union, List, Optional, Dict, Callable
78
from typeguard import typechecked
89
from datetime import timedelta, datetime
@@ -975,7 +976,10 @@ async def add_message(self, message: Union[TextMESSAGE, VoiceMESSAGE]):
975976
"""
976977
self.messages.append(message)
977978
for guild in self.cache.values():
978-
await guild.add_message(deepcopy(message))
979+
try:
980+
await guild.add_message(deepcopy(message))
981+
except Exception:
982+
trace(f"Could not add message {message} to {guild}, cached in {self}", TraceLEVELS.WARNING)
979983

980984
def remove_message(self, message: BaseMESSAGE):
981985
"""
@@ -993,7 +997,8 @@ def remove_message(self, message: BaseMESSAGE):
993997
"""
994998
self.messages.remove(message)
995999
for guild in self.guilds:
996-
guild.remove_message(message)
1000+
with suppress(ValueError): # Guilds can remove messages themselves
1001+
guild.remove_message(message)
9971002

9981003
def _get_server(self, snowflake: Union[int, discord.Guild, discord.User, discord.Object]):
9991004
"""

src/daf/message/text_based.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def generate_log_context(self,
244244

245245
embed = embed.to_dict() if embed is not None else None
246246

247-
files = [x.filename for x in files]
247+
files = [x.fullpath for x in files]
248248
sent_data_context = {}
249249
if text is not None:
250250
sent_data_context["text"] = text
@@ -631,7 +631,7 @@ def generate_log_context(self,
631631
}
632632
"""
633633
embed = embed.to_dict() if embed is not None else None
634-
files = [x.filename for x in files]
634+
files = [x.fullpath for x in files]
635635

636636
success_context = success_context.copy() # Don't modify outside
637637
if not success_context["success"]:
@@ -759,12 +759,13 @@ async def _send_channel(self,
759759
self.previous_message = await self.dm_channel.send(
760760
text,
761761
embed=embed,
762-
files=[discord.File(fwFILE.filename) for fwFILE in files]
762+
files=[discord.File(fwFILE.stream, fwFILE.filename) for fwFILE in files]
763763
)
764764

765765
# Mode is edit and message was already send to this channel
766766
elif self.mode == "edit":
767767
await self.previous_message.edit(text, embed=embed)
768+
768769
return {"success": True}
769770

770771
except Exception as ex:

src/daf/message/voice_based.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def generate_log_context(self,
194194
"reason": str(entry["reason"])} for entry in failed_ch]
195195
return {
196196
"sent_data": {
197-
"streamed_audio": audio.to_dict()
197+
"streamed_audio": audio.fullpath
198198
},
199199
"channels": {
200200
"successful": succeeded_ch,

src/daf_gui/convert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def issubclass_noexcept(*args):
110110

111111
CONVERSION_ATTR_TO_PARAM[daf.dtypes.FILE] = {k: k for k in daf.dtypes.FILE.__init__.__annotations__}
112112
CONVERSION_ATTR_TO_PARAM[daf.dtypes.FILE]["data"] = "hex"
113+
CONVERSION_ATTR_TO_PARAM[daf.dtypes.FILE]["filename"] = "fullpath"
113114

114115

115116
if daf.sql.SQL_INSTALLED:

0 commit comments

Comments
 (0)