Browse Source

Ajout d'un cocoquit

master
hadware 8 years ago
parent
commit
2accf0c8a4
  1. 5
      cocobot.py
  2. 10
      tools/coco/client.py
  3. 12
      tools/processors/messages.py

5
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])

10
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)

12
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"""

Loading…
Cancel
Save