Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions nonebot_plugin_value/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
require("nonebot_plugin_orm")
require("nonebot_plugin_localstore")

from . import action_type, migrations, repository
from . import migrations
from .api import api_balance, api_currency, api_transaction
from .api.api_currency import get_or_create_currency
from .api.depends import factory
from .hook import context, exception, hooks_manager, hooks_type
from .hook import context, hooks_manager, hooks_type
from .models import currency
from .pyd_models import balance_pyd, base_pyd, currency_pyd
from .pyd_models.currency_pyd import CurrencyData
from .repository import DEFAULT_CURRENCY_UUID
from .services import balance, transaction
from .services import currency as currency_api
from .repository import DEFAULT_CURRENCY_UUID, NAMESPACE_VALUE

__plugin_meta__ = PluginMetadata(
name="EconomyValue",
Expand All @@ -27,24 +25,18 @@
)

__all__ = [
"action_type",
"NAMESPACE_VALUE",
"api_balance",
"api_currency",
"api_transaction",
"balance",
"balance_pyd",
"base_pyd",
"context",
"currency",
"currency_api",
"currency_pyd",
"exception",
"factory",
"hook",
"hooks_manager",
"hooks_type",
"repository",
"transaction",
]


Expand Down
27 changes: 7 additions & 20 deletions nonebot_plugin_value/action_type.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
class Method:
"""交易记录方法"""

__DEPOSIT = "DEPOSIT" # 存款
__WITHDRAW = "WITHDRAW" # 取款
__TRANSFER_IN = "TRANSFER_IN" # 转入(与转出同时存在)
__TRANSFER_OUT = "TRANSFER_OUT" # 转出(与转入同时存在)

@classmethod
def deposit(cls) -> str:
return cls.__DEPOSIT
from enum import Enum

@classmethod
def withdraw(cls) -> str:
return cls.__WITHDRAW

@classmethod
def transfer_in(cls) -> str:
return cls.__TRANSFER_IN
class Method(str, Enum):
"""交易记录方法"""

@classmethod
def transfer_out(cls) -> str:
return cls.__TRANSFER_OUT
DEPOSIT = "DEPOSIT" # 存款
WITHDRAW = "WITHDRAW" # 取款
TRANSFER_IN = "TRANSFER_IN" # 转入(与转出同时存在)
TRANSFER_OUT = "TRANSFER_OUT" # 转出(与转入同时存在)

@classmethod
def valid_actions(cls, action: str) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions nonebot_plugin_value/services/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def del_balance(
user_id=user_id,
currency=currency_id,
amount=amount,
action_type=Method.withdraw(),
action_type=Method.WITHDRAW.value,
),
)
except DataUpdate as du:
Expand All @@ -211,7 +211,7 @@ async def del_balance(
account_id, # 使用提前获取的account_id
currency_id,
amount,
Method.transfer_out(),
Method.TRANSFER_OUT.value,
source,
balance_before,
balance_after,
Expand Down Expand Up @@ -303,7 +303,7 @@ async def add_balance(
user_id=user_id,
currency=currency_id,
amount=amount,
action_type=Method.deposit(),
action_type=Method.DEPOSIT.value,
),
)
except DataUpdate as du:
Expand All @@ -316,7 +316,7 @@ async def add_balance(
account_id,
currency_id,
amount,
Method.deposit(),
Method.DEPOSIT.value,
source,
balance_before,
balance_after,
Expand Down Expand Up @@ -401,7 +401,7 @@ async def transfer_funds(
user_id=fromuser_id,
currency=currency_id,
amount=amount,
action_type=Method.transfer_out(),
action_type=Method.TRANSFER_OUT.value,
),
)
except DataUpdate as du:
Expand All @@ -413,7 +413,7 @@ async def transfer_funds(
user_id=touser_id,
currency=currency_id,
amount=amount,
action_type=Method.transfer_in(),
action_type=Method.TRANSFER_IN.value,
),
)
except DataUpdate as du:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
[project]
name = "nonebot-plugin-value"
version = "0.1.3.post2"
version = "0.1.4"
description = "Economy API for NoneBot2"
readme = "README.md"
requires-python = ">=3.10, <4.0.0"
authors = [{ "name" = "LiteSuggarDEV", "email" = "windowserror@163.com" }]
license = { "file" = "LICENSE" }
dependencies = [
"aiofiles>=24.1.0",
"alembic>=1.16.2",
"nonebot-plugin-localstore>=0.7.4",
"nonebot-plugin-orm>=0.8.2",
"nonebot2>=2.4.2",

"sqlalchemy>=2.0.41",
]


[tool.uv]
dev-dependencies = [
"nb-cli>=1.4.1",
"alembic>=1.16.2",
"nonebot-plugin-orm[default]>=0.7.4",
"ruff>=0.12.0",
"pyright>=1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading