Ajout d'un peu de debugennww
This commit is contained in:
+6
-1
@@ -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('--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('--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('--method', type=str, help='http or https', default="https")
|
||||||
|
parser.add_argument('--verbose', help='print debug information', action='store_true')
|
||||||
|
|
||||||
# setting up coco client
|
# setting up coco client
|
||||||
cococlient = CocoClient()
|
cococlient = CocoClient()
|
||||||
@@ -35,8 +36,12 @@ root_messages_dispatcher = MessageDispatcher([coco_commands])
|
|||||||
connections_dispatcher = ConnectionDispatcher([])
|
connections_dispatcher = ConnectionDispatcher([])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
|
||||||
args = parser.parse_args()
|
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,
|
cocobot = CoboBot(args.cookie, args.channel, args.domain, args.port, args.method,
|
||||||
root_messages_dispatcher, connections_dispatcher, cococlient)
|
root_messages_dispatcher, connections_dispatcher, cococlient)
|
||||||
|
|||||||
+1
-1
@@ -95,9 +95,9 @@ class CoboBot:
|
|||||||
|
|
||||||
async def coco_pulse(self):
|
async def coco_pulse(self):
|
||||||
while True:
|
while True:
|
||||||
logging.debug("Checking coco for new messages")
|
|
||||||
await sleep(self.COCO_PULSE_TICK)
|
await sleep(self.COCO_PULSE_TICK)
|
||||||
if self.cococlient.is_connected:
|
if self.cococlient.is_connected:
|
||||||
|
logging.debug("Checking coco for new messages")
|
||||||
new_messages = self.cococlient.pulse()
|
new_messages = self.cococlient.pulse()
|
||||||
if isinstance(new_messages, list):
|
if isinstance(new_messages, list):
|
||||||
for response_obj in new_messages:
|
for response_obj in new_messages:
|
||||||
|
|||||||
@@ -86,9 +86,12 @@ class CocoClient:
|
|||||||
self.user_id, self.user_pass = login_req.retrieve()
|
self.user_id, self.user_pass = login_req.retrieve()
|
||||||
logging.info("Logged in to coco as %s" % self.nick)
|
logging.info("Logged in to coco as %s" % self.nick)
|
||||||
post_login_req = PostLoginRequest(self.user_id, self.user_pass)
|
post_login_req = PostLoginRequest(self.user_id, self.user_pass)
|
||||||
post_login_req.retrieve()
|
if post_login_req.retrieve():
|
||||||
logging.info("Post login successful")
|
logging.info("Post login successful")
|
||||||
self.is_connected = True
|
self.is_connected = True
|
||||||
|
|
||||||
|
else:
|
||||||
|
logging.info("Post login failed")
|
||||||
|
|
||||||
def pulse(self) -> List[AbstractResponse]:
|
def pulse(self) -> List[AbstractResponse]:
|
||||||
pulse_req = PulseRequest(self.user_id, self.user_pass)
|
pulse_req = PulseRequest(self.user_id, self.user_pass)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
from random import randint, choice, random
|
from random import randint, choice, random
|
||||||
from string import ascii_uppercase
|
from string import ascii_uppercase
|
||||||
@@ -64,6 +65,7 @@ class PostLoginRequest(LoggedInRequest):
|
|||||||
|
|
||||||
def _parse_response(self, response : str):
|
def _parse_response(self, response : str):
|
||||||
"""Checks if the post-login was successful"""
|
"""Checks if the post-login was successful"""
|
||||||
|
logging.debug(response)
|
||||||
return response.startswith("99556")
|
return response.startswith("99556")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ class CocoConnectCommand(BaseCocobotCommand):
|
|||||||
return Message("Le code postal c'est 5 chiffres, pd")
|
return Message("Le code postal c'est 5 chiffres, pd")
|
||||||
|
|
||||||
self.cococlient.connect(nick, int(age), True, zip_code)
|
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):
|
class CocoMsgCommand(BaseCocobotCommand):
|
||||||
|
|||||||
Reference in New Issue
Block a user