Browse Source

feat: add media send limit and interval

master
zhayujie 10 months ago
parent
commit
7e0fbd600f
2 changed files with 11 additions and 1 deletions
  1. +8
    -0
      bot/linkai/link_ai_bot.py
  2. +3
    -1
      config.py

+ 8
- 0
bot/linkai/link_ai_bot.py View File

@@ -386,8 +386,14 @@ class LinkAIBot(Bot):
def _send_image(self, channel, context, image_urls): def _send_image(self, channel, context, image_urls):
if not image_urls: if not image_urls:
return return
max_send_num = conf().get("max_media_send_count")
send_interval = conf().get("media_send_interval")
try: try:
i = 0
for url in image_urls: for url in image_urls:
if max_send_num and i >= max_send_num:
continue
i += 1
if url.endswith(".mp4"): if url.endswith(".mp4"):
reply_type = ReplyType.VIDEO_URL reply_type = ReplyType.VIDEO_URL
elif url.endswith(".pdf") or url.endswith(".doc") or url.endswith(".docx"): elif url.endswith(".pdf") or url.endswith(".doc") or url.endswith(".docx"):
@@ -399,6 +405,8 @@ class LinkAIBot(Bot):
reply_type = ReplyType.IMAGE_URL reply_type = ReplyType.IMAGE_URL
reply = Reply(reply_type, url) reply = Reply(reply_type, url)
channel.send(reply, context) channel.send(reply, context)
if send_interval:
time.sleep(send_interval)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)




+ 3
- 1
config.py View File

@@ -148,7 +148,9 @@ available_setting = {
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突 "plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
# 是否使用全局插件配置 # 是否使用全局插件配置
"use_global_plugin_config": False, "use_global_plugin_config": False,
# 知识库平台配置
"max_media_send_count": 3, # 单次最大发送媒体资源的个数
"media_send_interval": 1, # 发送图片的事件间隔,单位秒
# LinkAI平台配置
"use_linkai": False, "use_linkai": False,
"linkai_api_key": "", "linkai_api_key": "",
"linkai_app_code": "", "linkai_app_code": "",


Loading…
Cancel
Save