mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 20:45:06 +08:00
看起来merge 好了?(
This commit is contained in:
parent
18bb976db1
commit
a7932a0b2c
33
connect.py
33
connect.py
|
@ -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
|
||||||
|
|
2
main.py
2
main.py
|
@ -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
|
||||||
|
|
||||||
|
|
15
router.py
15
router.py
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user