Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 在娶和透中添加对机器人的保护 #11

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/plugins/waifu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ async def waifu_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool
msg = event.message.extract_plain_text()
if not msg.startswith("娶群友"):
return False
# 不能娶机器人
if event.to_me:
await bot.send(event, "不可以啦~", at_sender=True)
return False
group_id = event.group_id
user_id = event.user_id
protect_list = await WaifuProtect.get_or_none(group_id=group_id)
Expand Down Expand Up @@ -155,7 +159,6 @@ async def waifu_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool
)
await bot.send(event, msg, at_sender=True)
return False

if at:
if at == rec.get(str(at)):
X = HE
Expand All @@ -173,7 +176,11 @@ async def waifu_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool

if not waifu_id:
group_id = event.group_id
member_list = await bot.get_group_member_list(group_id=group_id)
member_list = [
member
for member in await bot.get_group_member_list(group_id=group_id)
if member["user_id"] != int(bot.self_id)
]
lastmonth = event.time - last_sent_time_filter
rule_out = protect_list or set(rec.keys())
waifu_ids = [
Expand Down Expand Up @@ -389,6 +396,10 @@ async def yinpa_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool
msg = event.message.extract_plain_text()
if not msg.startswith("透群友"):
return False
# 不能透机器人
if event.to_me:
await bot.send(event, "不行!", at_sender=True)
return False
group_id = event.group_id
user_id = event.user_id
protect_list, _ = await WaifuProtect.get_or_create(group_id=group_id)
Expand All @@ -402,6 +413,7 @@ async def yinpa_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool
at = at[0]
if at in protect_set:
return False

if at == user_id:
msg = f"恭喜你涩到了你自己!{MessageSegment.image(file=await user_img(user_id))}"
await bot.send(event, msg, at_sender=True)
Expand All @@ -428,6 +440,7 @@ async def yinpa_rule(bot: Bot, event: GroupMessageEvent, state: T_State) -> bool
for member in member_list
if (user_id := member["user_id"]) not in protect_set
and member["last_sent_time"] > lastmonth
and member["user_id"] != int(bot.self_id)
]
if yinpa_ids:
yinpa_id = random.choice(yinpa_ids)
Expand Down
1 change: 0 additions & 1 deletion src/plugins/waifu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import httpx
import hashlib
import asyncio

from pil_utils import BuildImage, Text2Image
from nonebot.adapters.onebot.v11 import Message

Expand Down