Skip to content

Commit

Permalink
Update Genshin Cos plugin version and add random image selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvandia committed Mar 9, 2024
1 parent f0f536f commit 291272d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ git clone安装(不推荐)
|cos_cd|int|30|用户触发cd|
|cos_forward_msg|bool|True|默认是否合并转发|
|cos_delay|float|0.5|当上面的配置项为`False`时,发送图片的每张延迟s|
|is_lagrange|bool|False|由于Lagrange的合并转发不符合OneBotAPI,如果您使用了Lagrange,请在使用前配置此项|

> 注意:绝对路劲中用`/`,用`\`可能会被转义
Expand Down
5 changes: 4 additions & 1 deletion nonebot_plugin_genshin_cos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
from nonebot_plugin_apscheduler import scheduler
import asyncio
import random
import re

__plugin_meta__ = PluginMetadata(
Expand All @@ -30,7 +31,7 @@
"unique_name": "genshin_cos",
"example": "保存cos:保存cos图片至本地文件",
"author": "divandia <106718176+Cvandia@users.noreply.github.com>",
"version": "0.2.6",
"version": "0.2.7",
},
)
logo = """<g>
Expand Down Expand Up @@ -386,6 +387,8 @@ async def send_images(
await matcher.send(f"获取{num}张图片中…请稍等")
msg_list = [MessageSegment.text(f"✅找到最新的一些{args[0]}图如下:✅")]
image_list = await send_type.async_get_urls()
'''random随机从列表中取出num个元素'''
image_list = [image_list[i] for i in random.sample(range(len(image_list)), num)]
if num > len(image_list):
await matcher.finish(
f"最多只能获取{len(image_list)}张图片", at_sender=True
Expand Down
21 changes: 7 additions & 14 deletions nonebot_plugin_genshin_cos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,14 @@ def to_json(msg: Message):
return {"type": "node", "data": {"name": name, "uin": uin, "content": msg}}

messages = [to_json(msg) for msg in msgs]
if IS_LAGRANGE:
res_id = await bot.call_api("send_forward_msg", messages=messages)
if isinstance(event, GroupMessageEvent):
return await bot.send_group_msg(group_id=event.group_id, message=MessageSegment.forward(res_id))
else:
return await bot.send_private_msg(user_id=event.user_id, message=MessageSegment.forward(res_id))
if isinstance(event, GroupMessageEvent):
return await bot.call_api(
"send_group_forward_msg", group_id=event.group_id, messages=messages
)
else:
if isinstance(event, GroupMessageEvent):
return await bot.call_api(
"send_group_forward_msg", group_id=event.group_id, messages=messages
)
else:
return await bot.call_api(
"send_private_forward_msg", user_id=event.user_id, messages=messages
)
return await bot.call_api(
"send_private_forward_msg", user_id=event.user_id, messages=messages
)


def msglist2forward(name: str, uin: str, msgs: list) -> list:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-genshin-cos"
version = "0.2.6"
version = "0.2.7"
description = "米游社原神cos图获取"
authors = ["Cvandia <106718176+Cvandia@users.noreply.github.com>"]
license = "MIT"
Expand Down

0 comments on commit 291272d

Please sign in to comment.