Skip to content

Commit

Permalink
feat:增加指令前缀
Browse files Browse the repository at this point in the history
  • Loading branch information
RongRongJi committed Mar 29, 2023
1 parent 24bf3ab commit 3bf14ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ _✨ QQ群聊 语录库 ✨_

| 指令 | 需要@ | 范围 | 说明 |
|:-----:|:----:|:------:|:-----------:|
| 上传/开始上传/上传开始 | | 群聊 | 开启语录上传通道 |
| 上传/开始上传/上传开始 | 必须 | 群聊 | 开启语录上传通道 |
| 语录上传通道开启后直接发送图片 || 群聊 | 上传图片至语录库 |
| 语录 + 关键词(可选) | | 群聊 | 根据关键词返回一个符合要求的图片, 没有关键词时随机返回 |
| 语录 + #标签 | | 群聊 | 根据标签返回一个符合要求的图片, 没有关键词时随机返回 |
| 回复机器人 + 删除 | | 群聊 | 删除该条语录 |
| 语录 + 关键词(可选) | 可选 | 群聊 | 根据关键词返回一个符合要求的图片, 没有关键词时随机返回 |
| 语录 + #标签 | 可选 | 群聊 | 根据标签返回一个符合要求的图片, 没有关键词时随机返回 |
| 回复机器人 + 删除 | 可选 | 群聊 | 删除该条语录 |
| 语句中包含语录 || 群聊 | 对如何使用语录进行说明 |
| 回复机器人 + addtag + 标签(addtag和标签之间需要空格)| | 群聊 | 为该条语录增加额外标签 |
| 回复机器人 + deltag + 标签(deltag和标签之间需要空格)| | 群聊 | 为该条语录删除指定标签 |
| 回复机器人 + alltag| | 群聊 | 查看该条语录所有标签 |
| 回复机器人 + addtag + 标签(addtag和标签之间需要空格)| 可选 | 群聊 | 为该条语录增加额外标签 |
| 回复机器人 + deltag + 标签(deltag和标签之间需要空格)| 可选 | 群聊 | 为该条语录删除指定标签 |
| 回复机器人 + alltag| 可选 | 群聊 | 查看该条语录所有标签 |


## 💿 安装
Expand Down Expand Up @@ -130,7 +130,8 @@ nb plugin install nonebot-plugin-quote
| INVERTED_INDEX_PATH || 'inverted_index.json' | 必要的json文件路径, 示例"/data/inverted_index.json" |
| QUOTE_SUPERUSER || 空字典 | 白名单字典(分群) |
| GLOBAL_SUPERUSER || 空数组 | 全局管理员(可以删除每个群的语录) |
| QUOTE_NEEDAT || True | 是否需要at机器人 |
| QUOTE_NEEDAT || True | 是否需要at机器人(开启上传通道必须at) |
| QUOTE_STARTCMD || '' | 增加指令前缀 |


