看起来merge 好了?(

This commit is contained in:
shenjack-5600u 2024-02-02 21:47:43 +08:00
parent 18bb976db1
commit a7932a0b2c
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
3 changed files with 20 additions and 32 deletions

View File

@ -14,32 +14,11 @@ from nacl.signing import SigningKey
from lib_not_dr.loggers import config from lib_not_dr.loggers import config
from data_struct import SendMessage, ReplyMessage, get_config, BotConfig, BotStatus from data_struct import SendMessage, ReplyMessage, get_config, BotConfig, BotStatus
from main import BOTCONFIG, _version_
_version_ = "0.3.0" from router import route
logger = config.get_logger("icalingua") 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() 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}") logger.info(f"{Fore.MAGENTA}add_message: {data}")
is_self = data["message"]["senderId"] == BOTCONFIG.self_id 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: if not is_self:
route(content, sio) await route(data, sio)
@sio.on("deleteMessage") # type: ignore @sio.on("deleteMessage") # type: ignore

View File

@ -15,6 +15,7 @@ _version_ = "0.3.0"
logger = config.get_logger("bot") logger = config.get_logger("bot")
BOTCONFIG: BotConfig = get_config() BOTCONFIG: BotConfig = get_config()
BotStatus = BotStatus()
if __name__ == "__main__": if __name__ == "__main__":
# --debug # --debug
@ -32,3 +33,4 @@ if __name__ == "__main__":
BOTCONFIG: BotConfig = get_config(args.config) BOTCONFIG: BotConfig = get_config(args.config)
if args.no_notice: if args.no_notice:
BOTCONFIG.notice_start = False BOTCONFIG.notice_start = False

View File

@ -3,13 +3,26 @@ import asyncio
from lib_not_dr.loggers import config 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.safe_eval import safe_eval
from plugins.bmcl import bmcl from plugins.bmcl import bmcl
from plugins.yw import yw from plugins.yw import yw
logger = config.get_logger("router") 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": if content == "/bot":
message = reply_msg.to_content(f"icalingua bot pong v{_version_}") message = reply_msg.to_content(f"icalingua bot pong v{_version_}")
await sio.emit("sendMessage", message.to_json()) await sio.emit("sendMessage", message.to_json())