message the character's player when penalties are applied
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
3f2c9369bd
commit
d9a66d0c74
@ -130,9 +130,11 @@ class IdleRPG(Plugin):
|
|||||||
|
|
||||||
def handle_nick_penalty(self, connection, event):
|
def handle_nick_penalty(self, connection, event):
|
||||||
"""Penalize characters for changing their nick while in the channel."""
|
"""Penalize characters for changing their nick while in the channel."""
|
||||||
# TODO: figure out how to update the character and seen hostmasks
|
logger.debug("nick change: %s", event)
|
||||||
|
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, 30,
|
return self._handle_generic_penalty_and_logout(event.source, event.target, 30,
|
||||||
"changing their nick",
|
"a nick change",
|
||||||
'time_penalized_nick_change')
|
'time_penalized_nick_change')
|
||||||
|
|
||||||
def handle_part_penalty(self, connection, event):
|
def handle_part_penalty(self, connection, event):
|
||||||
@ -155,6 +157,9 @@ class IdleRPG(Plugin):
|
|||||||
penalty = character.penalize(len(message), "sending a privmsg to the game channel")
|
penalty = character.penalize(len(message), "sending a privmsg to the game channel")
|
||||||
character.time_penalized_privmsg += penalty
|
character.time_penalized_privmsg += penalty
|
||||||
character.save()
|
character.save()
|
||||||
|
nick = irc.client.NickMask(hostmask).nick
|
||||||
|
self.bot.reply(None, f"{character} has been penalized {penalty} seconds for talking in the game channel.",
|
||||||
|
explicit_target=nick)
|
||||||
except Character.DoesNotExist:
|
except Character.DoesNotExist:
|
||||||
logger.debug("no character found for %s", hostmask)
|
logger.debug("no character found for %s", hostmask)
|
||||||
return
|
return
|
||||||
@ -209,7 +214,8 @@ class IdleRPG(Plugin):
|
|||||||
penalty = character.penalize(20, "logging out")
|
penalty = character.penalize(20, "logging out")
|
||||||
character.time_penalized_logout += penalty
|
character.time_penalized_logout += penalty
|
||||||
character.save()
|
character.save()
|
||||||
return self.bot.reply(event, f"{character}, has been successfully logged out.")
|
return self.bot.reply(event, f"{character}, has been successfully logged out. "
|
||||||
|
f"They have been penalized {penalty} seconds.")
|
||||||
|
|
||||||
def handle_register(self, connection, event, match):
|
def handle_register(self, connection, event, match):
|
||||||
"""Register a character for a user."""
|
"""Register a character for a user."""
|
||||||
@ -280,6 +286,10 @@ class IdleRPG(Plugin):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
logger.debug("tried to log out %s but they already were", character)
|
logger.debug("tried to log out %s but they already were", character)
|
||||||
character.save()
|
character.save()
|
||||||
|
nick = irc.client.NickMask(hostmask).nick
|
||||||
|
self.bot.reply(None,
|
||||||
|
f"{character} has been penalized {penalty} seconds for {reason}, and has been logged out.",
|
||||||
|
explicit_target=nick)
|
||||||
except Character.DoesNotExist:
|
except Character.DoesNotExist:
|
||||||
logger.debug("no character found for %s", hostmask)
|
logger.debug("no character found for %s", hostmask)
|
||||||
|
|
||||||
|
@ -4,14 +4,12 @@ SPDX-FileCopyrightText: © 2024 Brian S. Stephan <bss@incorporeal.org>
|
|||||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
|
||||||
import re
|
import re
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from ircbot.models import IrcServer
|
||||||
|
|
||||||
from ircbot.models import IrcChannel, IrcServer
|
|
||||||
from idlerpg.ircplugin import IdleRPG
|
from idlerpg.ircplugin import IdleRPG
|
||||||
from idlerpg.models import Character, Game
|
from idlerpg.models import Character, Game
|
||||||
|
|
||||||
@ -89,14 +87,22 @@ class IrcPluginTest(TestCase):
|
|||||||
# make a character so as to not disturb other tests
|
# make a character so as to not disturb other tests
|
||||||
test_char = Character.objects.register('testnickpen', self.game, 'test',
|
test_char = Character.objects.register('testnickpen', self.game, 'test',
|
||||||
'bss!bss@test_nick_penalty', 'tester')
|
'bss!bss@test_nick_penalty', 'tester')
|
||||||
with mock.patch('idlerpg.models.Character.penalize', return_value=5) as mock_penalize:
|
self.plugin.seen_hostmasks.add('bss!bss@test_nick_penalty')
|
||||||
|
with mock.patch('idlerpg.models.Character.penalize', return_value=30) as mock_penalize:
|
||||||
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
||||||
self.plugin.handle_nick_penalty(self.mock_connection, mock_event)
|
self.plugin.handle_nick_penalty(self.mock_connection, mock_event)
|
||||||
|
|
||||||
mock_penalize.assert_called_with(30, "changing their nick")
|
mock_penalize.assert_called_with(30, "a nick change")
|
||||||
mock_log_out.assert_called()
|
mock_log_out.assert_called()
|
||||||
test_char = Character.objects.get(name='testnickpen')
|
test_char = Character.objects.get(name='testnickpen')
|
||||||
assert test_char.time_penalized_nick_change == 5
|
assert test_char.time_penalized_nick_change == 30
|
||||||
|
assert 'bss!bss@test_nick_penalty' not in self.plugin.seen_hostmasks
|
||||||
|
self.mock_bot.reply.assert_called_once_with(
|
||||||
|
None,
|
||||||
|
"testnickpen, the level 0 tester has been penalized 30 seconds for a nick change, "
|
||||||
|
"and has been logged out.",
|
||||||
|
explicit_target='bss',
|
||||||
|
)
|
||||||
|
|
||||||
test_char.delete()
|
test_char.delete()
|
||||||
|
|
||||||
@ -110,14 +116,22 @@ class IrcPluginTest(TestCase):
|
|||||||
# make a character so as to not disturb other tests
|
# make a character so as to not disturb other tests
|
||||||
test_char = Character.objects.register('testpartpen', self.game, 'test',
|
test_char = Character.objects.register('testpartpen', self.game, 'test',
|
||||||
'bss!bss@test_part_penalty', 'tester')
|
'bss!bss@test_part_penalty', 'tester')
|
||||||
with mock.patch('idlerpg.models.Character.penalize', return_value=5) as mock_penalize:
|
self.plugin.seen_hostmasks.add('bss!bss@test_part_penalty')
|
||||||
|
with mock.patch('idlerpg.models.Character.penalize', return_value=200) as mock_penalize:
|
||||||
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
||||||
self.plugin.handle_part_penalty(self.mock_connection, mock_event)
|
self.plugin.handle_part_penalty(self.mock_connection, mock_event)
|
||||||
|
|
||||||
mock_penalize.assert_called_with(200, "parting the game channel")
|
mock_penalize.assert_called_with(200, "parting the game channel")
|
||||||
mock_log_out.assert_called()
|
mock_log_out.assert_called()
|
||||||
test_char = Character.objects.get(name='testpartpen')
|
test_char = Character.objects.get(name='testpartpen')
|
||||||
assert test_char.time_penalized_part == 5
|
assert test_char.time_penalized_part == 200
|
||||||
|
assert 'bss!bss@test_part_penalty' not in self.plugin.seen_hostmasks
|
||||||
|
self.mock_bot.reply.assert_called_once_with(
|
||||||
|
None,
|
||||||
|
"testpartpen, the level 0 tester has been penalized 200 seconds for parting the game channel, "
|
||||||
|
"and has been logged out.",
|
||||||
|
explicit_target='bss',
|
||||||
|
)
|
||||||
|
|
||||||
test_char.delete()
|
test_char.delete()
|
||||||
|
|
||||||
@ -132,13 +146,18 @@ class IrcPluginTest(TestCase):
|
|||||||
# make a character so as to not disturb other tests
|
# make a character so as to not disturb other tests
|
||||||
test_char = Character.objects.register('testpubmsgpen', self.game, 'test',
|
test_char = Character.objects.register('testpubmsgpen', self.game, 'test',
|
||||||
'bss!bss@test_pubmsg_penalty', 'tester')
|
'bss!bss@test_pubmsg_penalty', 'tester')
|
||||||
with mock.patch('idlerpg.models.Character.penalize', return_value=5) as mock_penalize:
|
with mock.patch('idlerpg.models.Character.penalize', return_value=22) as mock_penalize:
|
||||||
self.plugin.handle_message_penalty(self.mock_connection, mock_event)
|
self.plugin.handle_message_penalty(self.mock_connection, mock_event)
|
||||||
|
|
||||||
# 22 is the len of the message
|
# 22 is the len of the message
|
||||||
mock_penalize.assert_called_with(22, "sending a privmsg to the game channel")
|
mock_penalize.assert_called_with(22, "sending a privmsg to the game channel")
|
||||||
test_char = Character.objects.get(name='testpubmsgpen')
|
test_char = Character.objects.get(name='testpubmsgpen')
|
||||||
assert test_char.time_penalized_privmsg == 5
|
assert test_char.time_penalized_privmsg == 22
|
||||||
|
self.mock_bot.reply.assert_called_once_with(
|
||||||
|
None,
|
||||||
|
"testpubmsgpen, the level 0 tester has been penalized 22 seconds for talking in the game channel.",
|
||||||
|
explicit_target='bss',
|
||||||
|
)
|
||||||
|
|
||||||
test_char.delete()
|
test_char.delete()
|
||||||
|
|
||||||
@ -357,7 +376,8 @@ class IrcPluginTest(TestCase):
|
|||||||
assert refetch.next_level > test_char.next_level
|
assert refetch.next_level > test_char.next_level
|
||||||
assert refetch.status == Character.CHARACTER_STATUS_OFFLINE
|
assert refetch.status == Character.CHARACTER_STATUS_OFFLINE
|
||||||
self.mock_bot.reply.assert_called_once_with(
|
self.mock_bot.reply.assert_called_once_with(
|
||||||
mock_event, "test_logout, the level 0 tester, has been successfully logged out."
|
mock_event, ("test_logout, the level 0 tester, has been successfully logged out. "
|
||||||
|
"They have been penalized 20 seconds.")
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_register(self):
|
def test_register(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user