Compare commits
2 Commits
3f2c9369bd
...
2372363898
Author | SHA1 | Date | |
---|---|---|---|
2372363898 | |||
d9a66d0c74 |
@ -122,17 +122,28 @@ class IdleRPG(Plugin):
|
|||||||
|
|
||||||
def handle_kick_penalty(self, connection, event):
|
def handle_kick_penalty(self, connection, event):
|
||||||
"""Penalize characters for their user getting kicked from the channel."""
|
"""Penalize characters for their user getting kicked from the channel."""
|
||||||
self.seen_hostmasks.discard(event.source)
|
logger.debug("kick: %s", event)
|
||||||
logger.info("Removed %s from the set of seen hostmasks.", event.source)
|
|
||||||
return self._handle_generic_penalty_and_logout(event.source, event.target, 250,
|
# 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",
|
"getting kicked from the game channel",
|
||||||
'time_penalized_kicked')
|
'time_penalized_kicked')
|
||||||
|
|
||||||
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 +166,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 +223,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 +295,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
|
||||||
|
|
||||||
@ -47,21 +45,30 @@ class IrcPluginTest(TestCase):
|
|||||||
def test_kick_penalty(self):
|
def test_kick_penalty(self):
|
||||||
"""Test that if a character is kicked from the game channel, they get penalized."""
|
"""Test that if a character is kicked from the game channel, they get penalized."""
|
||||||
mock_event = mock.MagicMock()
|
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.target = '#test'
|
||||||
|
mock_event.arguments = ['bss', '']
|
||||||
mock_event.recursing = False
|
mock_event.recursing = False
|
||||||
|
|
||||||
# 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('testkickpen', self.game, 'test',
|
test_char = Character.objects.register('testkickpen', self.game, 'test',
|
||||||
'bss!bss@test_kick_penalty', 'tester')
|
'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:
|
with mock.patch('idlerpg.models.Character.log_out') as mock_log_out:
|
||||||
self.plugin.handle_kick_penalty(self.mock_connection, mock_event)
|
self.plugin.handle_kick_penalty(self.mock_connection, mock_event)
|
||||||
|
|
||||||
mock_penalize.assert_called_with(250, "getting kicked from the game channel")
|
mock_penalize.assert_called_with(250, "getting kicked from the game channel")
|
||||||
mock_log_out.assert_called()
|
mock_log_out.assert_called()
|
||||||
test_char = Character.objects.get(name='testkickpen')
|
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()
|
test_char.delete()
|
||||||
|
|
||||||
@ -89,14 +96,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 +125,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 +155,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 +385,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