Browse Source

Ajout du broadcast

master
hadware 8 years ago
parent
commit
856244c16d
  1. 20
      tools/coco/client.py
  2. 13
      tools/processors/messages.py

20
tools/coco/client.py

@ -107,13 +107,27 @@ class CocoClient:
self.histories[self.current_interlocutor].append((self.nick, msg))
out_msg = Message("💬 %s: %s" % (self.nick, msg))
out = [out_msg]
if output:
return [out_msg] + self.__process_and_format_received_msg(output)
else:
return [out_msg]
out += self.__process_and_format_received_msg(output)
return out
else:
return [BotMessage("Il faut sélectionner une conversation d'abord pd")]
def broadcast_msg(self, msg: str) -> List[AbstractResponse]:
if self.interlocutors:
outputs = [Message("💬 %s à tous: %s" % (self.nick, msg))]
for interlocutor in self.interlocutors:
sendmsg_req = SendMsgRequest(self.user_id, self.user_pass, interlocutor.id, msg)
output = sendmsg_req.retrieve()
self.histories[interlocutor].append((self.nick, msg))
if output:
outputs += self.__process_and_format_received_msg(output)
return outputs
else:
return [BotMessage("Aucune conversation active")]
def switch_conv(self, nick: str=None) -> Union[List[BotMessage], BotMessage]:
if not self.interlocutors:
return BotMessage("Pas de conversations en cours")

13
tools/processors/messages.py

@ -69,7 +69,11 @@ class CocoConnectCommand(BaseCocobotCommand):
if len(zip_code) != 5 or not zip_code.isnumeric():
return Message("Le code postal c'est 5 chiffres, pd")
try:
self.cococlient.connect(nick, int(age), True, zip_code)
except ValueError:
return Message("Le code postal a pas l'air d'être bon")
if self.cococlient.is_connected:
return BotMessage("Connecté en tant que %s, de %s ans" % (nick, age))
else:
@ -85,6 +89,15 @@ class CocoMsgCommand(BaseCocobotCommand):
return self.cococlient.send_msg(text)
class CocoBroadcastCommand(BaseCocobotCommand):
HELP_STR = "/cocoall message"
_cmd_suffix = "all"
def process(self, text : str, sender_id : str, users_list : UserList):
text = text[len(self._cmd_suffix):].strip()
return self.cococlient.broadcast_msg(text)
class CocoSwitchCommand(BaseCocobotCommand):
HELP_STR = "/cocoswitch [pseudo de l'interlocuteur]"
_cmd_suffix = "switch"

Loading…
Cancel
Save