From ee829e6dbe7adb0b2afb14eb9204d55dd326ba46 Mon Sep 17 00:00:00 2001 From: hadware Date: Wed, 30 May 2018 03:05:06 +0200 Subject: [PATCH] Quelques bugfix --- tools/base.py | 1 + tools/coco/client.py | 6 +++++- tools/coco/tools.py | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/base.py b/tools/base.py index d0d6ded..519c74b 100755 --- a/tools/base.py +++ b/tools/base.py @@ -31,6 +31,7 @@ class CoboBot: self.cococlient = cococlient async def _send_message(self, message): + logging.debug("Sending message to server") if isinstance(message, dict): await self.socket.send(json.dumps(message)) elif isinstance(message, bytes): diff --git a/tools/coco/client.py b/tools/coco/client.py index 843f740..6891ec0 100644 --- a/tools/coco/client.py +++ b/tools/coco/client.py @@ -72,6 +72,7 @@ class CocoClient: return out def connect(self, nick: str, age: int, is_female: bool, zip_code: str): + self.interlocutors = set() self.nick = nick self.histories = defaultdict(list) self.current_interlocutor = None @@ -103,6 +104,9 @@ class CocoClient: return [BotMessage("Il faut sélectionner une conversation d'abord pd")] def switch_conv(self, nick: str=None) -> Union[List[BotMessage], BotMessage]: + if not self.interlocutors: + return BotMessage("Pas de conversations en cours") + new_interlocutor = None if nick is not None: for usr in self.interlocutors: @@ -110,7 +114,7 @@ class CocoClient: new_interlocutor = usr break else: - new_interlocutor = random.choice(self.interlocutors) + new_interlocutor = random.choice(list(self.interlocutors)) if new_interlocutor is None: return BotMessage("Impossible de trouver l'utilisateur") diff --git a/tools/coco/tools.py b/tools/coco/tools.py index 310b356..8b76b0c 100644 --- a/tools/coco/tools.py +++ b/tools/coco/tools.py @@ -70,7 +70,7 @@ smilies = [":)", ":(", ";)", ":d", ":-o", ":s", ":$", "*-)", "-)", "^o)", ":p", "nw$", "ba$", "ao$", "db$", "si$", "oo$", "co$", "bi$", "cc$", "ye$", "mo$", "aa$", "ci$", "uu$", "ff$", "zz$", "gt$", "ah$", "mm$", "?$", "xx$"] -special_chars = bidict.bidict({" ": "~", "!": "!", "$": "*7", "%": "*g", "'": "*8", "(": "(", ")": ")", "*": "*s", "=": "*h", +special_chars = bidict.bidict({" ": "_", "$": "*7", "%": "*g", "'": "*8", "(": "(", ")": ")", "*": "*s", "=": "*h", "?": "=", "@": "*m", "^": "*l", "_": "*0", "€": "*d", "à": "*a", "â": "*k", "ç": "*c", "è": "*e", "é": "*r", "ê": "*b", "î": "*i", "ï": "*j", "ô": "*o", "ù": "*f", "û": "*u"}) @@ -82,7 +82,7 @@ def encode_msg(msg : str): for char, replacement in special_chars.items(): msg = msg.replace(char, replacement) - + msg = ''.join([c for c in msg if ord(c) < 128]) return msg