Skip to content

Commit

Permalink
Merge branch 'master' into v4.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhozic committed Sep 21, 2024
2 parents d8ba452 + 2fcb839 commit ab8d8f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ venv*
.venv*

*.bkp
*.dtmp
*.dtmp

.env
4 changes: 3 additions & 1 deletion src/daf/guild/autoguild.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ async def _close(self):
"""
Closes any lower-level async objects.
"""
self._cache.clear()
if self._event_ctrl is None: # Not initialized or already closed
self._cache.clear()
return

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

for guild in self._cache:
await guild._close()

self._cache.clear()
12 changes: 6 additions & 6 deletions testing/test_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ async def test_autochannel(guilds, channels, accounts):
guild: daf.discord.Guild
guild, _ = guilds
text_channels, voice_channels = channels
auto_channel = daf.message.AutoCHANNEL("testpy-[0-9]", "testpy-[5-9]")
auto_channel2 = daf.message.AutoCHANNEL("testpy-[0-9]", "testpy-[5-9]")
auto_channel = daf.message.AutoCHANNEL("testpy-[0-2]", "testpy-[2-9]")
auto_channel2 = daf.message.AutoCHANNEL("testpy-[0-1]", "testpy-[1-9]")

cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
Expand All @@ -64,11 +64,11 @@ async def test_autochannel(guilds, channels, accounts):
sort_key = lambda x: x.name
auto_channel._get_channels()
auto_channel2._get_channels()
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"
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"
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"
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"

await auto_channel.update(exclude_pattern=None)
await auto_channel2.update(exclude_pattern=None)
await auto_channel.update(include_pattern=daf.regex("testpy-[0-2]")) # Removes the original exclude pattern
await auto_channel2.update(include_pattern=daf.regex("testpy-[0-1]")) # Removes the original exclude pattern
auto_channel._get_channels()
auto_channel2._get_channels()
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"
Expand Down
1 change: 0 additions & 1 deletion testing/test_period_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ async def dynamic_getter_async(items: list):
and message.channel == text_channels[0],
timeout=TEST_MAX_WAIT_TIME)
# Test TextMESSAGE

assert len(guild.parent.servers) == 2
await asyncio.sleep(10)
text_message = daf.message.TextMESSAGE(None, TEST_SEND_PERIOD_TEXT, TEXT_MESSAGE_TEST_MESSAGE, [text_channels[0]],
Expand Down

0 comments on commit ab8d8f8

Please sign in to comment.