|
|
|
@ -1,4 +1,5 @@ |
|
|
|
from tools.commons import Message |
|
|
|
from tools.coco.client import CocoClient |
|
|
|
|
|
|
|
from tools.commons import Message, BotMessage |
|
|
|
from .commons import * |
|
|
|
from .commons import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -31,3 +32,83 @@ class CommandsDispatcherProcessor(DispatcherBotProcessor): |
|
|
|
response = super().process(without_cmd, sender_id, users_list) |
|
|
|
response = super().process(without_cmd, sender_id, users_list) |
|
|
|
return Message(self.default_response) if response is None else response |
|
|
|
return Message(self.default_response) if response is None else response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseCocobotCommand(MessageProcessor): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HELP_STR = None |
|
|
|
|
|
|
|
_cmd_suffix = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, cococlient: CocoClient): |
|
|
|
|
|
|
|
self.cococlient = cococlient |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def match(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
return text.lower().startswith(self._cmd_suffix) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CocoConnectCommand(BaseCocobotCommand): |
|
|
|
|
|
|
|
HELP_STR = "/coconnect pseudo age code_postal" |
|
|
|
|
|
|
|
_cmd_suffix = "nnect" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
text = text[len(self._cmd_suffix):].strip() |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
nick, age, zip_code = text.split() |
|
|
|
|
|
|
|
except ValueError: |
|
|
|
|
|
|
|
return Message("Pas le bon nombre d'arguments, pd") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not nick.isalnum(): |
|
|
|
|
|
|
|
return Message("Le pseudo doit être alphanumérique, pd") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(age) != 2 or not age.isnumeric(): |
|
|
|
|
|
|
|
return Message("L'âge c'est avec DEUX chiffres (déso bulbi)") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(zip_code) != 5 or not zip_code.isnumeric(): |
|
|
|
|
|
|
|
return Message("Le code postal c'est 5 chiffres, pd") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.cococlient.connect(nick, int(age), True, zip_code) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CocoMsgCommand(BaseCocobotCommand): |
|
|
|
|
|
|
|
HELP_STR = "/cocospeak message" |
|
|
|
|
|
|
|
_cmd_suffix = "speak" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
text = text[len(self._cmd_suffix):].strip() |
|
|
|
|
|
|
|
return self.cococlient.send_msg(text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CocoSwitchCommand(BaseCocobotCommand): |
|
|
|
|
|
|
|
HELP_STR = "/cocoswitch [pseudo de l'interlocuteur]" |
|
|
|
|
|
|
|
_cmd_suffix = "switch" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
text = text[len(self._cmd_suffix):].strip() |
|
|
|
|
|
|
|
if text: |
|
|
|
|
|
|
|
return self.cococlient.switch_conv(text) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return self.cococlient.switch_conv() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CocoListCommand(BaseCocobotCommand): |
|
|
|
|
|
|
|
HELP_STR = "/cocolist" |
|
|
|
|
|
|
|
_cmd_suffix = "list" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
return self.cococlient.list_convs() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BotHelp(MessageProcessor): |
|
|
|
|
|
|
|
"""Displays the help string for all processors in the list that have a helpt string""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, processors_list: List[BaseCocobotCommand]): |
|
|
|
|
|
|
|
all_help_strs = [proc.HELP_STR |
|
|
|
|
|
|
|
for proc in processors_list if proc.HELP_STR is not None] |
|
|
|
|
|
|
|
self.help_str = ", ".join(all_help_strs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def match(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
return text.lower().startswith("help") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(self, text : str, sender_id : str, users_list : UserList): |
|
|
|
|
|
|
|
return BotMessage(self.help_str) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|