Skip to content

Commit

Permalink
fix: 让牛牛认识牛牛
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Jan 25, 2024
1 parent 8d8dd09 commit 6770a2b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/plugins/block/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import time
from typing import List, Union

import nonebot
from nonebot import get_bots
from nonebot.adapters import Bot
from nonebot.adapters.onebot.v11 import GroupIncreaseNoticeEvent, GroupMessageEvent, PokeNotifyEvent, permission
from nonebot.rule import Rule
Expand All @@ -28,15 +30,20 @@ def refresh_accounts(self) -> None:

with self.refresh_lock:
self.refresh_time = time.time()
self.accounts = [
go_cqhttp_plugin_accounts: list[int] = [
int(d) for d in os.listdir(self.accounts_dir) if d.isnumeric()
]
onebot_accounts: list[int] = [
int(self_id) for self_id, bot in get_bots().items() if self_id.isnumeric() and bot.type == 'onebot'
]
self.accounts = list(set(go_cqhttp_plugin_accounts + onebot_accounts))

async def is_other_bot(self, bot: Bot, event: GroupMessageEvent, state: T_State) -> bool:
self.refresh_accounts()
return event.user_id in self.accounts

async def is_sleep(self, bot: Bot, event: Union[GroupMessageEvent, GroupIncreaseNoticeEvent, PokeNotifyEvent], state: T_State) -> bool:
async def is_sleep(self, bot: Bot, event: Union[GroupMessageEvent, GroupIncreaseNoticeEvent, PokeNotifyEvent],
state: T_State) -> bool:
if not event.group_id:
return False
return BotConfig(event.self_id, event.group_id).is_sleep()
Expand All @@ -51,7 +58,6 @@ async def is_sleep(self, bot: Bot, event: Union[GroupMessageEvent, GroupIncrease
permission=permission.GROUP
)


any_msg = on_message(
priority=4,
block=True,
Expand Down

0 comments on commit 6770a2b

Please sign in to comment.