Browse Source

Ajout du listing des conversations disponibles

master
hadware 8 years ago
parent
commit
0a73a2dc73
  1. 11
      tools/coco/client.py

11
tools/coco/client.py

@ -1,5 +1,5 @@
import random import random
from typing import List, Dict, Tuple, Union from typing import List, Dict, Tuple, Union, Set
from .requests import LoginRequest, PostLoginRequest, PulseRequest, SendMsgRequest from .requests import LoginRequest, PostLoginRequest, PulseRequest, SendMsgRequest
from ..commons import BotMessage, Message, AbstractResponse from ..commons import BotMessage, Message, AbstractResponse
@ -40,7 +40,7 @@ class Interlocutor:
class CocoClient: class CocoClient:
def __init__(self): def __init__(self):
self.interlocutors = [] # type: List[Interlocutor] self.interlocutors = set() # type: Set[Interlocutor]
self.current_interlocutor = None # type: Interlocutor self.current_interlocutor = None # type: Interlocutor
self.histories = {} # type:Dict[Interlocutor,List[Tuple]] self.histories = {} # type:Dict[Interlocutor,List[Tuple]]
@ -59,6 +59,7 @@ class CocoClient:
out = [] out = []
for user_code, msg in received_msgs: for user_code, msg in received_msgs:
user = Interlocutor.from_string(user_code) user = Interlocutor.from_string(user_code)
self.interlocutors.add(user)
self.histories[user].append((user.nick, msg)) self.histories[user].append((user.nick, msg))
if user == self.current_interlocutor: if user == self.current_interlocutor:
@ -109,4 +110,8 @@ class CocoClient:
else: else:
self.current_interlocutor = new_interlocutor self.current_interlocutor = new_interlocutor
return [new_interlocutor.to_botmessage()] + \ return [new_interlocutor.to_botmessage()] + \
self._format_history(self.current_interlocutor) self._format_history(self.current_interlocutor)
def list_convs(self):
return BotMessage("Conversations : " + ", ".join(["%s(%i)" % (usr.nick, usr.age)
for usr in self.interlocutors]))
Loading…
Cancel
Save