Skip to content

Commit 5a69a31

Browse files
authored
Merge pull request #243 from davidhozic/bug/autoobjects
Bug fixes
2 parents cf45f97 + 1bb7cde commit 5a69a31

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/daf/message/base.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
from ..logging.tracing import *
1111
from ..timing import *
1212
from .. import misc
13+
from .. import client
1314

1415
import random
1516
import re
17+
import copy
1618
import asyncio
1719
import _discord as discord
1820

21+
1922
__all__ = (
2023
"BaseMESSAGE",
2124
"AutoCHANNEL",
@@ -151,6 +154,20 @@ def __eq__(self, o: object) -> bool:
151154

152155
raise TypeError(f"Comparison of {type(self)} not allowed with {type(o)}")
153156

157+
def __deepcopy__(self, *args):
158+
"Duplicates the object (for use in AutoGUILD)"
159+
new = copy.copy(self)
160+
for slot in list(self.__slots__) + list(BaseMESSAGE.__slots__):
161+
self_val = getattr(self, slot)
162+
if isinstance(self_val, (asyncio.Semaphore, asyncio.Lock)):
163+
# Hack to copy semaphores since not all of it can be copied directly
164+
copied = type(self_val)(self_val._value)
165+
else:
166+
copied = copy.deepcopy((self_val))
167+
168+
setattr(new, slot, copied)
169+
170+
return new
154171

155172
@property
156173
def created_at(self) -> datetime:
@@ -408,10 +425,18 @@ def _process(self):
408425
stamp = datetime.now().timestamp()
409426
if stamp - self.last_scan > self.interval:
410427
self.last_scan = stamp
411-
for channel in getattr(self.parent.parent.apiobject, self.channel_getter):
428+
guild: discord.Guild = self.parent.parent.apiobject
429+
client_: discord.Client = client.get_client()
430+
member = guild.get_member(client_.user.id)
431+
if member is None:
432+
return
433+
434+
for channel in getattr(guild, self.channel_getter):
412435
if channel not in self.cache:
436+
perms = channel.permissions_for(member)
413437
name = channel.name
414-
if (re.search(self.include_pattern, name) is not None and
438+
if ((perms.send_messages or (perms.connect and perms.stream and perms.speak)) and
439+
re.search(self.include_pattern, name) is not None and
415440
(self.exclude_pattern is None or re.search(self.exclude_pattern, name) is None)
416441
):
417442
self.cache.add(channel)

src/daf/message/text_based.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ def generate_log_context(self,
233233
mode: str - The mode used to send the message (send, edit, clear-send)
234234
}
235235
"""
236+
if not (len(succeeded_ch) + len(failed_ch)):
237+
return None
236238

237239
succeeded_ch = [{"name": str(channel), "id" : channel.id} for channel in succeeded_ch]
238240
failed_ch = [{"name": str(entry["channel"]), "id" : entry["channel"].id,

src/daf/message/voice_based.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ class VoiceMESSAGE(BaseMESSAGE):
9696
"""
9797

9898
__slots__ = (
99-
"randomized_time",
10099
"period",
101100
"start_period",
102101
"end_period",
103-
"data",
104102
"volume",
105103
"channels",
106104
)
@@ -190,6 +188,8 @@ def generate_log_context(self,
190188
type: str - The type of the message, this is always VoiceMESSAGE.
191189
}
192190
"""
191+
if not (len(succeeded_ch) + len(failed_ch)):
192+
return None
193193

194194
succeeded_ch = [{"name": str(channel), "id" : channel.id} for channel in succeeded_ch]
195195
failed_ch = [{"name": str(entry["channel"]), "id" : entry["channel"].id,
@@ -347,6 +347,7 @@ async def _send(self) -> Union[dict, None]:
347347
errored_channels.append({"channel":channel, "reason": context["reason"]})
348348

349349
self._update_state(errored_channels)
350+
350351
return self.generate_log_context(**_data_to_send, succeeded_ch=succeeded_channels, failed_ch=errored_channels)
351352

352353
return None

0 commit comments

Comments
 (0)