-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8baeeb4
commit 56d7897
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# gold_trans | ||
|
||
zhenxun_bot 金币转账 | ||
|
||
## 使用 | ||
|
||
- 转账 [金币数] @CRAZYSHIMAKAZE | ||
|
||
### 更新 | ||
|
||
**2024/06/23**[v0.1] | ||
|
||
1. 初版 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Tuple | ||
|
||
from nonebot import on_regex | ||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, GROUP | ||
from nonebot.params import RegexGroup | ||
|
||
from models.bag_user import BagUser | ||
from utils.utils import get_message_at | ||
|
||
__zx_plugin_name__ = "金币转账" | ||
__plugin_usage__ = """ | ||
usage: | ||
转账 [金币数] @CRAZYSHIMAKAZE | ||
""".strip() | ||
|
||
__plugin_des__ = "金币转账" | ||
__plugin_type__ = ("一些工具",) | ||
__plugin_version__ = 0.1 | ||
__plugin_author__ = "CRAZYSHIMAKAZE" | ||
|
||
__plugin_settings__ = {"level": 5, "default_status": True, "limit_superuser": False, "cmd": ["转账"], } | ||
|
||
trans = on_regex(r'转账(\d+)', permission=GROUP, priority=5, block=True) | ||
|
||
|
||
@trans.handle() | ||
async def _(bot: Bot, event: GroupMessageEvent, args: Tuple[str, ...] = RegexGroup()): | ||
src_user = event.user_id | ||
tar_user = get_message_at(event.json())[0] | ||
coin = int(args[0].strip()) | ||
print(args[0], args) | ||
user_coin = await BagUser.get_gold(event.user_id, event.group_id) | ||
if user_coin <= coin: | ||
await trans.send(f'你拥有{user_coin}金币,不足转账数目!', at_sender=True) | ||
else: | ||
await BagUser.spend_gold(src_user, event.group_id, coin) | ||
await BagUser.add_gold(tar_user, event.group_id, coin) | ||
await trans.send(f'转账成功!', at_sender=True) |