test (and implement) the whoreply method to log existing users in
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
56b554f6f1
commit
3f2c9369bd
@ -96,6 +96,25 @@ class IdleRPG(Plugin):
|
||||
|
||||
super(IdleRPG, self).stop()
|
||||
|
||||
def handle_whoreply_response(self, connection, event):
|
||||
"""Track who is in the channel and flag who is online and log them in.
|
||||
|
||||
We do a /WHO when coming online and joining the game channel, presuming that everyone in it
|
||||
*would have* logged themselves in if they were able to, but the bot wasn't online. This may
|
||||
log in people who are not, but that doesn't seem like a huge risk to the spirit of the game.
|
||||
"""
|
||||
user = event.arguments[1]
|
||||
host = event.arguments[2]
|
||||
nick = event.arguments[4]
|
||||
hostmask = f'{nick}!{user}@{host}'
|
||||
self.seen_hostmasks.add(hostmask)
|
||||
logger.info("Added %s to the set of seen hostmasks.", hostmask)
|
||||
for character in Character.objects.filter(enabled=True, status=Character.CHARACTER_STATUS_OFFLINE,
|
||||
hostmask=hostmask):
|
||||
character.status = Character.CHARACTER_STATUS_LOGGED_IN
|
||||
logger.info("Marked %s as logged in.", character)
|
||||
character.save()
|
||||
|
||||
def handle_join(self, connection, event):
|
||||
"""Track a character as online if their player joins the game channel."""
|
||||
self.seen_hostmasks.add(event.source)
|
||||
|
@ -209,6 +209,22 @@ class IrcPluginTest(TestCase):
|
||||
|
||||
test_char.delete()
|
||||
|
||||
def test_whoreply(self):
|
||||
"""When joining, we do a /WHO to see who is online."""
|
||||
mock_event = mock.MagicMock()
|
||||
mock_event.arguments = ['', 'bss', 'bss', '', 'bss2']
|
||||
|
||||
assert 'bss2!bss@bss' not in self.plugin.seen_hostmasks
|
||||
char = Character.objects.get(name='bss2', game=self.game)
|
||||
assert char.status == Character.CHARACTER_STATUS_OFFLINE
|
||||
self.plugin.handle_whoreply_response(self.mock_connection, mock_event)
|
||||
|
||||
assert 'bss2!bss@bss' in self.plugin.seen_hostmasks
|
||||
char = Character.objects.get(name='bss2', game=self.game)
|
||||
assert char.status == Character.CHARACTER_STATUS_LOGGED_IN
|
||||
# clean up
|
||||
char.log_out()
|
||||
|
||||
def test_login_character_not_found(self):
|
||||
"""Test the LOGIN command sent to the bot."""
|
||||
mock_event = mock.MagicMock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user