Skip to content

Commit

Permalink
https://github.com/Todysheep/nonebot_plugin_bottle/issues/89
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdaYH committed Feb 9, 2025
1 parent 31d5e79 commit 7b5e4d8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
| webui用户名 | nonebot_plugin_bottle_admin_user | str | admin |
| webui密码(若空,则每次启动时随机生成) | nonebot_plugin_bottle_admin_password | str | |
| 待审批漂流瓶是否通知管理员 | nonebot_plugin_bottle_notice_admin | bool | False |
| 待审批漂流瓶是否依旧可见,直到被拒绝 | nonebot_plugin_bottle_allow_pending_approval_to_be_viewed | bool | False |
## 更新日志
- 2.1.0.0 [2024-08-29] [#79](https://github.com/Todysheep/nonebot_plugin_bottle/pull/79)
Expand Down
7 changes: 4 additions & 3 deletions nonebot_plugin_bottle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
everyone_can_read,
disable_forward,
enable_approve,
approve_notice_admin
approve_notice_admin,
allow_pending_approval_bottle_to_be_viewed
)
from .data_source import (
ba,
Expand Down Expand Up @@ -126,7 +127,7 @@ async def get_bottle(
)
if not bottle:
await matcher.finish("该漂流瓶不存在或已被删除!")
if not bottle.approved:
if not allow_pending_approval_bottle_to_be_viewed and not bottle.approved:
await matcher.finish("该漂流瓶扔在审批中")
return bottle

Expand Down Expand Up @@ -343,7 +344,7 @@ async def _(
ba.add("cooldown", event.user_id)
bottle_content = (await deserialize_message(bottle.content)).extract_plain_text().strip()
bottle_message = (
f"【漂流瓶No.{bottle.id}】【+{bottle.like}/{bottle.picked}\n来自【{group_name}】的“{user_name}”!\n"
f"【漂流瓶No.{bottle.id}{'(审批中)' if not bottle.approved else ''}】【+{bottle.like}/{bottle.picked}\n来自【{group_name}】的“{user_name}”!\n"
+ f"时间:{bottle.time.strftime('%Y-%m-%d')}\n"
+ f"内容:\n"
+ await deserialize_message(bottle.content)
Expand Down
3 changes: 3 additions & 0 deletions nonebot_plugin_bottle/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Config(BaseModel):
nonebot_plugin_bottle_admin_password: str = ""
# webui 是否发送待审批消息至管理员
nonebot_plugin_bottle_notice_admin: bool = True
# 是否允许待审批的漂流瓶被用户查看
nonebot_plugin_bottle_allow_pending_approval_to_be_viewed: bool = False

config: Config = get_plugin_config(Config)
api_key = config.nonebot_plugin_bottle_api_key
Expand All @@ -46,3 +48,4 @@ class Config(BaseModel):
disable_forward = config.nonebot_plugin_bottle_disable_forward
enable_approve = config.nonebot_plugin_bottle_enable_approve
approve_notice_admin = config.nonebot_plugin_bottle_notice_admin
allow_pending_approval_bottle_to_be_viewed = config.nonebot_plugin_bottle_allow_pending_approval_to_be_viewed
11 changes: 8 additions & 3 deletions nonebot_plugin_bottle/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from nonebot_plugin_datastore.db import get_engine, post_db_init, create_session

from .model import Like, Bottle, Report, Comment
from .config import api_key, secret_key, local_storage, enable_approve
from .config import api_key, secret_key, local_storage, enable_approve, allow_pending_approval_bottle_to_be_viewed
from .exception import NotSupportMessage

data_dir = Path("data/bottle")
Expand Down Expand Up @@ -246,9 +246,12 @@ async def select(self, session: AsyncSession) -> Optional[Bottle]:
Returns:
Optional[Bottle]: 随机一个瓶子
"""
whereclause = [Bottle.is_del == False]
if not allow_pending_approval_bottle_to_be_viewed:
whereclause.append(Bottle.approved == True)
bottle = await session.scalar(
select(Bottle)
.where(Bottle.is_del == False, Bottle.approved == True)
.where(*whereclause)
.order_by(func.random())
.limit(1)
)
Expand Down Expand Up @@ -436,7 +439,9 @@ async def list_bottles(
"""
whereclause = [Bottle.user_id == user_id]
if not include_del:
whereclause += [Bottle.is_del == False, Bottle.approved == True]
whereclause.append(Bottle.is_del == False)
if not allow_pending_approval_bottle_to_be_viewed:
whereclause.append(Bottle.approved == True)
return (
await session.scalars(
select(Bottle).where(*whereclause).order_by(Bottle.id)
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_bottle"
version = "2.1.0.7"
version = "2.1.0.8"
description = "Bottle post plugin in Nonebot"
authors = ["Todysheep <todysheep@163.com>"]
license = "GNU GPLv3"
Expand Down

0 comments on commit 7b5e4d8

Please sign in to comment.