diff --git a/CMakeLists.txt b/CMakeLists.txt index 194cb80..d2452ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.25) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Project instantiation -project(chlorobot VERSION 1.1.0.49) +project(chlorobot VERSION 1.1.0.50) # Fetch gRPC option(USE_SYSTEM_GRPC "Use system installed gRPC" ON) diff --git a/chloresolve/chloresolve/__init__.py b/chloresolve/chloresolve/__init__.py index 7b60bd0..8dc03ff 100644 --- a/chloresolve/chloresolve/__init__.py +++ b/chloresolve/chloresolve/__init__.py @@ -1 +1 @@ -__version__ = "1.1.0+rev37" \ No newline at end of file +__version__ = "1.1.0+rev38" \ No newline at end of file diff --git a/chloresolve/chloresolve/command.py b/chloresolve/chloresolve/command.py index e31db76..68b0726 100644 --- a/chloresolve/chloresolve/command.py +++ b/chloresolve/chloresolve/command.py @@ -34,14 +34,14 @@ async def version(args: dispatch.Arguments): async def join(args: dispatch.Arguments): if args.cloak.lower() == os.environ["CHLOROBOT_OWNER"]: - await args.resolver.send(None, "JOIN", [args.chanargs[1]], None) + await args.resolver.send(None, b"JOIN", [args.chanargs[1].encode()], None) else: await args.resolver.message(args.channel, args.nickname, "Not authorized") async def part(args: dispatch.Arguments): if args.cloak.lower() == os.environ["CHLOROBOT_OWNER"]: - await args.resolver.send(None, "PART", [args.chanargs[1]], None) + await args.resolver.send(None, b"PART", [args.chanargs[1].encode()], None) else: await args.resolver.message(args.channel, args.nickname, "Not authorized") diff --git a/chloresolve/main.py b/chloresolve/main.py index 436ef68..931407e 100644 --- a/chloresolve/main.py +++ b/chloresolve/main.py @@ -10,16 +10,14 @@ import asyncio import os import chloresolve -from chloresolve import dispatch, command - -CHLOROBOT_ENCODER_VERSION = 1 +from chloresolve import command class Chloresolver: - def __init__(self, stub, token: str, trigger: bytes, commands: dict[str, chloresolve.dispatch.Command]) -> None: + def __init__(self, stub, token: str, trigger: str, commands: dict[str, chloresolve.dispatch.Command]) -> None: self.stub = stub self.authentication = chlorobot_rpc_pb2.ChlorobotAuthentication( - token=token, version=CHLOROBOT_ENCODER_VERSION) + token=token, version=1) self.logger = logging.getLogger(__class__.__name__) self.trigger = trigger self.commands = commands @@ -61,12 +59,11 @@ async def listen(self) -> None: ident: str = b_ident.decode('utf-8') cloak: str = b_cloak.decode('utf-8') channel: str = b_channel.decode('utf-8') + s_message: str = message.trailing_parameter.decode('utf-8', errors='ignore') - self.logger.info(f"[{channel}] <{nickname}> {message}") - if message.trailing_parameter.startswith(self.trigger): - s_message: str = message.trailing_parameter.decode('utf-8', errors='ignore') - chanargs = s_message.trailing_parameter.removeprefix( - self.trigger).split(' ') + self.logger.info(f"[{channel}] <{nickname}> {s_message}") + if s_message.startswith(self.trigger): + chanargs = s_message.removeprefix(self.trigger).split(' ') self.logger.debug(f"[RCMD] n:{nickname} i:{ident} c:{ cloak} | h:{channel} | a:{chanargs}") @@ -131,7 +128,7 @@ async def main() -> None: async with grpc.aio.insecure_channel(f"{os.environ["CHLOROBOT_RPC_SERVER"]}:50051") as channel: logging.info("Trying to connect to gRPC socket") stub = chlorobot_rpc_pb2_grpc.ChlorobotRPCStub(channel) - resolver = Chloresolver(stub, os.environ["CHLOROBOT_RPC_TOKEN"], b'c|', { + resolver = Chloresolver(stub, os.environ["CHLOROBOT_RPC_TOKEN"], 'c|', { "ping": chloresolve.dispatch.Command(chloresolve.command.ping, "acknowledges if the bot resolver is online"), "help": chloresolve.dispatch.Command(chloresolve.command.help, "lists commands or gives a detailed description of one"), "join": chloresolve.dispatch.Command(chloresolve.command.join, "joins a channel"), @@ -143,7 +140,7 @@ async def main() -> None: ping = chlorobot_rpc_pb2.ChlorobotRequest( auth=resolver.authentication, command_type=chlorobot_rpc_pb2.ChlorobotCommandEnum.SEND_NOTHING) - result = await stub.Send(ping, timeout=15) + result = await stub.Send(ping, timeout=20) logging.info("Connected to gRPC socket") await resolver.listen() diff --git a/src/irc.cpp b/src/irc.cpp index 8ca47a1..a3797ad 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -137,6 +137,9 @@ void irc::authentication::proceed() { _context.AsyncNotifyWhenDone(this); _service->RequestListen(&_context, &_authentication, &_responder, _completion_queue, _completion_queue, this); + _state = irc::async_state::process; + } else if (_state == irc::async_state::process) { + std::cerr << "Started listening: " << this << std::endl; _encode_version = _authentication.has_version() ? _authentication.version() : 0; @@ -149,18 +152,18 @@ void irc::authentication::proceed() { << CURRENT_ENCODE_VERSION << std::endl; } + new irc::authentication(_service, _completion_queue); + if (_authentication.token() == *rpc_token) { - _state = irc::async_state::process; + std::cerr << "Valid auth on listener: " << this << std::endl; + listener_tags->insert(this); + _state = irc::async_state::finish; } else { std::cerr << "INVALID AUTH ON LISTENER: " << this << std::endl; _responder.Finish(grpc::Status::CANCELLED, this); _state = irc::async_state::finish; } - } else if (_state == irc::async_state::process) { - std::cerr << "Started listening: " << this << std::endl; - new irc::authentication(_service, _completion_queue); - listener_tags->insert(this); - _state = irc::async_state::finish; + } else { if (_context.IsCancelled()) { std::cerr << "Cancelled listening: " << this << std::endl;