Merge pull request #3122 from owllex/channelnick

Fix issue with channel nick aliases.
This commit is contained in:
Griatch 2023-02-25 23:11:27 +01:00 committed by GitHub
commit f250a3e7ce
3 changed files with 43 additions and 16 deletions

View file

@ -31,14 +31,7 @@ from evennia import (
from evennia.commands import cmdparser from evennia.commands import cmdparser
from evennia.commands.cmdset import CmdSet from evennia.commands.cmdset import CmdSet
from evennia.commands.command import Command, InterruptCommand from evennia.commands.command import Command, InterruptCommand
from evennia.commands.default import ( from evennia.commands.default import account, admin, batchprocess, building, comms, general
account,
admin,
batchprocess,
building,
comms,
general,
)
from evennia.commands.default import help as help_module from evennia.commands.default import help as help_module
from evennia.commands.default import syscommands, system, unloggedin from evennia.commands.default import syscommands, system, unloggedin
from evennia.commands.default.cmdset_character import CharacterCmdSet from evennia.commands.default.cmdset_character import CharacterCmdSet
@ -83,7 +76,9 @@ class TestGeneral(BaseEvenniaCommandTest):
def test_pose(self): def test_pose(self):
self.char2.msg = Mock() self.char2.msg = Mock()
self.call(general.CmdPose(), "looks around", "Char looks around") self.call(general.CmdPose(), "looks around", "Char looks around")
self.char2.msg.assert_called_with(text=('Char looks around', {'type': 'pose'}), from_obj=self.char1) self.char2.msg.assert_called_with(
text=("Char looks around", {"type": "pose"}), from_obj=self.char1
)
def test_nick(self): def test_nick(self):
self.call( self.call(
@ -173,7 +168,6 @@ class TestGeneral(BaseEvenniaCommandTest):
class TestHelp(BaseEvenniaCommandTest): class TestHelp(BaseEvenniaCommandTest):
maxDiff = None maxDiff = None
def setUp(self): def setUp(self):
@ -584,7 +578,6 @@ class TestAccount(BaseEvenniaCommandTest):
] ]
) )
def test_ooc_look(self, multisession_mode, auto_puppet, max_nr_chars, expected_result): def test_ooc_look(self, multisession_mode, auto_puppet, max_nr_chars, expected_result):
self.account.db._playable_characters = [self.char1] self.account.db._playable_characters = [self.char1]
self.account.unpuppet_all() self.account.unpuppet_all()
@ -1563,7 +1556,6 @@ class TestBuilding(BaseEvenniaCommandTest):
) )
def test_script_multi_delete(self): def test_script_multi_delete(self):
script1 = create.create_script() script1 = create.create_script()
script2 = create.create_script() script2 = create.create_script()
script3 = create.create_script() script3 = create.create_script()
@ -1867,7 +1859,7 @@ class TestCommsChannel(BaseEvenniaCommandTest):
self.call(self.cmdchannel(), "/sub testchannel", "You are now subscribed") self.call(self.cmdchannel(), "/sub testchannel", "You are now subscribed")
self.assertTrue(self.char1 in self.channel.subscriptions.all()) self.assertTrue(self.char1 in self.channel.subscriptions.all())
self.assertEqual( self.assertEqual(
self.char1.nicks.nickreplace("testchannel Hello"), "channel testchannel = Hello" self.char1.nicks.nickreplace("testchannel Hello"), "@channel testchannel = Hello"
) )
def test_channel__unsub(self): def test_channel__unsub(self):
@ -1883,7 +1875,7 @@ class TestCommsChannel(BaseEvenniaCommandTest):
"/alias testchannel = foo", "/alias testchannel = foo",
"Added/updated your alias 'foo' for channel testchannel.", "Added/updated your alias 'foo' for channel testchannel.",
) )
self.assertEqual(self.char1.nicks.nickreplace("foo Hello"), "channel testchannel = Hello") self.assertEqual(self.char1.nicks.nickreplace("foo Hello"), "@channel testchannel = Hello")
# use alias # use alias
self.channel.msg = Mock() self.channel.msg = Mock()
@ -2084,7 +2076,6 @@ class TestBatchProcess(BaseEvenniaCommandTest):
class CmdInterrupt(Command): class CmdInterrupt(Command):
key = "interrupt" key = "interrupt"
def parse(self): def parse(self):

View file

@ -7,6 +7,7 @@ import re
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.urls import reverse from django.urls import reverse
from django.utils.text import slugify from django.utils.text import slugify
from evennia.comms.managers import ChannelManager from evennia.comms.managers import ChannelManager
from evennia.comms.models import ChannelDB from evennia.comms.models import ChannelDB
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
@ -66,7 +67,7 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
# default nick-alias replacements (default using the 'channel' command) # default nick-alias replacements (default using the 'channel' command)
channel_msg_nick_pattern = r"{alias}\s*?|{alias}\s+?(?P<arg1>.+?)" channel_msg_nick_pattern = r"{alias}\s*?|{alias}\s+?(?P<arg1>.+?)"
channel_msg_nick_replacement = "channel {channelname} = $1" channel_msg_nick_replacement = "@channel {channelname} = $1"
def at_first_save(self): def at_first_save(self):
""" """

View file

@ -1,8 +1,20 @@
from django.test import SimpleTestCase
from evennia import DefaultChannel from evennia import DefaultChannel
from evennia.commands.default.comms import CmdChannel
from evennia.utils.create import create_message from evennia.utils.create import create_message
from evennia.utils.test_resources import BaseEvenniaTest from evennia.utils.test_resources import BaseEvenniaTest
class TestCommsNickMatchesCommand(SimpleTestCase):
def test(self):
"""
Verifies that the nick being set by DefaultChannel matches the channel
command key.
"""
self.assertTrue(DefaultChannel.channel_msg_nick_replacement.startswith(CmdChannel.key))
class ObjectCreationTest(BaseEvenniaTest): class ObjectCreationTest(BaseEvenniaTest):
def test_channel_create(self): def test_channel_create(self):
description = "A place to talk about coffee." description = "A place to talk about coffee."
@ -18,6 +30,29 @@ class ObjectCreationTest(BaseEvenniaTest):
self.assertEqual(str(msg), "peewee herman->: heh-heh!") self.assertEqual(str(msg), "peewee herman->: heh-heh!")
class ChannelSubscriptionTests(BaseEvenniaTest):
def setUp(self):
super().setUp()
self.default_channel, _ = DefaultChannel.create(
"catlovers", description="A place for feline fanciers."
)
self.default_channel.connect(self.obj1)
def test_subscribe_unsubscribe(self):
self.default_channel.connect(self.char1)
self.assertTrue(self.default_channel.subscriptions.has(self.char1))
self.assertEqual(
self.char1.nicks.nickreplace("catlovers I love cats!"),
"@channel catlovers = I love cats!",
)
self.default_channel.disconnect(self.char1)
self.assertFalse(self.default_channel.subscriptions.has(self.char1))
self.assertEqual(
self.char1.nicks.nickreplace("catlovers I love cats!"),
"catlovers I love cats!",
)
class ChannelWholistTests(BaseEvenniaTest): class ChannelWholistTests(BaseEvenniaTest):
def setUp(self): def setUp(self):
super().setUp() super().setUp()