Made addcom aliases case-insensitive. Resolves #428. Also fixed a bug with channel aliases that made them not work correctly with the new Attribute changes.

This commit is contained in:
Griatch 2014-02-16 23:29:19 +01:00
parent 5e942749e9
commit 9770786486
4 changed files with 10 additions and 11 deletions

View file

@ -451,7 +451,7 @@ class ObjectDB(TypedObject):
# do text encoding conversion
raw_string = to_unicode(raw_string)
raw_string = self.nicks.nickreplace(raw_string,
categories=("inputline", "channels"), include_player=True)
categories=("inputline", "channel"), include_player=True)
return cmdhandler.cmdhandler(_GA(self, "typeclass"), raw_string, callertype="object", sessid=sessid)
def msg(self, text=None, from_obj=None, sessid=0, **kwargs):

View file

@ -425,7 +425,7 @@ class PlayerDB(TypedObject, AbstractUser):
raw_string = utils.to_unicode(raw_string)
raw_string = self.nicks.nickreplace(raw_string,
categories=("inputline", "channels"), include_player=False)
categories=("inputline", "channel"), include_player=False)
if not sessid and _MULTISESSION_MODE in (0, 1):
# in this case, we should either have only one sessid, or the sessid
# should not matter (since the return goes to all of them we can

View file

@ -191,7 +191,7 @@ class ServerSession(Session):
puppet = self.player.get_puppet(self.sessid)
if puppet:
text = puppet.nicks.nickreplace(text,
categories=("inputline", "channels"), include_player=True)
categories=("inputline", "channel"), include_player=True)
else:
text = self.player.nicks.nickreplace(text,
categories=("inputline", "channels"), include_player=False)

View file

@ -27,12 +27,8 @@ these to create custom managers.
"""
import sys
#try:
# import cPickle as pickle
#except ImportError:
# import pickle
import re
import traceback
#from collections import defaultdict
from django.db import models
from django.conf import settings
@ -398,8 +394,9 @@ class NickHandler(AttributeHandler):
"Remove Nick with matching category"
super(NickHandler, self).remove(key, category=category, **kwargs)
def nickreplace(self, raw_string, categories=("inputline", "channels"), include_player=True):
def nickreplace(self, raw_string, categories=("inputline", "channel"), include_player=True):
"Replace entries in raw_string with nick replacement"
raw_string
obj_nicks, player_nicks = [], []
for category in make_iter(categories):
obj_nicks.extend(make_iter(self.get(category=category, return_obj=True)))
@ -407,8 +404,10 @@ class NickHandler(AttributeHandler):
for category in make_iter(categories):
player_nicks.extend(make_iter(self.obj.player.nicks.get(category=category, return_obj=True)))
for nick in obj_nicks + player_nicks:
if raw_string.startswith(nick.db_key):
raw_string = raw_string.replace(nick.db_key, nick.db_strvalue, 1)
# make a case-insensitive match here
match = re.match(re.escape(nick.db_key), raw_string, re.IGNORECASE)
if match:
raw_string = raw_string.replace(match.group(), nick.db_strvalue, 1)
break
return raw_string