mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 21:06:03 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61c29829ed | ||
|
|
5afcc03e8b | ||
|
|
fbeb4673f4 | ||
|
|
4aba319560 | ||
|
|
74f79e002c | ||
|
|
2668ef2b3f | ||
|
|
74c018e271 | ||
|
|
64776fd601 | ||
|
|
ffef944119 |
@@ -115,10 +115,9 @@
|
|||||||
|
|
||||||
### - 注册OpenAI账号
|
### - 注册OpenAI账号
|
||||||
|
|
||||||
**可以直接进群找群主购买**
|
参考以下文章自行注册
|
||||||
或参考以下文章自行注册
|
|
||||||
|
|
||||||
> ~~[只需 1 元搞定 ChatGPT 注册](https://zhuanlan.zhihu.com/p/589470082)~~(已失效)
|
> [国内注册ChatGPT的方法(100%可用)](https://www.pythonthree.com/register-openai-chatgpt/)
|
||||||
> [手把手教你如何注册ChatGPT,超级详细](https://guxiaobei.com/51461)
|
> [手把手教你如何注册ChatGPT,超级详细](https://guxiaobei.com/51461)
|
||||||
|
|
||||||
注册成功后请前往[个人中心查看](https://beta.openai.com/account/api-keys)api_key
|
注册成功后请前往[个人中心查看](https://beta.openai.com/account/api-keys)api_key
|
||||||
|
|||||||
@@ -183,6 +183,12 @@ blob_message_threshold = 256
|
|||||||
# - "forward": 将长消息转换为转发消息组件发送
|
# - "forward": 将长消息转换为转发消息组件发送
|
||||||
blob_message_strategy = "forward"
|
blob_message_strategy = "forward"
|
||||||
|
|
||||||
|
# 文字转图片时使用的字体文件路径
|
||||||
|
# 当策略为"image"时生效
|
||||||
|
# 若在Windows系统下,程序会自动使用Windows自带的微软雅黑字体
|
||||||
|
# 若未填写或不存在且不是Windows,将禁用文字转图片功能,改为使用转发消息组件
|
||||||
|
font_path = ""
|
||||||
|
|
||||||
# 消息处理超时重试次数
|
# 消息处理超时重试次数
|
||||||
retry_times = 3
|
retry_times = 3
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -7,13 +7,15 @@ import pkg.utils.context
|
|||||||
import pkg.plugin.host
|
import pkg.plugin.host
|
||||||
|
|
||||||
|
|
||||||
def walk(module, prefix=''):
|
def walk(module, prefix='', path_prefix=''):
|
||||||
"""遍历并重载所有模块"""
|
"""遍历并重载所有模块"""
|
||||||
for item in pkgutil.iter_modules(module.__path__):
|
for item in pkgutil.iter_modules(module.__path__):
|
||||||
if item.ispkg:
|
if item.ispkg:
|
||||||
walk(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.')
|
|
||||||
|
walk(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.', path_prefix + item.name + '/')
|
||||||
else:
|
else:
|
||||||
logging.info('reload module: {}'.format(prefix + item.name))
|
logging.info('reload module: {}, path: {}'.format(prefix + item.name, path_prefix + item.name + '.py'))
|
||||||
|
pkg.plugin.host.__current_module_path__ = "plugins/" + path_prefix + item.name + '.py'
|
||||||
importlib.reload(__import__(module.__name__ + '.' + item.name, fromlist=['']))
|
importlib.reload(__import__(module.__name__ + '.' + item.name, fromlist=['']))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,37 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import config
|
||||||
|
import traceback
|
||||||
|
|
||||||
text_render_font = ImageFont.truetype("res/simhei.ttf", 32, encoding="utf-8")
|
text_render_font: ImageFont = None
|
||||||
|
|
||||||
|
if hasattr(config, "blob_message_strategy") and config.blob_message_strategy == "image": # 仅在启用了image时才加载字体
|
||||||
|
use_font = config.font_path if hasattr(config, "font_path") else ""
|
||||||
|
try:
|
||||||
|
|
||||||
|
# 检查是否存在
|
||||||
|
if not os.path.exists(use_font):
|
||||||
|
# 若是windows系统,使用微软雅黑
|
||||||
|
if os.name == "nt":
|
||||||
|
use_font = "C:/Windows/Fonts/msyh.ttc"
|
||||||
|
if not os.path.exists(use_font):
|
||||||
|
logging.warn("未找到字体文件,且无法使用Windows自带字体,更换为转发消息组件以发送长消息,您可以在config.py中调整相关设置。")
|
||||||
|
config.blob_message_strategy = "forward"
|
||||||
|
else:
|
||||||
|
logging.info("使用Windows自带字体:" + use_font)
|
||||||
|
text_render_font = ImageFont.truetype(use_font, 32, encoding="utf-8")
|
||||||
|
else:
|
||||||
|
logging.warn("未找到字体文件,且无法使用Windows自带字体,更换为转发消息组件以发送长消息,您可以在config.py中调整相关设置。")
|
||||||
|
config.blob_message_strategy = "forward"
|
||||||
|
else:
|
||||||
|
text_render_font = ImageFont.truetype(use_font, 32, encoding="utf-8")
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
logging.error("加载字体文件失败({}),更换为转发消息组件以发送长消息,您可以在config.py中调整相关设置。".format(use_font))
|
||||||
|
config.blob_message_strategy = "forward"
|
||||||
|
|
||||||
|
|
||||||
def indexNumber(path=''):
|
def indexNumber(path=''):
|
||||||
@@ -123,7 +152,7 @@ def text_to_image(text_str: str, save_as="temp.png", width=800):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
# 准备画布
|
# 准备画布
|
||||||
img = Image.new('RGBA', (width, max(280, len(final_lines) * 35 + 45)), (255, 255, 255, 255))
|
img = Image.new('RGBA', (width, max(280, len(final_lines) * 35 + 65)), (255, 255, 255, 255))
|
||||||
draw = ImageDraw.Draw(img, mode='RGBA')
|
draw = ImageDraw.Draw(img, mode='RGBA')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -152,24 +152,12 @@ def get_remote_url(repo_path: str) -> str:
|
|||||||
|
|
||||||
def get_current_version_info() -> str:
|
def get_current_version_info() -> str:
|
||||||
"""获取当前版本信息"""
|
"""获取当前版本信息"""
|
||||||
check_dulwich_closure()
|
rls_list = get_release_list()
|
||||||
|
current_tag = get_current_tag()
|
||||||
from dulwich import porcelain
|
for rls in rls_list:
|
||||||
|
if rls['tag_name'] == current_tag:
|
||||||
repo = porcelain.open_repo('.')
|
return rls['name'] + "\n" + rls['body']
|
||||||
|
return "未知版本"
|
||||||
version_str = ""
|
|
||||||
|
|
||||||
for entry in repo.get_walker():
|
|
||||||
version_str += "提交编号: "+str(entry.commit.id)[2:9] + "\n"
|
|
||||||
tz = datetime.timezone(datetime.timedelta(hours=entry.commit.commit_timezone // 3600))
|
|
||||||
dt = datetime.datetime.fromtimestamp(entry.commit.commit_time, tz)
|
|
||||||
version_str += "时间: "+dt.strftime('%m-%d %H:%M:%S') + "\n"
|
|
||||||
version_str += "说明: "+str(entry.commit.message, encoding="utf-8").strip() + "\n"
|
|
||||||
version_str += "提交作者: '" + str(entry.commit.author)[2:-1] + "'"
|
|
||||||
break
|
|
||||||
|
|
||||||
return version_str
|
|
||||||
|
|
||||||
|
|
||||||
def get_commit_id_and_time_and_msg() -> str:
|
def get_commit_id_and_time_and_msg() -> str:
|
||||||
|
|||||||
BIN
res/simhei.ttf
BIN
res/simhei.ttf
Binary file not shown.
Reference in New Issue
Block a user