mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 12:56:02 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e85467e02 | ||
|
|
eb41cf5481 | ||
|
|
b970a42d07 | ||
|
|
8c9d123e1c | ||
|
|
ab2a95e347 | ||
|
|
2184c558a4 | ||
|
|
83cb8588fd | ||
|
|
007e82c533 | ||
|
|
499f8580a7 |
@@ -123,13 +123,36 @@ preset_mode = "normal"
|
|||||||
# 注意:由消息前缀(prefix)匹配的消息中将会删除此前缀,正则表达式(regexp)匹配的消息不会删除匹配的部分
|
# 注意:由消息前缀(prefix)匹配的消息中将会删除此前缀,正则表达式(regexp)匹配的消息不会删除匹配的部分
|
||||||
# 前缀匹配优先级高于正则表达式匹配
|
# 前缀匹配优先级高于正则表达式匹配
|
||||||
# 正则表达式简明教程:https://www.runoob.com/regexp/regexp-tutorial.html
|
# 正则表达式简明教程:https://www.runoob.com/regexp/regexp-tutorial.html
|
||||||
|
#
|
||||||
|
# 支持针对不同群设置不同的响应规则,例如:
|
||||||
|
# response_rules = {
|
||||||
|
# "default": {
|
||||||
|
# "at": True,
|
||||||
|
# "prefix": ["/ai", "!ai", "!ai", "ai"],
|
||||||
|
# "regexp": [],
|
||||||
|
# "random_rate": 0.0,
|
||||||
|
# },
|
||||||
|
# "12345678": {
|
||||||
|
# "at": False,
|
||||||
|
# "prefix": ["/ai", "!ai", "!ai", "ai"],
|
||||||
|
# "regexp": [],
|
||||||
|
# "random_rate": 0.0,
|
||||||
|
# },
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# 以上设置将会在群号为12345678的群中关闭at响应
|
||||||
|
# 未单独设置的群将使用default规则
|
||||||
response_rules = {
|
response_rules = {
|
||||||
"at": True, # 是否响应at机器人的消息
|
"default": {
|
||||||
"prefix": ["/ai", "!ai", "!ai", "ai"],
|
"at": True, # 是否响应at机器人的消息
|
||||||
"regexp": [], # "为什么.*", "怎么?样.*", "怎么.*", "如何.*", "[Hh]ow to.*", "[Ww]hy not.*", "[Ww]hat is.*", ".*怎么办", ".*咋办"
|
"prefix": ["/ai", "!ai", "!ai", "ai"],
|
||||||
"random_rate": 0.0, # 随机响应概率,0.0-1.0,0.0为不随机响应,1.0为响应所有消息, 仅在前几项判断不通过时生效
|
"regexp": [], # "为什么.*", "怎么?样.*", "怎么.*", "如何.*", "[Hh]ow to.*", "[Ww]hy not.*", "[Ww]hat is.*", ".*怎么办", ".*咋办"
|
||||||
|
"random_rate": 0.0, # 随机响应概率,0.0-1.0,0.0为不随机响应,1.0为响应所有消息, 仅在前几项判断不通过时生效
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 消息忽略规则
|
# 消息忽略规则
|
||||||
# 适用于私聊及群聊
|
# 适用于私聊及群聊
|
||||||
# 符合此规则的消息将不会被响应
|
# 符合此规则的消息将不会被响应
|
||||||
|
|||||||
@@ -27,15 +27,17 @@
|
|||||||
},
|
},
|
||||||
"preset_mode": "normal",
|
"preset_mode": "normal",
|
||||||
"response_rules": {
|
"response_rules": {
|
||||||
"at": true,
|
"default": {
|
||||||
"prefix": [
|
"at": true,
|
||||||
"/ai",
|
"prefix": [
|
||||||
"!ai",
|
"/ai",
|
||||||
"!ai",
|
"!ai",
|
||||||
"ai"
|
"!ai",
|
||||||
],
|
"ai"
|
||||||
"regexp": [],
|
],
|
||||||
"random_rate": 0.0
|
"regexp": [],
|
||||||
|
"random_rate": 0.0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"ignore_rules": {
|
"ignore_rules": {
|
||||||
"prefix": [
|
"prefix": [
|
||||||
|
|||||||
@@ -283,11 +283,11 @@ class PluginHost:
|
|||||||
|
|
||||||
def send_person_message(self, person, message):
|
def send_person_message(self, person, message):
|
||||||
"""发送私聊消息"""
|
"""发送私聊消息"""
|
||||||
asyncio.run(self.get_bot().send_friend_message(person, message))
|
self.get_bot_adapter().send_message("person", person, message)
|
||||||
|
|
||||||
def send_group_message(self, group, message):
|
def send_group_message(self, group, message):
|
||||||
"""发送群消息"""
|
"""发送群消息"""
|
||||||
asyncio.run(self.get_bot().send_group_message(group, message))
|
self.get_bot_adapter().send_message("group", group, message)
|
||||||
|
|
||||||
def notify_admin(self, message):
|
def notify_admin(self, message):
|
||||||
"""通知管理员"""
|
"""通知管理员"""
|
||||||
|
|||||||
@@ -25,10 +25,18 @@ import pkg.qqbot.adapter as msadapter
|
|||||||
|
|
||||||
|
|
||||||
# 检查消息是否符合泛响应匹配机制
|
# 检查消息是否符合泛响应匹配机制
|
||||||
def check_response_rule(text: str):
|
def check_response_rule(group_id:int, text: str):
|
||||||
config = pkg.utils.context.get_config()
|
config = pkg.utils.context.get_config()
|
||||||
|
|
||||||
rules = config.response_rules
|
rules = config.response_rules
|
||||||
|
|
||||||
|
# 检查是否有特定规则
|
||||||
|
if 'prefix' not in config.response_rules:
|
||||||
|
if str(group_id) in config.response_rules:
|
||||||
|
rules = config.response_rules[str(group_id)]
|
||||||
|
else:
|
||||||
|
rules = config.response_rules['default']
|
||||||
|
|
||||||
# 检查前缀匹配
|
# 检查前缀匹配
|
||||||
if 'prefix' in rules:
|
if 'prefix' in rules:
|
||||||
for rule in rules['prefix']:
|
for rule in rules['prefix']:
|
||||||
@@ -46,19 +54,39 @@ def check_response_rule(text: str):
|
|||||||
return False, ""
|
return False, ""
|
||||||
|
|
||||||
|
|
||||||
def response_at():
|
def response_at(group_id: int):
|
||||||
config = pkg.utils.context.get_config()
|
config = pkg.utils.context.get_config()
|
||||||
if 'at' not in config.response_rules:
|
|
||||||
|
use_response_rule = config.response_rules
|
||||||
|
|
||||||
|
# 检查是否有特定规则
|
||||||
|
if 'prefix' not in config.response_rules:
|
||||||
|
if str(group_id) in config.response_rules:
|
||||||
|
use_response_rule = config.response_rules[str(group_id)]
|
||||||
|
else:
|
||||||
|
use_response_rule = config.response_rules['default']
|
||||||
|
|
||||||
|
if 'at' not in use_response_rule:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return config.response_rules['at']
|
return use_response_rule['at']
|
||||||
|
|
||||||
|
|
||||||
def random_responding():
|
def random_responding(group_id):
|
||||||
config = pkg.utils.context.get_config()
|
config = pkg.utils.context.get_config()
|
||||||
if 'random_rate' in config.response_rules:
|
|
||||||
|
use_response_rule = config.response_rules
|
||||||
|
|
||||||
|
# 检查是否有特定规则
|
||||||
|
if 'prefix' not in config.response_rules:
|
||||||
|
if str(group_id) in config.response_rules:
|
||||||
|
use_response_rule = config.response_rules[str(group_id)]
|
||||||
|
else:
|
||||||
|
use_response_rule = config.response_rules['default']
|
||||||
|
|
||||||
|
if 'random_rate' in use_response_rule:
|
||||||
import random
|
import random
|
||||||
return random.random() < config.response_rules['random_rate']
|
return random.random() < use_response_rule['random_rate']
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -317,16 +345,16 @@ class QQBotManager:
|
|||||||
if Image in event.message_chain:
|
if Image in event.message_chain:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if At(self.bot_account_id) in event.message_chain and response_at():
|
if At(self.bot_account_id) in event.message_chain and response_at(event.group.id):
|
||||||
# 直接调用
|
# 直接调用
|
||||||
reply = process()
|
reply = process()
|
||||||
else:
|
else:
|
||||||
check, result = check_response_rule(str(event.message_chain).strip())
|
check, result = check_response_rule(event.group.id, str(event.message_chain).strip())
|
||||||
|
|
||||||
if check:
|
if check:
|
||||||
reply = process(result.strip())
|
reply = process(result.strip())
|
||||||
# 检查是否随机响应
|
# 检查是否随机响应
|
||||||
elif random_responding():
|
elif random_responding(event.group.id):
|
||||||
logging.info("随机响应group_{}消息".format(event.group.id))
|
logging.info("随机响应group_{}消息".format(event.group.id))
|
||||||
reply = process()
|
reply = process()
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
3. 打开go-cqhttp同目录的`config.yml`
|
3. 打开go-cqhttp同目录的`config.yml`
|
||||||
|
|
||||||
1. 编辑账号登录信息(可选)
|
1. 编辑账号登录信息
|
||||||
|
|
||||||
只需要修改下方`uin`和`password`为你要登录的机器人账号的QQ号和密码即可。
|
只需要修改下方`uin`和`password`为你要登录的机器人账号的QQ号和密码即可。
|
||||||
**若您不填写,将会在启动时请求扫码登录。**
|
**若您不填写,将会在启动时请求扫码登录。**
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
max-times: 0 # 最大重连次数, 0为无限制
|
max-times: 0 # 最大重连次数, 0为无限制
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 修改websocket端口(必需)
|
2. 修改websocket端口
|
||||||
|
|
||||||
在`config.yml`下方找到以下内容
|
在`config.yml`下方找到以下内容
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user