Skip to content

Commit e703f8c

Browse files
authored
Merge pull request #147 from LoLei/fix-herald-strip-special-characters
Fix removal of special characters for herald clean
2 parents ab946ef + ac0f055 commit e703f8c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

plugins/herald.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def welcome(nick, message, bot, chan):
106106

107107
greet = herald_cache[chan.casefold()].get(nick.casefold())
108108
if greet:
109-
stripped = greet.translate(dict.fromkeys(["\u200b", " ", "\u202f", "\x02"]))
109+
stripped = greet.translate(dict.fromkeys(map(ord, ["\u200b", " ", "\u202f", "\x02"])))
110110
stripped = colors_re.sub("", stripped)
111111
greet = re.sub(bino_re, 'flenny', greet)
112112
greet = re.sub(offensive_re, ' freespeech oppression ', greet)

tests/plugin_tests/test_herald.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from unittest.mock import MagicMock
2+
3+
import pytest
4+
5+
from cloudbot.event import Event
6+
from plugins import herald
7+
from tests.util import wrap_hook_response
8+
9+
10+
@pytest.fixture()
11+
def clear_cache():
12+
try:
13+
yield
14+
finally:
15+
herald.herald_cache.clear()
16+
17+
18+
@pytest.fixture()
19+
def unset_timeout():
20+
try:
21+
yield
22+
finally:
23+
herald.floodcheck.clear()
24+
25+
26+
@pytest.mark.usefixtures("unset_timeout")
27+
class TestWelcome:
28+
def _run(self):
29+
conn = MagicMock()
30+
event = Event(
31+
hook=MagicMock(),
32+
bot=conn.bot,
33+
conn=conn,
34+
channel='#foo',
35+
nick='foobaruser'
36+
)
37+
return wrap_hook_response(herald.welcome, event)
38+
39+
def test_no_herald(self):
40+
result = self._run()
41+
assert result == []
42+
43+
@pytest.mark.parametrize('text,out', [
44+
('Hello world', '\u200b Hello world'),
45+
('bino', '\u200b flenny'),
46+
('\u200b hi', '\u200b \u200b hi'),
47+
('o\u200b<', 'DECOY DUCK --> o\u200b<'),
48+
])
49+
def test_char_strip(self, clear_cache, text, out):
50+
herald.herald_cache['#foo']['foobaruser'] = text
51+
result = self._run()
52+
assert result == [('message', ('#foo', out))]

0 commit comments

Comments
 (0)