Skip to content

Commit

Permalink
Merge pull request #264 from serfend/EventSubscript
Browse files Browse the repository at this point in the history
refactor[event]split logic and fix #149
  • Loading branch information
Serfend authored Jun 28, 2023
2 parents 4eab1ab + 04a6e6c commit 4b5c0af
Show file tree
Hide file tree
Showing 22 changed files with 690 additions and 571 deletions.
23 changes: 9 additions & 14 deletions src/plugins/jx3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,19 @@ async def _():

ws_recev = on(type="WsRecv", priority=5, block=False)
@ws_recev.handle()
async def _(bot: Bot, event: RecvEvent):
message = event.get_message()
if message == "False":
async def on_ws_recev(bot: Bot, event: RecvEvent):
message = event.user_message_type
if not message:
return
groups = await bot.call_api("get_group_list")
for i in groups:
group = i["group_id"]
subscribe = json.loads(read(DATA + "/" + str(group) + "/subscribe.json"))
if message["type"] in subscribe:
if message["type"] == "玄晶":
group_info = json.loads(read(DATA + "/" + str(group) + "/jx3group.json"))
if group_info["server"] != message["server"] and group_info["server"] != "":
continue
elif message["type"] == "818":
group_info = json.loads(read(DATA + "/" + str(group) + "/jx3group.json"))
if group_info["server"] != "" and group_info["server"] != message["server"] and message["name"] != "剑网3":
continue
subscribe = json.loads(read(f"{DATA}{os.sep}{group}{os.sep}subscribe.json"))
if message in subscribe:
to_send_messagee = event.render_message(group)
if not to_send_messagee:
return # 无消息发送则退出
try:
await bot.call_api("send_group_msg", group_id = group, message = message["msg"])
await bot.call_api("send_group_msg", group_id = group, message = to_send_messagee)
except:
logger.info(f"向群({i})推送失败,可能是因为风控、禁言或者未加入该群。")
4 changes: 2 additions & 2 deletions src/tools/dep/jx3/jx3apiws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ async def _handle_msg(self, message: str):
try:
ws_obj = json.loads(message)
data = WsData.parse_obj(ws_obj)
event = EventRister.get_event(data)
event = EventRegister.get_event(data)
if event:
logger.debug(event.log)
logger.debug(f'ws_event:{event.log}')
bots = get_bots()
for _, one_bot in bots.items():
await handle_event(one_bot, event)
Expand Down
Loading

0 comments on commit 4b5c0af

Please sign in to comment.