X-Git-Url: http://gitweb.pimeys.fr/?a=blobdiff_plain;f=quotes.py;h=bd05913fe316a4bf980fd09adf07f58460788d50;hb=b58870bba04ffabc1a7469e6fd80e4bc60ebc41c;hp=fa9ac0afdedf3c8dfc6b945150d46533b4b03f72;hpb=a140e55d58b6af4b50c1cd83a78aa387f78e1a80;p=bots%2Fparrot.git diff --git a/quotes.py b/quotes.py index fa9ac0a..bd05913 100644 --- a/quotes.py +++ b/quotes.py @@ -13,11 +13,16 @@ import config quote_matcher = re.compile(config.quote_regexp, flags=re.UNICODE) quote_matcher_with_timestamp = re.compile(config.quote_regexp_with_timestamp, flags=re.UNICODE) +spaces_matcher = re.compile(u"\s", flags=re.U) def get_now(): """ Renvoie la date actuelle """ return datetime.datetime(*time.localtime()[:6]) +def sanitize_author(raw): + """Proprifie l'auteur : enlève les espaces insécables.""" + return spaces_matcher.sub(u" ", raw) + class Quote(object): """ Une citation """ def __init__(self, author, content, timestamp=None): @@ -25,7 +30,7 @@ class Quote(object): timestamp = get_now() elif isinstance(timestamp, basestring): timestamp = datetime.datetime(*time.strptime(timestamp, u"%Y-%m-%d_%H:%M:%S")[:6]) - self.author = author + self.author = sanitize_author(author) self.content = content self.timestamp = timestamp @@ -42,8 +47,8 @@ class Quote(object): def __eq__(self, otherquote): """ Vérifie si cette phrase n'a pas déjà été dite par la même personne. - Indépendamment de la date. """ - return [self.author, self.content] == [otherquote.author, otherquote.content] + Indépendamment de la date et de la casse. """ + return [self.author.lower(), self.content.lower()] == [otherquote.author.lower(), otherquote.content.lower()] def parse(text, date=None):