`RECORD_PATH``INVERTED_INDEX_PATH`只需要配置,无需创建文件;若不配置`RECORD_PATH``INVERTED_INDEX_PATH`,将会自动在项目根目录下创建了两个json文件。
Expand Down Expand Up @@ -162,6 +163,7 @@ INVERTED_INDEX_PATH=D:\your_path\inverted_index.json
QUOTE_SUPERUSER={"12345":["123456"],"54321":["123456","654321]}
GLOBAL_SUPERUSER=["6666666"]
QUOTE_NEEDAT=True
QUOTE_STARTCMD=""
```


Expand Down Expand Up @@ -216,9 +218,10 @@ nonebot.load_plugins("src/plugins", "nonebot_plugin_quote")

- 适配了一个不同版本reply格式不同的问题

### v0.3.2 (2023/3/28)
### v0.3.2 (2023/3/29)

- 增加了是否需要at机器人的选项
- 增加了指令前缀

## 🎉 鸣谢

Expand Down
20 changes: 11 additions & 9 deletions nonebot_plugin_quote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@


forward_index = inverted2forward(inverted_index)
# reply_index = {}


# 语录库
record = on_command("开始上传", aliases={"上传", '上传开始'}, priority=10, block=True, rule=to_me())
record = on_command("{}上传".format(plugin_config.quote_startcmd), priority=10, block=True, rule=to_me())
end_conversation = ['stop', '结束', '上传截图', '结束上传']


Expand Down Expand Up @@ -124,7 +125,7 @@ async def record_upload(bot: Bot, event: MessageEvent, prompt: Message = Arg(),
await record.finish('上传会话已结束')


record_pool = on_startswith('语录', priority=2, block=True, **need_at)
record_pool = on_startswith('{}语录'.format(plugin_config.quote_startcmd), priority=2, block=True, **need_at)


@record_pool.handle()
Expand All @@ -139,7 +140,7 @@ async def record_pool_handle(bot: Bot, event: Event, state: T_State):
if 'group' in session_id:

search_info = str(event.get_message()).strip()
search_info = search_info.replace('语录','').replace(' ','')
search_info = search_info.replace('{}语录'.format(plugin_config.quote_startcmd),'').replace(' ','')

tmpList = session_id.split('_')
groupNum = tmpList[1]
Expand Down Expand Up @@ -201,7 +202,7 @@ async def record_help_handle(bot: Bot, event: Event, state: T_State):
await record_help.finish()


delete_record = on_command('删除', aliases={'delete'}, **need_at)
delete_record = on_command('{}删除'.format(plugin_config.quote_startcmd), aliases={'delete'}, **need_at)

@delete_record.handle()
async def delete_record_handle(bot: Bot, event: Event, state: T_State):
Expand Down Expand Up @@ -276,7 +277,7 @@ async def delete_record_handle(bot: Bot, event: Event, state: T_State):



alltag = on_command('alltag', aliases={'标签','所有标签','展示标签','tag','Tag'}, **need_at)
alltag = on_command('{}alltag'.format(plugin_config.quote_startcmd), aliases={'{}标签'.format(plugin_config.quote_startcmd),'{}tag'.format(plugin_config.quote_startcmd)}, **need_at)

@alltag.handle()
async def alltag_handle(bot: Bot, event: Event, state: T_State):
Expand Down Expand Up @@ -337,7 +338,7 @@ async def alltag_handle(bot: Bot, event: Event, state: T_State):
await alltag.finish()


addtag = on_regex(pattern="^addtag\ ", **need_at)
addtag = on_regex(pattern="^{}addtag\ ".format(plugin_config.quote_startcmd), **need_at)

@addtag.handle()
async def addtag_handle(bot: Bot, event: Event, state: T_State):
Expand All @@ -348,7 +349,7 @@ async def addtag_handle(bot: Bot, event: Event, state: T_State):

session_id = event.get_session_id()
user_id = str(event.get_user_id())
tags = str(event.get_message()).replace('addtag', '').strip().split(' ')
tags = str(event.get_message()).replace('{}addtag'.format(plugin_config.quote_startcmd), '').strip().split(' ')

if 'group' not in session_id:
await addtag.finish()
Expand Down Expand Up @@ -401,7 +402,7 @@ async def addtag_handle(bot: Bot, event: Event, state: T_State):
await addtag.finish()


deltag = on_regex(pattern="^deltag\ ", **need_at)
deltag = on_regex(pattern="^{}deltag\ ".format(plugin_config.quote_startcmd), **need_at)

@deltag.handle()
async def deltag_handle(bot: Bot, event: Event, state: T_State):
Expand All @@ -412,7 +413,7 @@ async def deltag_handle(bot: Bot, event: Event, state: T_State):

session_id = event.get_session_id()
user_id = str(event.get_user_id())
tags = str(event.get_message()).replace('deltag', '').strip().split(' ')
tags = str(event.get_message()).replace('{}deltag'.format(plugin_config.quote_startcmd), '').strip().split(' ')

if 'group' not in session_id:
await addtag.finish()
Expand Down Expand Up @@ -463,3 +464,4 @@ async def deltag_handle(bot: Bot, event: Event, state: T_State):
})

await deltag.finish()

4 changes: 3 additions & 1 deletion nonebot_plugin_quote/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pydantic import BaseModel, Extra
from typing import List, Dict


class Config(BaseModel, extra=Extra.ignore):
record_path: str = 'record.json'
inverted_index_path: str = 'inverted_index.json'
quote_superuser: Dict[str, List[str]] = {}
global_superuser: List[str] = []
quote_needat: bool = True
quote_needat: bool = True
quote_startcmd: str = ''
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-quote"
version = "0.3.1"
version = "0.3.2"
description = "一款适用于QQ群聊天的语录库插件"
authors = ["RongRongJi <316315867@qq.com>"]
license = "MIT"
Expand Down

0 comments on commit 3bf14ce

Please sign in to comment.