Ajout d'un cocoquit
This commit is contained in:
+3
-2
@@ -24,9 +24,10 @@ connect_cmd = CocoConnectCommand(cococlient)
|
|||||||
msg_cmd = CocoMsgCommand(cococlient)
|
msg_cmd = CocoMsgCommand(cococlient)
|
||||||
list_cmd = CocoListCommand(cococlient)
|
list_cmd = CocoListCommand(cococlient)
|
||||||
switch_cmd = CocoSwitchCommand(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?")
|
"coco", default_response="de?")
|
||||||
|
|
||||||
root_messages_dispatcher = MessageDispatcher([coco_commands])
|
root_messages_dispatcher = MessageDispatcher([coco_commands])
|
||||||
|
|||||||
@@ -71,11 +71,17 @@ class CocoClient:
|
|||||||
out.append(BotMessage("💬 %s: %s" % (user.nick, msg)))
|
out.append(BotMessage("💬 %s: %s" % (user.nick, msg)))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def connect(self, nick: str, age: int, is_female: bool, zip_code: str):
|
def disconnect(self):
|
||||||
self.interlocutors = set()
|
self.interlocutors = set()
|
||||||
self.nick = nick
|
|
||||||
self.histories = defaultdict(list)
|
self.histories = defaultdict(list)
|
||||||
self.current_interlocutor = None
|
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)
|
login_req = LoginRequest(nick, age, is_female, zip_code)
|
||||||
self.user_id, self.user_pass = login_req.retrieve()
|
self.user_id, self.user_pass = login_req.retrieve()
|
||||||
logging.info("Logged in to coco as %s" % self.nick)
|
logging.info("Logged in to coco as %s" % self.nick)
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ class CocoConnectCommand(BaseCocobotCommand):
|
|||||||
if len(age) != 2 or not age.isnumeric():
|
if len(age) != 2 or not age.isnumeric():
|
||||||
return Message("L'âge c'est avec DEUX chiffres (déso bulbi)")
|
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():
|
if len(zip_code) != 5 or not zip_code.isnumeric():
|
||||||
return Message("Le code postal c'est 5 chiffres, pd")
|
return Message("Le code postal c'est 5 chiffres, pd")
|
||||||
|
|
||||||
@@ -98,6 +101,15 @@ class CocoListCommand(BaseCocobotCommand):
|
|||||||
return self.cococlient.list_convs()
|
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):
|
class BotHelp(MessageProcessor):
|
||||||
"""Displays the help string for all processors in the list that have a helpt string"""
|
"""Displays the help string for all processors in the list that have a helpt string"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user