diff --git a/cocobot.py b/cocobot.py index 32c5b26..9dc39d6 100755 --- a/cocobot.py +++ b/cocobot.py @@ -15,6 +15,7 @@ parser.add_argument('--channel', type=str, help='channel to watch', default="") parser.add_argument('--domain', type=str, help='domain to connect to', default="loult.family") parser.add_argument('--port', type=int, help='port on which to connect the socket', default=80) parser.add_argument('--method', type=str, help='http or https', default="https") +parser.add_argument('--verbose', help='print debug information', action='store_true') # setting up coco client cococlient = CocoClient() @@ -35,8 +36,12 @@ root_messages_dispatcher = MessageDispatcher([coco_commands]) connections_dispatcher = ConnectionDispatcher([]) if __name__ == "__main__": - logging.getLogger().setLevel(logging.DEBUG) args = parser.parse_args() + if args.verbose: + logging.getLogger().setLevel(logging.DEBUG) + logging.getLogger("websockets").setLevel(logging.INFO) + else: + logging.getLogger().setLevel(logging.INFO) cocobot = CoboBot(args.cookie, args.channel, args.domain, args.port, args.method, root_messages_dispatcher, connections_dispatcher, cococlient) diff --git a/tools/base.py b/tools/base.py index 519c74b..6c0da62 100755 --- a/tools/base.py +++ b/tools/base.py @@ -95,9 +95,9 @@ class CoboBot: async def coco_pulse(self): while True: - logging.debug("Checking coco for new messages") await sleep(self.COCO_PULSE_TICK) if self.cococlient.is_connected: + logging.debug("Checking coco for new messages") new_messages = self.cococlient.pulse() if isinstance(new_messages, list): for response_obj in new_messages: diff --git a/tools/coco/client.py b/tools/coco/client.py index f88180d..07a3230 100644 --- a/tools/coco/client.py +++ b/tools/coco/client.py @@ -86,9 +86,12 @@ class CocoClient: self.user_id, self.user_pass = login_req.retrieve() logging.info("Logged in to coco as %s" % self.nick) post_login_req = PostLoginRequest(self.user_id, self.user_pass) - post_login_req.retrieve() - logging.info("Post login successful") - self.is_connected = True + if post_login_req.retrieve(): + logging.info("Post login successful") + self.is_connected = True + + else: + logging.info("Post login failed") def pulse(self) -> List[AbstractResponse]: pulse_req = PulseRequest(self.user_id, self.user_pass) diff --git a/tools/coco/requests.py b/tools/coco/requests.py index f3ce30b..d29ddc6 100644 --- a/tools/coco/requests.py +++ b/tools/coco/requests.py @@ -1,3 +1,4 @@ +import logging from urllib.request import Request, urlopen from random import randint, choice, random from string import ascii_uppercase @@ -64,6 +65,7 @@ class PostLoginRequest(LoggedInRequest): def _parse_response(self, response : str): """Checks if the post-login was successful""" + logging.debug(response) return response.startswith("99556") diff --git a/tools/processors/messages.py b/tools/processors/messages.py index eacb884..224be5b 100755 --- a/tools/processors/messages.py +++ b/tools/processors/messages.py @@ -70,7 +70,10 @@ class CocoConnectCommand(BaseCocobotCommand): return Message("Le code postal c'est 5 chiffres, pd") self.cococlient.connect(nick, int(age), True, zip_code) - return BotMessage("Connecté en tant que %s, de %s ans" % (nick, age)) + if self.cococlient.is_connected: + return BotMessage("Connecté en tant que %s, de %s ans" % (nick, age)) + else: + return BotMessage("La connection a chié, déswe") class CocoMsgCommand(BaseCocobotCommand):