Skip to content

Commit

Permalink
v1.1 ok, fix up bytes and str confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chlorophytus committed Jun 3, 2024
1 parent 00fa650 commit 80ad1a4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion chloresolve/chloresolve/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.0+rev37"
__version__ = "1.1.0+rev38"
4 changes: 2 additions & 2 deletions chloresolve/chloresolve/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
21 changes: 9 additions & 12 deletions chloresolve/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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"),
Expand All @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions src/irc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 80ad1a4

Please sign in to comment.