diff --git a/connect.py b/connect.py index 04f83fd..b3a087b 100644 --- a/connect.py +++ b/connect.py @@ -14,32 +14,11 @@ from nacl.signing import SigningKey from lib_not_dr.loggers import config from data_struct import SendMessage, ReplyMessage, get_config, BotConfig, BotStatus - -_version_ = "0.3.0" +from main import BOTCONFIG, _version_ +from router import route logger = config.get_logger("icalingua") -BOTCONFIG: BotConfig = get_config() - -if __name__ == "__main__": - # --debug - # --config=config.toml - # -n --no-notice - parser = argparse.ArgumentParser() - parser.add_argument("-d", "--debug", action="store_true") - parser.add_argument("-n", "--no-notice", action="store_true") - parser.add_argument("-c", "--config", type=str) - args = parser.parse_args() - if args.debug: - logger.global_level = 0 - if args.config: - # global BOTCONFIG - BOTCONFIG: BotConfig = get_config(args.config) - if args.no_notice: - BOTCONFIG.notice_start = False - -BotStatus = BotStatus() - sio: socketio.AsyncClient = socketio.AsyncClient() @@ -96,15 +75,9 @@ async def add_message(data: Dict[str, Any]): logger.info(f"{Fore.MAGENTA}add_message: {data}") is_self = data["message"]["senderId"] == BOTCONFIG.self_id - sender_name = data["message"]["username"] - sender_id = data["message"]["senderId"] - content = data["message"]["content"] - room_id = data["roomId"] - msg_id = data["message"]["_id"] - reply_msg = SendMessage(content="", room_id=room_id, reply_to=ReplyMessage(id=msg_id)) if not is_self: - route(content, sio) + await route(data, sio) @sio.on("deleteMessage") # type: ignore diff --git a/main.py b/main.py index 820bed5..ebd2c84 100644 --- a/main.py +++ b/main.py @@ -15,6 +15,7 @@ _version_ = "0.3.0" logger = config.get_logger("bot") BOTCONFIG: BotConfig = get_config() +BotStatus = BotStatus() if __name__ == "__main__": # --debug @@ -31,4 +32,5 @@ if __name__ == "__main__": # global BOTCONFIG BOTCONFIG: BotConfig = get_config(args.config) if args.no_notice: - BOTCONFIG.notice_start = False \ No newline at end of file + BOTCONFIG.notice_start = False + diff --git a/router.py b/router.py index b7ea50e..2be8939 100644 --- a/router.py +++ b/router.py @@ -3,13 +3,26 @@ import asyncio from lib_not_dr.loggers import config +from main import BOTCONFIG, _version_ +from data_struct import SendMessage, ReplyMessage + from plugins.safe_eval import safe_eval from plugins.bmcl import bmcl from plugins.yw import yw logger = config.get_logger("router") -async def route(content, sio): +async def route(data, sio): + + is_self = data["message"]["senderId"] == BOTCONFIG.self_id + sender_name = data["message"]["username"] + sender_id = data["message"]["senderId"] + content = data["message"]["content"] + room_id = data["roomId"] + msg_id = data["message"]["_id"] + + reply_msg = SendMessage(content="", room_id=room_id, reply_to=ReplyMessage(id=msg_id)) + if content == "/bot": message = reply_msg.to_content(f"icalingua bot pong v{_version_}") await sio.emit("sendMessage", message.to_json())