Merge pull request #3107 from Machine-Garden-MUD/3106_fix

Prevent recreation of same-named channels
This commit is contained in:
Griatch 2023-02-25 09:04:46 +01:00 committed by GitHub
commit e431a786b5
2 changed files with 13 additions and 14 deletions

View file

@ -489,9 +489,8 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
def create_channel(self, name, description, typeclass=None, aliases=None): def create_channel(self, name, description, typeclass=None, aliases=None):
""" """
Create a new channel. Its name must not previously exist Create a new channel. Its name must not previously exist (case agnostic)
(users can alias as needed). Will also connect to the (users can alias as needed). Will also connect to the new channel.
new channel.
Args: Args:
name (str): The new channel name/key. name (str): The new channel name/key.
@ -880,7 +879,6 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
if "create" in switches: if "create" in switches:
# create a new channel # create a new channel
if not self.access(caller, "manage"): if not self.access(caller, "manage"):
self.msg("You don't have access to use channel/create.") self.msg("You don't have access to use channel/create.")
return return
@ -937,7 +935,7 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
) )
elif len(found_channels) > 1: elif len(found_channels) > 1:
errors.append( errors.append(
"Multiple possible channel matches/alias for '{channel_name}':\n" f"Multiple possible channel matches/alias for '{channel_name}':\n"
+ ", ".join(chan.key for chan in found_channels) + ", ".join(chan.key for chan in found_channels)
) )
else: else:

View file

@ -392,20 +392,21 @@ class Evennia:
from evennia.utils.create import create_channel from evennia.utils.create import create_channel
superuser = AccountDB.objects.get(id=1) superuser = AccountDB.objects.get(id=1)
# mudinfo # mudinfo
mudinfo_chan = settings.CHANNEL_MUDINFO mudinfo_chan = settings.CHANNEL_MUDINFO
if mudinfo_chan: if mudinfo_chan and not ChannelDB.objects.filter(db_key__iexact=mudinfo_chan["key"]):
if not ChannelDB.objects.filter(db_key=mudinfo_chan["key"]):
channel = create_channel(**mudinfo_chan) channel = create_channel(**mudinfo_chan)
channel.connect(superuser) channel.connect(superuser)
# connectinfo # connectinfo
connectinfo_chan = settings.CHANNEL_MUDINFO connectinfo_chan = settings.CHANNEL_CONNECTINFO
if connectinfo_chan: if connectinfo_chan and not ChannelDB.objects.filter(
if not ChannelDB.objects.filter(db_key=mudinfo_chan["key"]): db_key__iexact=connectinfo_chan["key"]
):
channel = create_channel(**connectinfo_chan) channel = create_channel(**connectinfo_chan)
# default channels # default channels
for chan_info in settings.DEFAULT_CHANNELS: for chan_info in settings.DEFAULT_CHANNELS:
if not ChannelDB.objects.filter(db_key=chan_info["key"]): if not ChannelDB.objects.filter(db_key__iexact=chan_info["key"]):
channel = create_channel(**chan_info) channel = create_channel(**chan_info)
channel.connect(superuser) channel.connect(superuser)