the kick event source is the kicker, so find the kickee by nick
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
d9a66d0c74
commit
2372363898
@ -122,9 +122,18 @@ class IdleRPG(Plugin):
|
||||
|
||||
def handle_kick_penalty(self, connection, event):
|
||||
"""Penalize characters for their user getting kicked from the channel."""
|
||||
self.seen_hostmasks.discard(event.source)
|
||||
logger.info("Removed %s from the set of seen hostmasks.", event.source)
|
||||
return self._handle_generic_penalty_and_logout(event.source, event.target, 250,
|
||||
logger.debug("kick: %s", event)
|
||||
|
||||
# somewhat hacky attempt to find the hostmask for the kicked nick
|
||||
kicked_nick_hostmask_prefix = f'{event.arguments[0]}!'
|
||||
try:
|
||||
source = [x for x in self.seen_hostmasks if x.startswith(kicked_nick_hostmask_prefix)][0]
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
self.seen_hostmasks.discard(source)
|
||||
logger.info("Removed %s from the set of seen hostmasks.", source)
|
||||
return self._handle_generic_penalty_and_logout(source, event.target, 250,
|
||||
"getting kicked from the game channel",
|
||||
'time_penalized_kicked')
|
||||
|
||||
|
@ -45,21 +45,30 @@ class IrcPluginTest(TestCase):
|
||||
def test_kick_penalty(self):
|
||||
"""Test that if a character is kicked from the game channel, they get penalized."""
|
||||
mock_event = mock.MagicMock()
|
||||
mock_event.source = 'bss!bss@test_kick_penalty'
|
||||
mock_event.source = 'admin!admin@the_kicker'
|
||||
mock_event.target = '#test'
|
||||
mock_event.arguments = ['bss', '']
|
||||
mock_event.recursing = False
|
||||
|
||||
# make a character so as to not disturb other tests
|
||||
test_char = Character.objects.register('testkickpen', self.game, 'test',
|
||||
'bss!bss@test_kick_penalty', 'tester')
|
||||
with mock.patch('idlerpg.models.Character.penalize', return_value=5) as mock_penalize:
|
||||
self.plugin.seen_hostmasks.add('bss!bss@test_kick_penalty')
|
||||
with mock.patch('idlerpg.models.Character.penalize', return_value=250) as mock_penalize:
|
||||
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
||||
self.plugin.handle_kick_penalty(self.mock_connection, mock_event)
|
||||
|
||||
mock_penalize.assert_called_with(250, "getting kicked from the game channel")
|
||||
mock_log_out.assert_called()
|
||||
test_char = Character.objects.get(name='testkickpen')
|
||||
assert test_char.time_penalized_kicked == 5
|
||||
assert test_char.time_penalized_kicked == 250
|
||||
assert 'bss!bss@test_kick_penalty' not in self.plugin.seen_hostmasks
|
||||
self.mock_bot.reply.assert_called_once_with(
|
||||
None,
|
||||
"testkickpen, the level 0 tester has been penalized 250 seconds for getting kicked from the game channel, "
|
||||
"and has been logged out.",
|
||||
explicit_target='bss',
|
||||
)
|
||||
|
||||
test_char.delete()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user