Skip to main content

nonebot多平台账户信息绑定

Project description

nonebot_plugin_bind

pypi python pypi

适配支持

  • onebotv11
  • telegram
  • discord
  • kook(开黑啦)
  • villa(大别野)
  • 飞书

使用说明

用户使用说明

命令 限制 含义
'bind' 群聊或私聊 将其他通用账户绑定至当前通用账户
'bindinfo' 仅私聊 查看当前通用账户的平台账户绑定信息
'rebind' 仅私聊 取消本平台账户和通用账户的绑定,并形成一个新的通用账户
'bind -group' 群聊或私聊 将其他通用群组绑定至当前通用群组
'bindinfo -group' 仅私聊 查看当前通用群组的平台群组绑定信息
'rebind -group' 仅私聊 取消本平台群组和通用尊祖的绑定,并形成一个新的通用群组

配置项

请使用Webui 进行配置,默认端口为8666,ip为主机对应ip,默认本地地址为http: //127.0.0.1:8666

配置名 默认 含义
bind_superuser [] bind的superuser,用以管理群组绑定,注意填写的值应该是通过bindinfo查询出的id,而不是你的某个社交平台的账户
bind_group_admin False 是否允许某社交平台的群组的管理员直接管理其群组绑定,不管他是否是bind_superuser

具体使用请看下图流程示例(群聊绑定同理)
(如果是在群聊中发起的绑定,不会显示下面的绑定信息,只会显示其他内容)
使用qq发送bind命令
使用discord发送bind命令和token
使用qq发送密钥确认绑定
取消绑定

开发者说明

主要提供两个依赖注入

  1. GetUser:返回一个User实例,其属性id为一个通用账户的唯一标识,其属性platform_users中包含绑定的所有平台账户的信息
  2. GetGroup:返回一个Group实例,其属性id为一个通用群组的唯一标识,其属性platform_groups中包含所有绑定的平台群组的信息( 其中groupid是对应平台群组的id)(如果不想在匹配非群组消息时跳过matcher,请使用Optional类型注释)

示例代码如下

from typing import Annotated

from nonebot import require

require('nonebot_plugin_bind')

from nonebot_plugin_bind import GetUser, GetGroup, GetGroupId, User, Group

# 此处省略了部分import

bind_info = on_alconna(Alconna(Command_Start, "bindinfo", Option("-group")))


@bind_info.assign("$main")
async def bind_info_(
        event: Event, bot: Bot, matcher: Matcher, user: Annotated[User, GetUser()]
):
    user_str = "\n".join(
        pg + "  √" if event.get_user_id() in pg else pg for pg in str(user).split("\n")
    )
    if _is_private_(event, bot):
        await matcher.finish(f"当前通用账户的绑定的平台账户如下:\n{str(user_str)}")
    else:
        await matcher.finish("账户绑定信息只能在私聊中查看")


@bind_info.assign("group")
async def bind_info_group(
        matcher: Matcher,
        group: Optional[Group] = GetGroup(),
        groupid: Optional[str] = GetGroupId(),
):
    # 如果在私聊中发送此命令,得到的group会是None,groupid也是如此 
    if group is None:
        await matcher.finish("本命令只能在各平台的群聊中使用,私聊中无法使用")
    group_str = "\n".join(
        pg + "  √" if groupid in pg else pg for pg in str(group).split("\n")
    )
    await matcher.send(f"当前通用群组的绑定的平台群组如下:\n{group_str}")


_bind_ = on_alconna(
    Alconna(Command_Start, "bind", Option("token", Args["token_value", str]))
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_bind-0.2.2.tar.gz (10.0 kB view hashes)

Uploaded Source

Built Distribution

nonebot_plugin_bind-0.2.2-py3-none-any.whl (12.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page