mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 12:56:02 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8dbd426ae | ||
|
|
40d6e809a0 | ||
|
|
236c540d18 | ||
|
|
d6ca059f6c | ||
|
|
52c06a60ca | ||
|
|
6353644ec3 | ||
|
|
20df9ded3d | ||
|
|
7569b18a4c | ||
|
|
b9da4f4951 | ||
|
|
89b9e29257 | ||
|
|
d605de9de4 |
2
.github/pull_request_template.md
vendored
2
.github/pull_request_template.md
vendored
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
### 事务
|
### 事务
|
||||||
|
|
||||||
- [ ] 已阅读仓库[贡献指引](../CONTRIBUTING.md)
|
- [ ] 已阅读仓库[贡献指引](https://github.com/RockChinQ/QChatGPT/blob/master/CONTRIBUTING.md)
|
||||||
- [ ] 已与维护者在issues或其他平台沟通此PR大致内容
|
- [ ] 已与维护者在issues或其他平台沟通此PR大致内容
|
||||||
|
|
||||||
## 以下内容可在起草PR后、合并PR前逐步完成
|
## 以下内容可在起草PR后、合并PR前逐步完成
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,5 +17,6 @@ scenario/
|
|||||||
override.json
|
override.json
|
||||||
cookies.json
|
cookies.json
|
||||||
res/announcement_saved
|
res/announcement_saved
|
||||||
|
res/announcement_saved.json
|
||||||
cmdpriv.json
|
cmdpriv.json
|
||||||
tips.py
|
tips.py
|
||||||
@@ -212,6 +212,12 @@ blob_message_threshold = 256
|
|||||||
# - "forward": 将长消息转换为转发消息组件发送
|
# - "forward": 将长消息转换为转发消息组件发送
|
||||||
blob_message_strategy = "forward"
|
blob_message_strategy = "forward"
|
||||||
|
|
||||||
|
# 允许等待
|
||||||
|
# 同一会话内,是否等待上一条消息处理完成后再处理下一条消息
|
||||||
|
# 若设置为False,若上一条未处理完时收到了新消息,将会丢弃新消息
|
||||||
|
# 丢弃消息时的提示信息可以在tips.py中修改
|
||||||
|
wait_last_done = True
|
||||||
|
|
||||||
# 文字转图片时使用的字体文件路径
|
# 文字转图片时使用的字体文件路径
|
||||||
# 当策略为"image"时生效
|
# 当策略为"image"时生效
|
||||||
# 若在Windows系统下,程序会自动使用Windows自带的微软雅黑字体
|
# 若在Windows系统下,程序会自动使用Windows自带的微软雅黑字体
|
||||||
@@ -233,11 +239,11 @@ hide_exce_info_to_user = False
|
|||||||
sys_pool_num = 8
|
sys_pool_num = 8
|
||||||
|
|
||||||
# 执行管理员请求和指令的线程池并行线程数量,一般和管理员数量相等
|
# 执行管理员请求和指令的线程池并行线程数量,一般和管理员数量相等
|
||||||
admin_pool_num = 2
|
admin_pool_num = 4
|
||||||
|
|
||||||
# 执行用户请求和指令的线程池并行线程数量
|
# 执行用户请求和指令的线程池并行线程数量
|
||||||
# 如需要更高的并发,可以增大该值
|
# 如需要更高的并发,可以增大该值
|
||||||
user_pool_num = 6
|
user_pool_num = 8
|
||||||
|
|
||||||
# 每个会话的过期时间,单位为秒
|
# 每个会话的过期时间,单位为秒
|
||||||
# 默认值20分钟
|
# 默认值20分钟
|
||||||
|
|||||||
5
main.py
5
main.py
@@ -303,8 +303,9 @@ def start(first_time_init=False):
|
|||||||
try:
|
try:
|
||||||
import pkg.utils.announcement as announcement
|
import pkg.utils.announcement as announcement
|
||||||
new_announcement = announcement.fetch_new()
|
new_announcement = announcement.fetch_new()
|
||||||
if new_announcement != "":
|
if len(new_announcement) > 0:
|
||||||
logging.critical("[公告] {}".format(new_announcement))
|
for announcement in new_announcement:
|
||||||
|
logging.critical("[公告]<{}> {}".format(announcement['time'], announcement['content']))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning("获取公告失败:{}".format(e))
|
logging.warning("获取公告失败:{}".format(e))
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,13 @@
|
|||||||
"show_prefix": false,
|
"show_prefix": false,
|
||||||
"blob_message_threshold": 256,
|
"blob_message_threshold": 256,
|
||||||
"blob_message_strategy": "forward",
|
"blob_message_strategy": "forward",
|
||||||
|
"wait_last_done": true,
|
||||||
"font_path": "",
|
"font_path": "",
|
||||||
"retry_times": 3,
|
"retry_times": 3,
|
||||||
"hide_exce_info_to_user": false,
|
"hide_exce_info_to_user": false,
|
||||||
"sys_pool_num": 8,
|
"sys_pool_num": 8,
|
||||||
"admin_pool_num": 2,
|
"admin_pool_num": 4,
|
||||||
"user_pool_num": 6,
|
"user_pool_num": 8,
|
||||||
"session_expire_time": 1200,
|
"session_expire_time": 1200,
|
||||||
"rate_limitation": {
|
"rate_limitation": {
|
||||||
"default": 60
|
"default": 60
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||||||
logging.info("根据忽略规则忽略消息: {}".format(text_message))
|
logging.info("根据忽略规则忽略消息: {}".format(text_message))
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
if not config.wait_last_done and session_name in processing:
|
||||||
|
return MessageChain([Plain(tips_custom.message_drop_tip)])
|
||||||
|
|
||||||
# 检查是否被禁言
|
# 检查是否被禁言
|
||||||
if launcher_type == 'group':
|
if launcher_type == 'group':
|
||||||
result = mgr.bot.member_info(target=launcher_id, member_id=mgr.bot.qq).get()
|
result = mgr.bot.member_info(target=launcher_id, member_id=mgr.bot.qq).get()
|
||||||
@@ -79,9 +84,6 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||||||
|
|
||||||
# 处理消息
|
# 处理消息
|
||||||
try:
|
try:
|
||||||
if session_name in processing:
|
|
||||||
pkg.openai.session.get_session(session_name).release_response_lock()
|
|
||||||
return MessageChain([Plain("[bot]err:正在处理中,请稍后再试")])
|
|
||||||
|
|
||||||
config = pkg.utils.context.get_config()
|
config = pkg.utils.context.get_config()
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,68 @@
|
|||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import pkg.utils.network as network
|
|
||||||
|
|
||||||
|
def read_latest() -> list:
|
||||||
def read_latest() -> str:
|
import pkg.utils.network as network
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement",
|
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement.json",
|
||||||
proxies=network.wrapper_proxies()
|
proxies=network.wrapper_proxies()
|
||||||
)
|
)
|
||||||
obj_json = resp.json()
|
obj_json = resp.json()
|
||||||
b64_content = obj_json["content"]
|
b64_content = obj_json["content"]
|
||||||
# 解码
|
# 解码
|
||||||
content = base64.b64decode(b64_content).decode("utf-8")
|
content = base64.b64decode(b64_content).decode("utf-8")
|
||||||
return content
|
return json.loads(content)
|
||||||
|
|
||||||
|
|
||||||
def read_saved() -> str:
|
def read_saved() -> list:
|
||||||
# 已保存的在res/announcement_saved
|
# 已保存的在res/announcement_saved
|
||||||
# 检查是否存在
|
# 检查是否存在
|
||||||
if not os.path.exists("res/announcement_saved"):
|
if not os.path.exists("res/announcement_saved.json"):
|
||||||
with open("res/announcement_saved", "w", encoding="utf-8") as f:
|
with open("res/announcement_saved.json", "w", encoding="utf-8") as f:
|
||||||
f.write("")
|
f.write("[]")
|
||||||
|
|
||||||
with open("res/announcement_saved", "r", encoding="utf-8") as f:
|
with open("res/announcement_saved.json", "r", encoding="utf-8") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
return content
|
return json.loads(content)
|
||||||
|
|
||||||
|
|
||||||
def write_saved(content: str):
|
def write_saved(content: list):
|
||||||
# 已保存的在res/announcement_saved
|
# 已保存的在res/announcement_saved
|
||||||
with open("res/announcement_saved", "w", encoding="utf-8") as f:
|
with open("res/announcement_saved.json", "w", encoding="utf-8") as f:
|
||||||
f.write(content)
|
f.write(json.dumps(content, indent=4, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
||||||
def fetch_new() -> str:
|
def fetch_new() -> list:
|
||||||
latest = read_latest()
|
latest = read_latest()
|
||||||
saved = read_saved()
|
saved = read_saved()
|
||||||
if latest.replace(saved, "").strip() == "":
|
|
||||||
return ""
|
to_show: list = []
|
||||||
else:
|
|
||||||
write_saved(latest)
|
for item in latest:
|
||||||
return latest.replace(saved, "").strip()
|
# 遍历saved检查是否有相同id的公告
|
||||||
|
for saved_item in saved:
|
||||||
|
if saved_item["id"] == item["id"]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# 没有相同id的公告
|
||||||
|
to_show.append(item)
|
||||||
|
|
||||||
|
write_saved(latest)
|
||||||
|
return to_show
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
resp = requests.get(
|
||||||
|
url="https://api.github.com/repos/RockChinQ/QChatGPT/contents/res/announcement.json",
|
||||||
|
)
|
||||||
|
obj_json = resp.json()
|
||||||
|
b64_content = obj_json["content"]
|
||||||
|
# 解码
|
||||||
|
content = base64.b64decode(b64_content).decode("utf-8")
|
||||||
|
print(json.dumps(json.loads(content), indent=4, ensure_ascii=False))
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
1
res/announcement.json
Normal file
1
res/announcement.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
32
res/scripts/publish_announcement.py
Normal file
32
res/scripts/publish_announcement.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# 输出工作路径
|
||||||
|
import os
|
||||||
|
print("工作路径: " + os.getcwd())
|
||||||
|
announcement = input("请输入公告内容: ")
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
# 读取现有的公告文件 res/announcement.json
|
||||||
|
with open("res/announcement.json", "r", encoding="utf-8") as f:
|
||||||
|
announcement_json = json.load(f)
|
||||||
|
|
||||||
|
# 将公告内容写入公告文件
|
||||||
|
|
||||||
|
# 当前自然时间
|
||||||
|
import time
|
||||||
|
now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
|
|
||||||
|
# 获取最后一个公告的id
|
||||||
|
last_id = announcement_json[-1]["id"] if len(announcement_json) > 0 else -1
|
||||||
|
|
||||||
|
announcement = {
|
||||||
|
"id": last_id + 1,
|
||||||
|
"time": now,
|
||||||
|
"timestamp": int(time.time()),
|
||||||
|
"content": announcement
|
||||||
|
}
|
||||||
|
|
||||||
|
announcement_json.append(announcement)
|
||||||
|
|
||||||
|
# 将公告写入公告文件
|
||||||
|
with open("res/announcement.json", "w", encoding="utf-8") as f:
|
||||||
|
json.dump(announcement_json, f, indent=4, ensure_ascii=False)
|
||||||
@@ -9,6 +9,11 @@ alter_tip_message = '[bot]err:出错了,请稍后再试'
|
|||||||
# 若设置为空字符串,则不发送提示信息
|
# 若设置为空字符串,则不发送提示信息
|
||||||
rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃"
|
rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃"
|
||||||
|
|
||||||
|
# 只允许同时处理一条消息时,新消息被丢弃时的提示信息
|
||||||
|
# 当config.py中的wait_last_done为False时生效
|
||||||
|
# 若设置为空字符串,则不发送提示信息
|
||||||
|
message_drop_tip = "[bot]当前有一条消息正在处理,请等待处理完成"
|
||||||
|
|
||||||
# 指令!help帮助消息
|
# 指令!help帮助消息
|
||||||
help_message = """此机器人通过调用大型语言模型生成回复,不具有情感。
|
help_message = """此机器人通过调用大型语言模型生成回复,不具有情感。
|
||||||
你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。
|
你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。
|
||||||
|
|||||||
Reference in New Issue
Block a user