From 2accf0c8a4940bec410bd4f010a5d72b165a4120 Mon Sep 17 00:00:00 2001 From: hadware Date: Wed, 30 May 2018 17:28:37 +0200 Subject: [PATCH] Ajout d'un cocoquit --- cocobot.py | 5 +++-- tools/coco/client.py | 10 ++++++++-- tools/processors/messages.py | 12 ++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cocobot.py b/cocobot.py index c2eb449..32c5b26 100755 --- a/cocobot.py +++ b/cocobot.py @@ -24,9 +24,10 @@ connect_cmd = CocoConnectCommand(cococlient) msg_cmd = CocoMsgCommand(cococlient) list_cmd = CocoListCommand(cococlient) switch_cmd = CocoSwitchCommand(cococlient) -help_cmd = BotHelp([connect_cmd, msg_cmd, list_cmd, switch_cmd]) +quit_cmd = CocoQuitCommand(cococlient) +help_cmd = BotHelp([connect_cmd, msg_cmd, list_cmd, switch_cmd, quit_cmd]) -coco_commands = CommandsDispatcherProcessor([connect_cmd, msg_cmd, list_cmd, switch_cmd, help_cmd], +coco_commands = CommandsDispatcherProcessor([connect_cmd, msg_cmd, list_cmd, switch_cmd, help_cmd, quit_cmd], "coco", default_response="de?") root_messages_dispatcher = MessageDispatcher([coco_commands]) diff --git a/tools/coco/client.py b/tools/coco/client.py index b19b5c7..f88180d 100644 --- a/tools/coco/client.py +++ b/tools/coco/client.py @@ -71,11 +71,17 @@ class CocoClient: out.append(BotMessage("💬 %s: %s" % (user.nick, msg))) return out - def connect(self, nick: str, age: int, is_female: bool, zip_code: str): + def disconnect(self): self.interlocutors = set() - self.nick = nick self.histories = defaultdict(list) self.current_interlocutor = None + self.is_connected = False + self.nick = None + + def connect(self, nick: str, age: int, is_female: bool, zip_code: str): + self.disconnect() + + self.nick = nick login_req = LoginRequest(nick, age, is_female, zip_code) self.user_id, self.user_pass = login_req.retrieve() logging.info("Logged in to coco as %s" % self.nick) diff --git a/tools/processors/messages.py b/tools/processors/messages.py index 778dfca..d68badf 100755 --- a/tools/processors/messages.py +++ b/tools/processors/messages.py @@ -62,6 +62,9 @@ class CocoConnectCommand(BaseCocobotCommand): if len(age) != 2 or not age.isnumeric(): return Message("L'âge c'est avec DEUX chiffres (déso bulbi)") + if int(age) < 15: + return Message("L'âge minimum c'est 15 ans (déso bubbi)") + if len(zip_code) != 5 or not zip_code.isnumeric(): return Message("Le code postal c'est 5 chiffres, pd") @@ -98,6 +101,15 @@ class CocoListCommand(BaseCocobotCommand): return self.cococlient.list_convs() +class CocoQuitCommand(BaseCocobotCommand): + HELP_STR = "/cocoquit" + _cmd_suffix = "quit" + + def process(self, text : str, sender_id : str, users_list : UserList): + self.cococlient.disconnect() + return BotMessage("Déconnecté!") + + class BotHelp(MessageProcessor): """Displays the help string for all processors in the list that have a helpt string"""