Skip to content

Commit d6270af

Browse files
committed
Properly handle empty log_channel
1 parent 35a7e27 commit d6270af

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

plugins/core/core_misc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ async def onjoin(conn, bot):
111111
conn.cmd("MODE", conn.nick, mode)
112112

113113
log_chan = conn.config.get("log_channel")
114-
if " " in log_chan:
115-
log_chan, key = log_chan.split(None, 1)
116-
else:
117-
key = None
118-
119114
if log_chan:
115+
if " " in log_chan:
116+
log_chan, key = log_chan.split(None, 1)
117+
else:
118+
key = None
119+
120120
conn.join(log_chan, key)
121121

122122
conn.ready = True

tests/plugin_tests/core_misc_test.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from unittest.mock import call
1+
from unittest.mock import MagicMock, call
22

3+
import pytest
34
from irclib.parser import ParamList
45

56
from plugins.core import core_misc
@@ -28,3 +29,26 @@ def test_invite_join_disabled():
2829
core_misc.invite(ParamList("foo", "#bar"), conn)
2930

3031
assert conn.send.mock_calls == []
32+
33+
34+
@pytest.mark.asyncio()
35+
@pytest.mark.parametrize(
36+
"config,calls",
37+
[
38+
({}, []),
39+
({"log_channel": "#foo"}, [call("JOIN #foo")]),
40+
({"log_channel": "#foo bar"}, [call("JOIN #foo bar")]),
41+
({"log_channel": "#foo bar baz"}, [call("JOIN #foo :bar baz")]),
42+
],
43+
)
44+
async def test_on_connect(config, calls):
45+
bot = MagicMock()
46+
config = config.copy()
47+
config.setdefault("connection", {}).setdefault("server", "host.invalid")
48+
conn = MockIrcClient(bot, "fooconn", "foobot", config)
49+
50+
res = await core_misc.onjoin(conn, bot)
51+
52+
assert res is None
53+
54+
assert conn.send.mock_calls == calls

0 commit comments

Comments
 (0)