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

feat: 牛牛夺舍plus #116

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: 牛牛夺舍plus
顺便改了类型返回兼容

BREAKING CHANGE: 移除了默认启动的nonebot_go_cqhttp插件

Closes #113
  • Loading branch information
mxcoras committed Sep 7, 2024
commit 6c343158a5e487679a10214b8b36ce921cf2e489
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ nonebot-plugin-gocqhttp = "^0.6.4"
nb-cli = "^1.2.0"

[tool.nonebot]
plugins = ["nonebot_plugin_apscheduler", "nonebot_plugin_gocqhttp"]
plugins = ["nonebot_plugin_apscheduler"]
plugin_dirs = ["src/plugins"]

[build-system]
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/array2cqcode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json

from .message_segment import BaseMessageSegment
from typing import Any
from typing import Union, Any


def try_convert_to_cqcode(data: Any) -> str | Any:
def try_convert_to_cqcode(data: Any) -> Union[str, Any]:
try:
msg = json.loads(data)
if not isinstance(msg, list):
Expand Down
52 changes: 50 additions & 2 deletions src/plugins/take_name/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import random
from nonebot import require, logger, get_bot
from nonebot import require, logger, get_bot, on_notice
from nonebot.rule import Rule
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.exception import ActionFailed
from nonebot.adapters.onebot.v11 import Message
from nonebot.adapters.onebot.v11 import Message, NoticeEvent

from src.plugins.repeater.model import Chat
from src.common.config import BotConfig
Expand Down Expand Up @@ -77,3 +80,48 @@ async def change_name():
except ActionFailed:
# 可能牛牛退群了
continue


async def is_change_name_notice(bot: Bot, event: NoticeEvent, state: T_State) -> bool:
config = BotConfig(event.self_id, event.group_id)
if event.notice_type == 'group_card' and event.user_id == config.taken_name():
return True
return False


watch_name = on_notice(rule=Rule(is_change_name_notice), priority=4)


@watch_name.handle()
async def watch_name_handle(bot: Bot, event: NoticeEvent, state: T_State):
group_id = event.group_id
user_id = event.user_id

try:
info = await bot.call_api('get_group_member_info', **{
'group_id': group_id,
'user_id': user_id,
'no_cache': True
})
except ActionFailed:
return

card = info['card'] if info['card'] else info['nickname']

logger.info(
'bot [{}] watch name change by [{}] in group [{}]'.format(
bot.self_id, user_id, group_id))

config = BotConfig(bot.self_id, group_id)

try:
await bot.call_api('set_group_card', **{
'group_id': group_id,
'user_id': user_id,
'card': card
})

config.update_taken_name(user_id)

except ActionFailed:
return