diff --git a/README.md b/README.md
index 2b62e687c..75fd6c4d3 100644
--- a/README.md
+++ b/README.md
@@ -6,8 +6,6 @@
# AstrBot
-*✨ 2024 - 希望成为一个跨平台、极易上手、稳定安全的机器人项目。✨*
-
[](https://github.com/Soulter/AstrBot/releases/latest)
@@ -17,10 +15,9 @@
-项目主页(开发中) |
-部署文档 |
+项目部署 |
问题提交 |
-插件开发(最少只需 25 行,真不难!)
+插件开发(最少只需 25 行)
## 🤔您可能想了解的
diff --git a/model/command/command.py b/model/command/command.py
index fecf3366a..a518e344b 100644
--- a/model/command/command.py
+++ b/model/command/command.py
@@ -81,7 +81,7 @@ class Command:
if self.command_start_with(message, "plugin"):
return True, self.plugin_oper(message, role, cached_plugins, platform)
if self.command_start_with(message, "myid") or self.command_start_with(message, "!myid"):
- return True, self.get_my_id(message_obj)
+ return True, self.get_my_id(message_obj, platform)
if self.command_start_with(message, "nconf") or self.command_start_with(message, "newconf"):
return True, self.get_new_conf(message, role)
if self.command_start_with(message, "web"): # 网页搜索
@@ -104,8 +104,14 @@ class Command:
return True, "已关闭网页搜索", "web"
return True, f"网页搜索功能当前状态: {self.global_object.web_search}", "web"
- def get_my_id(self, message_obj):
- return True, f"你的ID:{str(message_obj.sender.tiny_id)}", "plugin"
+ def get_my_id(self, message_obj, platform):
+ user_id = "Unknown"
+ if platform == PLATFORM_QQCHAN:
+ user_id = str(message_obj.sender.tiny_id)
+ elif platform == PLATFORM_GOCQ:
+ user_id = str(message_obj.user_id)
+
+ return True, f"你的ID:{user_id}", "plugin"
def get_new_conf(self, message, role):
if role != "admin":
diff --git a/model/platform/qq_gocq.py b/model/platform/qq_gocq.py
index 80b52072c..85eac2d1b 100644
--- a/model/platform/qq_gocq.py
+++ b/model/platform/qq_gocq.py
@@ -8,7 +8,8 @@ from nakuru import (
GroupMessage,
FriendMessage,
GroupMemberIncrease,
- Notify
+ Notify,
+ Member
)
from typing import Union
import time
@@ -38,12 +39,10 @@ class QQGOCQ(Platform):
try:
self.nick_qq = cfg['nick_qq']
except:
- self.nick_qq = ("ai","!","!")
+ self.nick_qq = ["ai","!","!"]
nick_qq = self.nick_qq
if isinstance(nick_qq, str):
- nick_qq = (nick_qq,)
- if isinstance(nick_qq, list):
- nick_qq = tuple(nick_qq)
+ nick_qq = [nick_qq]
self.unique_session = cfg['uniqueSessionMode']
self.pic_mode = cfg['qq_pic_mode']
@@ -61,11 +60,9 @@ class QQGOCQ(Platform):
async def _(app: CQHTTP, source: GroupMessage):
if self.cc.get("gocq_react_group", True):
if isinstance(source.message[0], Plain):
- # await self.handle_msg(source, True)
self.new_sub_thread(self.handle_msg, (source, True))
elif isinstance(source.message[0], At):
if source.message[0].qq == source.self_id:
- # await self.handle_msg(source, True)
self.new_sub_thread(self.handle_msg, (source, True))
else:
return
@@ -74,7 +71,6 @@ class QQGOCQ(Platform):
async def _(app: CQHTTP, source: FriendMessage):
if self.cc.get("gocq_react_friend", True):
if isinstance(source.message[0], Plain):
- # await self.handle_msg(source, False)
self.new_sub_thread(self.handle_msg, (source, False))
else:
return
@@ -113,22 +109,25 @@ class QQGOCQ(Platform):
async def handle_msg(self, message: Union[GroupMessage, FriendMessage, GuildMessage, Notify], is_group: bool):
# 判断是否响应消息
resp = False
- for i in message.message:
- if isinstance(i, At):
- if message.type == "GuildMessage":
- if i.qq == message.user_id or i.qq == message.self_tiny_id:
- resp = True
- if message.type == "FriendMessage":
- if i.qq == message.self_id:
- resp = True
- if message.type == "GroupMessage":
- if i.qq == message.self_id:
- resp = True
- elif isinstance(i, Plain):
- for nick in self.nick_qq:
- if nick != '' and i.text.strip().startswith(nick):
- resp = True
- break
+ if not is_group:
+ resp = True
+ else:
+ for i in message.message:
+ if isinstance(i, At):
+ if message.type == "GuildMessage":
+ if i.qq == message.user_id or i.qq == message.self_tiny_id:
+ resp = True
+ if message.type == "FriendMessage":
+ if i.qq == message.self_id:
+ resp = True
+ if message.type == "GroupMessage":
+ if i.qq == message.self_id:
+ resp = True
+ elif isinstance(i, Plain):
+ for nick in self.nick_qq:
+ if nick != '' and i.text.strip().startswith(nick):
+ resp = True
+ break
if not resp: return
diff --git a/model/provider/openai_official.py b/model/provider/openai_official.py
index aedf0bbaa..2a1ade62f 100644
--- a/model/provider/openai_official.py
+++ b/model/provider/openai_official.py
@@ -31,7 +31,7 @@ class ProviderOpenAIOfficial(Provider):
if cfg['key'] != '' and cfg['key'] != None:
self.key_list = cfg['key']
else:
- input("[System] 请先去完善ChatGPT的Key。详情请前往https://beta.openai.com/account/api-keys")
+ input("[System] 请先填写 Key。详情请前往 https://beta.openai.com/account/api-keys 或使用中转 Key 方案。")
if len(self.key_list) == 0:
raise Exception("您打开了 OpenAI 模型服务,但是未填写 key。请前往填写。")
diff --git a/util/function_calling/gplugin.py b/util/function_calling/gplugin.py
index d6a4f4f14..8cba715aa 100644
--- a/util/function_calling/gplugin.py
+++ b/util/function_calling/gplugin.py
@@ -53,6 +53,7 @@ def google_web_search(keyword) -> str:
for i in ls:
desc = i.description
try:
+ gu.log(f"搜索网页: {i.url}", tag="网页搜索", level=gu.LEVEL_INFO)
desc = fetch_website_content(i.url)
except BaseException as e:
print(f"(google) fetch_website_content err: {str(e)}")
@@ -74,51 +75,54 @@ def web_keyword_search_via_bing(keyword) -> str:
}
url = "https://www.bing.com/search?q="+keyword
_cnt = 0
- _detail_store = []
+ # _detail_store = []
while _cnt < 5:
try:
response = requests.get(url, headers=headers)
response.encoding = "utf-8"
gu.log(f"bing response: {response.text}", tag="bing", level=gu.LEVEL_DEBUG, max_len=9999)
soup = BeautifulSoup(response.text, "html.parser")
- res = []
+ res = ""
+ result_cnt = 0
ols = soup.find(id="b_results")
for i in ols.find_all("li", class_="b_algo"):
try:
title = i.find("h2").text
desc = i.find("p").text
link = i.find("h2").find("a").get("href")
- res.append({
- "title": title,
- "desc": desc,
- "link": link,
- })
- if len(res) >= 5: # 限制5条
- break
- if len(_detail_store) >= 3:
- continue
+ # res.append({
+ # "title": title,
+ # "desc": desc,
+ # "link": link,
+ # })
+ try:
+ gu.log(f"搜索网页: {link}", tag="网页搜索", level=gu.LEVEL_INFO)
+ desc = fetch_website_content(link)
+ except BaseException as e:
+ print(f"(bing) fetch_website_content err: {str(e)}")
- # 爬取前两条的网页内容
- if "zhihu.com" in link:
- try:
- _detail_store.append(special_fetch_zhihu(link))
- except BaseException as e:
- print(f"zhihu parse err: {str(e)}")
- else:
- try:
- _detail_store.append(fetch_website_content(link))
- except BaseException as e:
- print(f"fetch_website_content err: {str(e)}")
+ res += f"# No.{str(result_cnt + 1)}\ntitle: {title}\nurl: {link}\ncontent: {desc}\n\n"
+ result_cnt += 1
+ if result_cnt > 5: break
+
+ # if len(_detail_store) >= 3:
+ # continue
+ # # 爬取前两条的网页内容
+ # if "zhihu.com" in link:
+ # try:
+ # _detail_store.append(special_fetch_zhihu(link))
+ # except BaseException as e:
+ # print(f"zhihu parse err: {str(e)}")
+ # else:
+ # try:
+ # _detail_store.append(fetch_website_content(link))
+ # except BaseException as e:
+ # print(f"fetch_website_content err: {str(e)}")
except Exception as e:
print(f"bing parse err: {str(e)}")
- if len(res) == 0:
- break
- if len(_detail_store) > 0:
- ret = f"{str(res)} \n具体网页内容: {str(_detail_store)}"
- else:
- ret = f"{str(res)}"
- return str(ret)
+ if result_cnt == 0: break
+ return res
except Exception as e:
gu.log(f"bing fetch err: {str(e)}")
_cnt += 1
@@ -175,26 +179,6 @@ def fetch_website_content(url):
}
response = requests.get(url, headers=headers, timeout=3)
response.encoding = "utf-8"
- # soup = BeautifulSoup(response.text, "html.parser")
- # # 如果有container / content / main等的话,就只取这些部分
- # has = False
- # beleive_ls = ["container", "content", "main"]
- # res = ""
- # for cls in beleive_ls:
- # for i in soup.find_all(class_=cls):
- # has = True
- # res += i.text
- # if not has:
- # res = soup.text
- # res = res.replace("\n", "").replace(" ", " ").replace("\r", "").replace("\t", "")
- # if not has:
- # res = res[300:1100]
- # else:
- # res = res[100:800]
- # # with open(f"temp_{time.time()}.html", "w", encoding="utf-8") as f:
- # # f.write(res)
- # gu.log(f"fetch_website_content: end", tag="fetch_website_content", level=gu.LEVEL_DEBUG)
- # return res
doc = Document(response.content)
# print('title:', doc.title())
ret = doc.summary(html_partial=True)
@@ -213,7 +197,7 @@ def web_search(question, provider: Provider, session_id, official_fc=False):
"description": "google search query (分词,尽量保留所有信息)"
}],
"通过搜索引擎搜索。如果问题需要在网页上搜索(如天气、新闻或任何需要通过网页获取信息的问题),则调用此函数;如果没有,不要调用此函数。",
- google_web_search
+ web_keyword_search_via_bing
)
new_func_call.add_func("fetch_website_content", [{
"type": "string",
@@ -259,13 +243,20 @@ def web_search(question, provider: Provider, session_id, official_fc=False):
if has_func:
provider.forget(session_id)
- question3 = f"""请你用活泼的语气回答`{question}`问题。\n以下是相关材料,请直接拿此材料针对问题进行总结回答。在文章末尾加上各参考链接,如`[1]