Ajout du broadcast
This commit is contained in:
+17
-3
@@ -107,13 +107,27 @@ class CocoClient:
|
|||||||
self.histories[self.current_interlocutor].append((self.nick, msg))
|
self.histories[self.current_interlocutor].append((self.nick, msg))
|
||||||
out_msg = Message("💬 %s: %s" % (self.nick, msg))
|
out_msg = Message("💬 %s: %s" % (self.nick, msg))
|
||||||
|
|
||||||
|
out = [out_msg]
|
||||||
if output:
|
if output:
|
||||||
return [out_msg] + self.__process_and_format_received_msg(output)
|
out += self.__process_and_format_received_msg(output)
|
||||||
else:
|
return out
|
||||||
return [out_msg]
|
|
||||||
else:
|
else:
|
||||||
return [BotMessage("Il faut sélectionner une conversation d'abord pd")]
|
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]:
|
def switch_conv(self, nick: str=None) -> Union[List[BotMessage], BotMessage]:
|
||||||
if not self.interlocutors:
|
if not self.interlocutors:
|
||||||
return BotMessage("Pas de conversations en cours")
|
return BotMessage("Pas de conversations en cours")
|
||||||
|
|||||||
@@ -69,7 +69,11 @@ class CocoConnectCommand(BaseCocobotCommand):
|
|||||||
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")
|
||||||
|
|
||||||
|
try:
|
||||||
self.cococlient.connect(nick, int(age), True, zip_code)
|
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:
|
if self.cococlient.is_connected:
|
||||||
return BotMessage("Connecté en tant que %s, de %s ans" % (nick, age))
|
return BotMessage("Connecté en tant que %s, de %s ans" % (nick, age))
|
||||||
else:
|
else:
|
||||||
@@ -85,6 +89,15 @@ class CocoMsgCommand(BaseCocobotCommand):
|
|||||||
return self.cococlient.send_msg(text)
|
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):
|
class CocoSwitchCommand(BaseCocobotCommand):
|
||||||
HELP_STR = "/cocoswitch [pseudo de l'interlocuteur]"
|
HELP_STR = "/cocoswitch [pseudo de l'interlocuteur]"
|
||||||
_cmd_suffix = "switch"
|
_cmd_suffix = "switch"
|
||||||
|
|||||||
Reference in New Issue
Block a user