|
10 | 10 | from ..logging.tracing import * |
11 | 11 | from ..timing import * |
12 | 12 | from .. import misc |
| 13 | +from .. import client |
13 | 14 |
|
14 | 15 | import random |
15 | 16 | import re |
| 17 | +import copy |
16 | 18 | import asyncio |
17 | 19 | import _discord as discord |
18 | 20 |
|
| 21 | + |
19 | 22 | __all__ = ( |
20 | 23 | "BaseMESSAGE", |
21 | 24 | "AutoCHANNEL", |
@@ -151,6 +154,20 @@ def __eq__(self, o: object) -> bool: |
151 | 154 |
|
152 | 155 | raise TypeError(f"Comparison of {type(self)} not allowed with {type(o)}") |
153 | 156 |
|
| 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 |
154 | 171 |
|
155 | 172 | @property |
156 | 173 | def created_at(self) -> datetime: |
@@ -408,10 +425,18 @@ def _process(self): |
408 | 425 | stamp = datetime.now().timestamp() |
409 | 426 | if stamp - self.last_scan > self.interval: |
410 | 427 | 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): |
412 | 435 | if channel not in self.cache: |
| 436 | + perms = channel.permissions_for(member) |
413 | 437 | 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 |
415 | 440 | (self.exclude_pattern is None or re.search(self.exclude_pattern, name) is None) |
416 | 441 | ): |
417 | 442 | self.cache.add(channel) |
|
0 commit comments