mirror of
https://github.com/evennia/evennia.git
synced 2026-04-04 23:17:17 +02:00
Adding a check to prevent duplicate channel names.
This commit is contained in:
parent
463197470e
commit
725b1b2ac0
2 changed files with 19 additions and 1 deletions
|
|
@ -139,6 +139,12 @@ def cmd_ccreate(cdat):
|
|||
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
if name_matches:
|
||||
session.msg("A channel with that name already exists.")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
cdat = {"name": cname, "owner": pobject}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,16 @@ def create_channel(cdat):
|
|||
new_chan.header = "[%s]" % (ansi.parse_ansi(cdat["name"]),)
|
||||
new_chan.set_owner(cdat["owner"])
|
||||
new_chan.save()
|
||||
return new_chan
|
||||
return new_chan
|
||||
|
||||
def cname_search(search_text, exact=False):
|
||||
"""
|
||||
Searches for a particular channel name. Returns a QuerySet with the
|
||||
results.
|
||||
|
||||
exact: (bool) Do an exact (case-insensitive) name match if true.
|
||||
"""
|
||||
if exact:
|
||||
return CommChannel.objects.filter(name__iexact=search_text)
|
||||
else:
|
||||
return CommChannel.objects.filter(name__istartswith=search_text)
|
||||
Loading…
Add table
Add a link
Reference in a new issue