Skip to content

Commit 2fcb839

Browse files
authored
Fix autoguild (#613)
* Fix autoguild * Update test_period_dynamic.py
1 parent 38057ad commit 2fcb839

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ venv*
2222
.venv*
2323

2424
*.bkp
25-
*.dtmp
25+
*.dtmp
26+
27+
.env

src/daf/guild/autoguild.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ async def _close(self):
565565
"""
566566
Closes any lower-level async objects.
567567
"""
568-
self._cache.clear()
569568
if self._event_ctrl is None: # Not initialized or already closed
569+
self._cache.clear()
570570
return
571571

572572
self._event_ctrl.remove_listener(EventID._trigger_auto_guild_start_join, self._join_guilds)
@@ -592,3 +592,5 @@ async def _close(self):
592592

593593
for guild in self._cache:
594594
await guild._close()
595+
596+
self._cache.clear()

testing/test_autogen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ async def test_autochannel(guilds, channels, accounts):
4545
guild: daf.discord.Guild
4646
guild, _ = guilds
4747
text_channels, voice_channels = channels
48-
auto_channel = daf.message.AutoCHANNEL("testpy-[0-9]", "testpy-[5-9]")
49-
auto_channel2 = daf.message.AutoCHANNEL("testpy-[0-9]", "testpy-[5-9]")
48+
auto_channel = daf.message.AutoCHANNEL("testpy-[0-2]", "testpy-[2-9]")
49+
auto_channel2 = daf.message.AutoCHANNEL("testpy-[0-1]", "testpy-[1-9]")
5050

5151
cwd = os.getcwd()
5252
os.chdir(os.path.dirname(__file__))
@@ -64,11 +64,11 @@ async def test_autochannel(guilds, channels, accounts):
6464
sort_key = lambda x: x.name
6565
auto_channel._get_channels()
6666
auto_channel2._get_channels()
67-
assert sorted(text_channels[:5], key=sort_key) == sorted(auto_channel.channels, key=sort_key), "Correct behavior would be for AutoCHANNEL to only find first 5 text channels"
68-
assert sorted(voice_channels[:5], key=sort_key) == sorted(auto_channel2.channels, key=sort_key), "Correct behavior would be for AutoCHANNEL to only find first 5 voice channels"
67+
assert sorted(text_channels[:2], key=sort_key) == sorted(auto_channel.channels, key=sort_key), "Correct behavior would be for AutoCHANNEL to only find first 5 text channels"
68+
assert sorted(voice_channels[:1], key=sort_key) == sorted(auto_channel2.channels, key=sort_key), "Correct behavior would be for AutoCHANNEL to only find first 5 voice channels"
6969

70-
await auto_channel.update(exclude_pattern=None)
71-
await auto_channel2.update(exclude_pattern=None)
70+
await auto_channel.update(include_pattern=daf.regex("testpy-[0-2]")) # Removes the original exclude pattern
71+
await auto_channel2.update(include_pattern=daf.regex("testpy-[0-1]")) # Removes the original exclude pattern
7272
auto_channel._get_channels()
7373
auto_channel2._get_channels()
7474
assert sorted(text_channels, key=sort_key) == sorted(auto_channel.channels, key=sort_key), "Correct behavior would be for AutoCHANNEL to find all text channels"

testing/test_period_dynamic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ async def dynamic_getter_async(items: list):
7373
and message.channel == text_channels[0],
7474
timeout=TEST_MAX_WAIT_TIME)
7575
# Test TextMESSAGE
76-
7776
assert len(guild.parent.servers) == 2
7877
await asyncio.sleep(10)
7978
text_message = daf.message.TextMESSAGE(None, TEST_SEND_PERIOD_TEXT, TEXT_MESSAGE_TEST_MESSAGE, [text_channels[0]],

0 commit comments

Comments
 (0)