Giter Site home page Giter Site logo

nonebot_plugin_smart_reply's Introduction

nonebot2智能(障)回复插件

问问提前请务必看完readme, 这是一个融合了openai, 词库的智障回复插件

提醒, openai国内服务器需要科学上网才可调用, 希望你能熟练使用v2ray或clash或其他代理软件

功能

艾特bot时回复一些基于词库的消息, 戳一戳回复特定的消息或者语音以及反戳
接入了openai apikey的接口, 详情见下文
接入了青云客的接口

词库添加关键词:

1、添加关键词 [text1] 答 [text2]		 
2、查看关键词 [text1]
3、查看所有关键词
4、删除关键词 [text1]
5、删除关键词 [text1] 删 [number]
注: 其中1,5相应器用的是on_regex, 其余全是on_command, 请注意是否需要带上.env响应头command_start
    删除关键词的[number]可以用指令第二个查询查询
    查看关键词,查看所有关键词采取的是输出图片的形式发送的, 如果这两个功能用的时候报错, 那么我猜测你的Linux没有simsun.ttc(宋体)这个字体
    解决方案: 源码内txtToImg.py中函数txt_to_img第三个参数font_path的值, 换成你系统有的字体, 或者安装simsun.ttc这个字体

安装方式:

nb plugin install nonebot-plugin-smart-reply
pip install nonebot-plugin-smart-reply
git clone https://github.com/Special-Week/nonebot_plugin_smart_reply.git
Download Zip

env配置项:

config type default example usage
bot_nickname string Bot_NICKNAME = "Hinata" 你Bot的称呼
ai_reply_private boolean false ai_reply_private = true 私聊时是否启用AI聊天
openai_api_key list openai_api_key = ["aabb114514"] openai的api_key, 详细请看下文
openai_max_tokens int 1000 openai_max_tokens = 1500 openai的max_tokens, 详细请看下文
openai_cd_time int 600 openai_cd_time = 114 openai创建会话的cd
openai_max_conversation int 10 openai_max_conversation = 10 openai的单个会话点最大交互数量
openai_proxy str "" openai_proxy = "http://127.0.0.1:1081" openai或者newbing的代理, 配置详细请看下文

.env完全不配置不影响插件运行, 但是部分功能会无法使用(openai) config这里会有一个读取superusers, 如果你env没有配置在su = random.choice(utils.superuser)这里应该会报错, 但我觉得你创建项目时应该就至少配置了一个的

对戳一戳的反应. 33%概率回复莲宝的藏话(发送语音需要配置好ffmpeg), 33%的概率回复poke__reply的内容, 剩下的概率戳回去, 如果想改概率的话, 找到@poke_.handle()下的函数, 根据注释改概率, 莲包的藏话放在了插件目录下的resource/audio, 想加可以任意

但由于优先级较低(数字越大越低), 可能被其他插件阻断, 如果没反应请查看控制台判断被哪个插件的on_message阻断了, 然后自行拉高或者降低相关响应器的优先级, 响应器见结尾

关于openai:

1. openai_api_key请注册openai后在 https://beta.openai.com/account/api-keys 自己获取
2. openai_max_tokens貌似是ai返回的文本最大多少(根据我自己用的经验)
3. openai_api_key必须配置, openai_max_tokens随意, 有默认值(1000)
4. 需要配置代理, 否则无法使用, 代理配置详细请看下文
5. 这个模块貌似不是免费的, 注册的账号只有$18.00的免费额度(现在缩成了5刀??), 请注意使用
6. openai_api_key要求你填的是list, 创建会话的时候会随机从list选一个, 你可以填多个, 注意观察加载插件的时候, log会提示你加载了几个apikey
7. 尽量保证revChatGPT模块是最新(pip install revChatGPT --upgrade)


用法:
    1. openai + 内容, 和openai发起会话, 如果没有会新建会话
    2. 重置openai, 重置openai的会话

使用了与openai通讯的接口 [ChatGPT](https://github.com/acheong08/ChatGPT)        

bopenai_proxy的配置:

1. 你需要使用v2ray或者clash等代理工具开启本地监听端口
2. 由于httpx的陈年老bug, socks5代理应该用不了, 请使用http代理 
3. 以v2rayN举例, 本地监听端口1080, 你应该配置成"http://127.0.0.1:1081"(http = socks5 + 1)
4. 以clash for windows举例, 本地监听端口7890, 你应该配置成"http://127.0.0.1:7890"

响应器:

# 戳一戳响应器 优先级1, 不会向下阻断, 条件: 戳一戳bot触发
on_notice(rule=to_me(), block=False, handlers=[key_word_module.poke_handle])
# 添加关键词响应器, 优先级11, 条件: 正则表达式
on_regex(r"^添加关键词\s*(\S+.*?)\s*答\s*(\S+.*?)\s*$", flags=re.S, block=True, priority=11, permission=SUPERUSER, handlers=[key_word_module.add_new_keyword])
# 查看所有关键词响应器, 优先级11, 条件: 命令头
on_command("查看所有关键词", aliases={"查询所有关键词"}, block=True, priority=11, permission=SUPERUSER, handlers=[key_word_module.check_all_keyword])
# 删除关键词响应器, 优先级11, 条件: 命令头
on_regex(r"^删除关键词\s*(\S+.*?)\s*删\s*(\S+.*?)\s*$", flags=re.S, priority=10, permission=SUPERUSER, handlers=[key_word_module.del_akeyword_handle])
# 删除关键词的一个回复响应器, 优先级10, 条件: 正则表达式
on_regex(r"^删除关键词\s*(\S+.*?)\s*删\s*(\S+.*?)\s*$", flags=re.S, priority=10, permission=SUPERUSER, handlers=[key_word_module.del_akeyword_handle])
# 普通回复响应器, 优先级999, 条件: 艾特bot就触发
on_message(rule=to_me(), priority=999, block=False, handlers=[key_word_module.regular_reply])
# 查看关键词响应器
on_command("查看关键词", aliases={"查询关键词"}, priority=11, block=True, permission=SUPERUSER, handlers=[key_word_module.check_keyword_handle])
# 使用openai的响应器
on_command("openai",aliases={"求助"},block=True, priority=55, handlers=[openai.openai_handle])
on_command("重置openai", aliases={"重置会话", "openai重置", "会话重置"}, priority=10, block=True, handlers=[openai.reserve_openai])

nonebot_plugin_smart_reply's People

Contributors

special-week avatar agnes4m avatar

Stargazers

FLLess avatar Lightneko avatar MrNewt avatar stars avatar Qu1n avatar  avatar  avatar  avatar HeisenBerg? avatar  avatar  avatar Wolo avatar Hongbin Mao avatar ljlVink avatar sansiny avatar Sherlocked_hzoi avatar  avatar  avatar Tim Cook avatar  avatar AICodeHunt avatar Cvandia avatar  avatar Joseph Smith avatar  avatar  avatar  avatar  avatar 毎日Flakoちゃん avatar  avatar MonianHello avatar KaMmy avatar  avatar  avatar Steven Lee avatar  avatar 浠楚 avatar emsrs avatar  avatar Info_li avatar 谢鹏 (Xie Peng) avatar  avatar  avatar  avatar  avatar Tenvi avatar 热寂 avatar ROOK avatar 久绊A avatar WuLiang avatar  avatar  avatar  avatar BENDIT avatar 杨磊 avatar blackside avatar doris_R avatar  avatar  avatar Chlorophy_Tokai avatar  avatar 月ヶ瀬 avatar  avatar  avatar Nanako avatar  avatar Maho Shojo Kierkegaard avatar  avatar Cuspis avatar 片刻 avatar  avatar  avatar  avatar DeSean Wu avatar  avatar LoCCai avatar Icetail avatar ThetaPilla. avatar

Watchers

Kostas Georgiou avatar Qu1n avatar  avatar

nonebot_plugin_smart_reply's Issues

安装问题求解...摸索十二小时没进展

我是这两天才入坑的nonebot,然后都是通过nb安装和使用的机器人,但是我不知道该怎么安装作者你这个插件.....我通过nb install那一行安装在我的bot目录后有三个问题:1.代理我不知道配在哪里,语法是什么 2.戳一戳机器人,发送音频文件时直接发送的一串代码.... 3.询问查看所有关键词没反应,控制台报错,发送openai也没反应但没报错,你好有反应。。。。现在快凌晨三点,从午休起来琢磨到现在,不知道是哪里出了问题,求作者大大解答T T

图1是戳一戳发送的代码
图2是查看所有关键词报错
image

image

如何阻断戳一戳(

我抄了一下之前的代码,但是戳一戳还是会被响应QwQ。
@attack.handle()
async def handle_receive(event: MessageEvent):
img = Path(os.path.join(os.path.dirname(__file__), "resource")) / "1.jpg"
qid = event.get_user_id()
data = read_json()
mid = event.message_id
# 写入json,记录时间和id
write_json(qid, event.time, mid, data)
await attack.send(message=f"{random.choice(attack_sendmessage)}"+MessageSegment.image(img), at_sender=True)

小爱同学 api 有时会返回空值

如题,群友问的一些稀奇古怪的东西会返回”“。
bot日志中提示向xxx发送"",可是这是空的,实际上并没有发送(
比如 小黄脸表情 和 空格 等。
即使保留纯文本的方式以提交来获取回复,但是更离谱的是……
当发送 ”钉钉“ 一些其它文本信息时,也会返回空字符串(
image
逆天,这个接口和钉钉有仇(

有没有办法可以当内容为空时用另外一个 api 回复捏QwQ
我尝试自己解决一下TAT

触发AI回复就报错,可能是我nonebot2配置问题,请指教

每次触发智障AI回复时就报如下错误,刚用不久,不太清楚原因
nonebot2版本为 bate.5

Running matcher <Matcher from src.plugins.nonebot_plugin_smart_replys, type=message, priority=99, temp=False> failed.
Traceback (most recent call last):
File "/lib/python3.8/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "
/lib/python3.8/site-packages/anyio/_core/_sockets.py", line 218, in connect_tcp
await event.wait()
File "/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 662, in aexit
raise exceptions[0]
File "
/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 733, in task_done
exc = _task.exception()
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/lib/python3.8/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
yield
File "
/lib/python3.8/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "~/lib/python3.8/site-packages/anyio/_core/_tasks.py", line 118, in exit
raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/lib/python3.8/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "
/lib/python3.8/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "
/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/lib/python3.8/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
raise exc
File "
/lib/python3.8/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
stream = await self._connect(request)
File "/lib/python3.8/site-packages/httpcore/_async/connection.py", line 111, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
File "
/lib/python3.8/site-packages/httpcore/backends/auto.py", line 29, in connect_tcp
return await self._backend.connect_tcp(
File "/lib/python3.8/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "
/lib/python3.8/contextlib.py", line 131, in exit
self.gen.throw(type, value, traceback)
File "~/lib/python3.8/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc)
httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/bin/nb", line 8, in
sys.exit(main())
File "
/lib/python3.8/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "
/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "
/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/lib/python3.8/site-packages/nb_cli/commands/main.py", line 30, in run
run_bot(file, app)
File "
/lib/python3.8/site-packages/nb_cli/handlers/deploy.py", line 25, in run_bot
nonebot.run(app=f"{module_name}:{app}")
File "/lib/python3.8/site-packages/nonebot/init.py", line 261, in run
get_driver().run(*args, **kwargs)
File "
/lib/python3.8/site-packages/nonebot/drivers/fastapi.py", line 170, in run
uvicorn.run(
File "/lib/python3.8/site-packages/uvicorn/main.py", line 575, in run
server.run()
File "
/lib/python3.8/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "
/lib/python3.8/site-packages/nonebot/message.py", line 146, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)

File "/lib/python3.8/site-packages/nonebot/message.py", line 196, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "
/lib/python3.8/site-packages/nonebot/internal/matcher.py", line 672, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "/lib/python3.8/site-packages/nonebot/internal/matcher.py", line 639, in simple_run
await handler(
File "
/lib/python3.8/site-packages/nonebot/dependencies/init.py", line 92, in call
return await self.call(**values)
File "./src/plugins/nonebot_plugin_smart_replys/init.py", line 67, in _
message = await xiaoice_reply(xiaoai_url)
File "./src/plugins/nonebot_plugin_smart_replys/utils.py", line 85, in xiaoice_reply
res = (await client.get(url)).text
File "/lib/python3.8/site-packages/httpx/_client.py", line 1751, in get
return await self.request(
File "
/lib/python3.8/site-packages/httpx/_client.py", line 1527, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/lib/python3.8/site-packages/httpx/_client.py", line 1614, in send
response = await self._send_handling_auth(
File "
/lib/python3.8/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
response = await self._send_handling_redirects(
File "/lib/python3.8/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
response = await self._send_single_request(request)
File "
/lib/python3.8/site-packages/httpx/_client.py", line 1716, in _send_single_request
response = await transport.handle_async_request(request)
File "/lib/python3.8/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "
/lib/python3.8/contextlib.py", line 131, in exit
self.gen.throw(type, value, traceback)
File "~/lib/python3.8/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectTimeout

语音发送失败

ffmpeg放到path里面了,命令行打ffmpeg也有反应,但是每次发送语音都会
nonebot.adapters.onebot.v11.exception.ActionFailed: ActionFailed(status='failed', retcode=1200, data=None, message='语音转换失败, 请检查语音文件是否正常', wording='语音转换失败, 请检查语音文件是否正常', echo='3')
python 3.10.9
nonebot2-2.3.1
nonebot-adapter-onebot-2.4.3
ffmpeg 7.0.1
pillow 9.2.0
nb也重装了,就是没找到原因😭

这个之前的青云客api为啥不让用了呀

更新了之后发现青云客的api木有了。之前还挺好用的呢【虽然是正儿八经的智障】 总比默认的智障回复强
能不能再加回去啊
ChatGPT我去年就再玩了。但是我秘钥今年4月到期了。至于那个bing那个我不知道怎么弄。也懒得配置。,我自己能访问就行。懒得弄机器人了
机器人的话主要是增添乐趣。希望作者能重新把青云客的api加到代码里面

建议

能加一个开关指令,切换到全部由API回复吗?

两个优化建议

  1. 戳一戳回复的消息能否增加图片,音频之类
  2. 回复概率能否修改,比如设置为0.5,这样更像真人

用命令添加词库

能不能就像教学一样,我在QQ里输入我说xxx你回答xxx,这样就可以让群友用爱产生词库而不用自己苦逼找文案。然后转发给管理员审核,审核通过就添加进去并回复那个人成功通过审核,不通过就回复不行啥的。QAQ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.