nonebot-plugin-fishing2 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_fishing2/__init__.py +240 -0
- nonebot_plugin_fishing2/config.py +182 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/data_source.py +193 -17
- nonebot_plugin_fishing2/migrations/68463f3e5f33_.py +35 -0
- {nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.2.dist-info}/METADATA +1 -1
- nonebot_plugin_fishing2-0.0.2.dist-info/RECORD +14 -0
- {nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.2.dist-info}/WHEEL +1 -1
- nonebot_plugin_fishing2-0.0.2.dist-info/top_level.txt +1 -0
- nonebot_plugin_fishing/__init__.py +0 -165
- nonebot_plugin_fishing/config.py +0 -95
- nonebot_plugin_fishing/migrations/1be1c9b715a9_add_achievements.py +0 -39
- nonebot_plugin_fishing2-0.0.1.dist-info/RECORD +0 -14
- nonebot_plugin_fishing2-0.0.1.dist-info/top_level.txt +0 -1
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/migrations/7609e6d106dd_init_db.py +0 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/migrations/c5ab992c9af3_add_achievements.py +0 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/migrations/e9015df43907_add_special_fishes_field.py +0 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/migrations/f70bdeaec7a4_add_specialfishes_table.py +0 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/model.py +0 -0
- {nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,240 @@
|
|
1
|
+
from nonebot import on_command, require
|
2
|
+
|
3
|
+
require("nonebot_plugin_orm") # noqa
|
4
|
+
|
5
|
+
from nonebot import logger
|
6
|
+
from nonebot.plugin import PluginMetadata
|
7
|
+
from nonebot.adapters import Event, Message
|
8
|
+
from nonebot.params import CommandArg
|
9
|
+
from nonebot.permission import SUPERUSER
|
10
|
+
from nonebot.matcher import Matcher
|
11
|
+
|
12
|
+
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, PrivateMessageEvent, Message, MessageSegment, ActionFailed
|
13
|
+
|
14
|
+
import asyncio
|
15
|
+
|
16
|
+
from typing import Union
|
17
|
+
|
18
|
+
from .config import Config, config
|
19
|
+
from .data_source import (
|
20
|
+
can_fishing,
|
21
|
+
can_free_fish,
|
22
|
+
get_fish,
|
23
|
+
get_stats,
|
24
|
+
get_backpack,
|
25
|
+
sell_fish,
|
26
|
+
get_balance,
|
27
|
+
free_fish,
|
28
|
+
lottery,
|
29
|
+
give,
|
30
|
+
check_achievement,
|
31
|
+
get_achievements,
|
32
|
+
get_board,
|
33
|
+
check_tools,
|
34
|
+
remove_tools
|
35
|
+
)
|
36
|
+
|
37
|
+
fishing_coin_name = config.fishing_coin_name
|
38
|
+
|
39
|
+
__plugin_meta__ = PluginMetadata(
|
40
|
+
name="赛博钓鱼",
|
41
|
+
description="你甚至可以电子钓鱼",
|
42
|
+
usage=f'''钓鱼帮助
|
43
|
+
▶ 查询 [物品]:
|
44
|
+
▶ 钓鱼 [鱼竿] [鱼饵]:
|
45
|
+
▷ 有 {config.fishing_limit}s 的冷却,时间随上一条鱼稀有度而增加
|
46
|
+
▷ 加参数可以使用鱼饵或鱼竿,同时只能使用一种
|
47
|
+
▷ 频繁钓鱼会触怒河神
|
48
|
+
▶ 出售 <物品> <数量>:出售物品获得{fishing_coin_name}
|
49
|
+
▶ 购买 <鱼名> <数量>:【尚未实现】
|
50
|
+
▶ 放生 <鱼名>:给一条鱼取名并放生
|
51
|
+
▶ 祈愿:向神祈愿,随机获取/损失{fishing_coin_name}
|
52
|
+
▶ 背包:查看背包中的{fishing_coin_name}与物品
|
53
|
+
▶ 成就:查看拥有的成就
|
54
|
+
▶ 钓鱼排行榜:查看{fishing_coin_name}排行榜
|
55
|
+
''',
|
56
|
+
type="application",
|
57
|
+
homepage="https://github.com/FDCraft/nonebot-plugin-fishing2",
|
58
|
+
config=Config,
|
59
|
+
supported_adapters=None,
|
60
|
+
)
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
block_user_list = []
|
65
|
+
punish_user_dict = {}
|
66
|
+
|
67
|
+
fishing_help = on_command("fishing_help", aliases={"钓鱼帮助"}, priority=3,block=True)
|
68
|
+
fishing_lookup = on_command("fishing_lookup", aliases={"查看", "查询"}, priority=3,block=True)
|
69
|
+
fishing = on_command("fishing", aliases={"钓鱼"}, priority=5)
|
70
|
+
backpack = on_command("backpack", aliases={"背包", "钓鱼背包"}, priority=5)
|
71
|
+
buy = on_command("buy", aliases={"购买", "商店"}, priority=5)
|
72
|
+
sell = on_command("sell", aliases={"卖鱼", "出售", "售卖"}, priority=5)
|
73
|
+
free_fish_cmd = on_command("free_fish", aliases={"放生", "钓鱼放生"}, priority=5)
|
74
|
+
lottery_cmd = on_command("lottery", aliases={"祈愿"}, priority=5)
|
75
|
+
achievement_cmd = on_command("achievement", aliases={"成就", "钓鱼成就"}, priority=5)
|
76
|
+
give_cmd = on_command("give", aliases={"赐予"}, permission=SUPERUSER, priority=5)
|
77
|
+
board_cmd = on_command("board", aliases={"排行榜", "钓鱼排行榜"}, priority=5)
|
78
|
+
|
79
|
+
|
80
|
+
@fishing_help.handle()
|
81
|
+
async def _():
|
82
|
+
await fishing_help.finish(__plugin_meta__.usage)
|
83
|
+
|
84
|
+
|
85
|
+
async def punish(bot: Bot, event: Event, matcher: Matcher, user_id: int):
|
86
|
+
global punish_user_dict
|
87
|
+
|
88
|
+
if not await can_fishing(user_id):
|
89
|
+
try:
|
90
|
+
punish_user_dict[user_id] += 1
|
91
|
+
except KeyError:
|
92
|
+
punish_user_dict[user_id] = 1
|
93
|
+
|
94
|
+
if punish_user_dict[user_id] < config.punish_limit - 1 :
|
95
|
+
await matcher.finish(MessageSegment.at(user_id) + " " + "河累了,休息一下吧")
|
96
|
+
elif punish_user_dict[user_id] == config.punish_limit - 1:
|
97
|
+
await matcher.finish(MessageSegment.at(user_id) + " " + "河神快要不耐烦了")
|
98
|
+
elif punish_user_dict[user_id] == config.punish_limit:
|
99
|
+
groud_id = event.group_id if isinstance(event, GroupMessageEvent) else None
|
100
|
+
try:
|
101
|
+
await bot.set_group_ban(group_id=groud_id, user_id=user_id, duration=1800)
|
102
|
+
except ActionFailed:
|
103
|
+
pass
|
104
|
+
await matcher.finish(MessageSegment.at(user_id) + " " + "河神生气了,降下了惩罚")
|
105
|
+
else:
|
106
|
+
await matcher.finish()
|
107
|
+
|
108
|
+
|
109
|
+
@fishing.handle()
|
110
|
+
async def _(bot:Bot, event: Event, matcher: Matcher, arg: Message = CommandArg()):
|
111
|
+
user_id = event.get_user_id()
|
112
|
+
if user_id in block_user_list:
|
113
|
+
await fishing.finish()
|
114
|
+
|
115
|
+
use_tools = False
|
116
|
+
tools = arg.extract_plain_text().split()[:2]
|
117
|
+
logger.debug(f"PLDEBUG0: {tools}")
|
118
|
+
if tools and tools != [] and tools != [""]:
|
119
|
+
use_tools = True
|
120
|
+
check_result = await check_tools(user_id, tools)
|
121
|
+
if check_result:
|
122
|
+
await fishing.finish(MessageSegment.at(user_id) + " " + check_result)
|
123
|
+
|
124
|
+
await punish(bot, event, matcher, user_id)
|
125
|
+
block_user_list.append(user_id)
|
126
|
+
try:
|
127
|
+
if use_tools:
|
128
|
+
await remove_tools(user_id, tools)
|
129
|
+
await fishing.send(MessageSegment.at(user_id) + "\n你使用了" + "、".join(tools) + "\n正在钓鱼…")
|
130
|
+
result = await get_fish(user_id, tools)
|
131
|
+
else:
|
132
|
+
await fishing.send(MessageSegment.at(user_id) + " 正在钓鱼…")
|
133
|
+
result = await get_fish(user_id)
|
134
|
+
achievements = await check_achievement(user_id)
|
135
|
+
if achievements is not None:
|
136
|
+
for achievement in achievements:
|
137
|
+
await fishing.send(achievement)
|
138
|
+
except Exception as e:
|
139
|
+
logger.error(e)
|
140
|
+
finally:
|
141
|
+
block_user_list.remove(user_id)
|
142
|
+
punish_user_dict.pop(user_id, None)
|
143
|
+
await fishing.finish(MessageSegment.at(user_id) + " " + result)
|
144
|
+
|
145
|
+
|
146
|
+
@backpack.handle()
|
147
|
+
async def _(event: Event):
|
148
|
+
user_id = event.get_user_id()
|
149
|
+
await backpack.finish(MessageSegment.at(user_id) + " \n" + await get_stats(user_id) + "\n" + await get_balance(user_id) + "\n" + await get_backpack(user_id))
|
150
|
+
|
151
|
+
@buy.handle()
|
152
|
+
async def _(event: Event, arg: Message = CommandArg()):
|
153
|
+
fish_info = arg.extract_plain_text()
|
154
|
+
user_id = event.get_user_id()
|
155
|
+
if fish_info == "":
|
156
|
+
await buy.finish(MessageSegment.at(user_id) + " " + "请输入要买入的鱼的名字和数量 (数量为1时可省略), 如 /购买 鱼竿 1")
|
157
|
+
if len(fish_info.split()) == 1:
|
158
|
+
await buy.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_info))
|
159
|
+
else:
|
160
|
+
fish_name, fish_quantity = fish_info.split()
|
161
|
+
await buy.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_name, int(fish_quantity)))
|
162
|
+
|
163
|
+
|
164
|
+
@sell.handle()
|
165
|
+
async def _(event: Event, arg: Message = CommandArg()):
|
166
|
+
fish_info = arg.extract_plain_text()
|
167
|
+
user_id = event.get_user_id()
|
168
|
+
if fish_info == "":
|
169
|
+
await sell.finish(MessageSegment.at(user_id) + " " + "请输入要卖出的鱼的名字和数量 (数量为1时可省略), 如 /卖鱼 小鱼 1")
|
170
|
+
if len(fish_info.split()) == 1:
|
171
|
+
await sell.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_info))
|
172
|
+
else:
|
173
|
+
fish_name, fish_quantity = fish_info.split()
|
174
|
+
await sell.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_name, int(fish_quantity)))
|
175
|
+
|
176
|
+
|
177
|
+
@free_fish_cmd.handle()
|
178
|
+
async def _(event: Event, arg: Message = CommandArg()):
|
179
|
+
if not can_free_fish():
|
180
|
+
await free_fish_cmd.finish("未开启此功能, 请联系机器人管理员")
|
181
|
+
fish_name = arg.extract_plain_text()
|
182
|
+
user_id = event.get_user_id()
|
183
|
+
if fish_name == "":
|
184
|
+
await free_fish_cmd.finish(MessageSegment.at(user_id) + " " + "请输入要放生的鱼的名字, 如 /放生 测试鱼")
|
185
|
+
await free_fish_cmd.finish(MessageSegment.at(user_id) + " " + await free_fish(user_id, fish_name))
|
186
|
+
|
187
|
+
|
188
|
+
@lottery_cmd.handle()
|
189
|
+
async def _(bot: Bot, event: Event, matcher: Matcher):
|
190
|
+
user_id = event.get_user_id()
|
191
|
+
try:
|
192
|
+
await punish(bot, event, matcher, user_id)
|
193
|
+
result = await lottery(user_id)
|
194
|
+
except:
|
195
|
+
pass
|
196
|
+
finally:
|
197
|
+
punish_user_dict.pop(user_id, None)
|
198
|
+
await lottery_cmd.finish(MessageSegment.at(user_id) + " " + result)
|
199
|
+
|
200
|
+
|
201
|
+
@achievement_cmd.handle()
|
202
|
+
async def _(event: Event):
|
203
|
+
user_id = event.get_user_id()
|
204
|
+
await achievement_cmd.finish(MessageSegment.at(user_id) + " " + await get_achievements(user_id))
|
205
|
+
|
206
|
+
|
207
|
+
@give_cmd.handle()
|
208
|
+
async def _(arg: Message = CommandArg()):
|
209
|
+
args = arg.extract_plain_text().split()
|
210
|
+
if len(args) < 2 or len(args) > 3:
|
211
|
+
await give_cmd.finish("请输入用户的 id 和鱼的名字和数量 (数量为1时可省略), 如 /give 114514 开发鱼 1")
|
212
|
+
else:
|
213
|
+
print(f"PLDEBUG1: {args}")
|
214
|
+
quantity = int(args[2]) if len(args) == 3 else 1
|
215
|
+
result = await give(args[0], args[1], quantity)
|
216
|
+
achievements = await check_achievement(args[0])
|
217
|
+
if achievements is not None:
|
218
|
+
for achievement in achievements:
|
219
|
+
await fishing.send(achievement)
|
220
|
+
await give_cmd.finish(result)
|
221
|
+
|
222
|
+
|
223
|
+
@board_cmd.handle()
|
224
|
+
async def _(bot: Bot, event: GroupMessageEvent):
|
225
|
+
group_id = event.group_id
|
226
|
+
top_users_list = await get_board()
|
227
|
+
msg = '钓鱼富豪排行榜:'
|
228
|
+
for index, user in enumerate(top_users_list):
|
229
|
+
try:
|
230
|
+
user_info = await bot.get_group_member_info(group_id=group_id, user_id=user[0])
|
231
|
+
username = user_info['card'] if user_info['card'] is not None and user_info['card'] != '' else user_info['nickname']
|
232
|
+
except ActionFailed:
|
233
|
+
username = "[神秘富豪]"
|
234
|
+
|
235
|
+
msg += f'\n{index + 1}. {username}: {user[1]} {fishing_coin_name}'
|
236
|
+
|
237
|
+
await board_cmd.finish(msg)
|
238
|
+
|
239
|
+
|
240
|
+
|
@@ -0,0 +1,182 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
from typing import List, Dict
|
3
|
+
|
4
|
+
try:
|
5
|
+
# pydantic v2
|
6
|
+
from nonebot import get_plugin_config
|
7
|
+
except ImportError:
|
8
|
+
# pydantic v1
|
9
|
+
from nonebot import get_driver
|
10
|
+
|
11
|
+
|
12
|
+
class Config(BaseModel):
|
13
|
+
fishes: List[Dict] = [
|
14
|
+
{
|
15
|
+
"type": "fish",
|
16
|
+
"name": "小鱼",
|
17
|
+
"price": 10,
|
18
|
+
"props": [
|
19
|
+
{
|
20
|
+
"type": "rm_fish",
|
21
|
+
"key": "小鱼"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"description": "一条小鱼。\n把它当做鱼饵可以防止钓到小鱼。",
|
25
|
+
"can_catch": True,
|
26
|
+
"frequency": 2,
|
27
|
+
"weight": 1000,
|
28
|
+
"can_buy": False,
|
29
|
+
"can_sell": True
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"type": "item",
|
33
|
+
"name": "尚方宝剑",
|
34
|
+
"price": 20,
|
35
|
+
"props": [],
|
36
|
+
"description": "假的。",
|
37
|
+
"can_catch": True,
|
38
|
+
"frequency": 2,
|
39
|
+
"weight": 500,
|
40
|
+
"can_buy": False,
|
41
|
+
"can_sell": True,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"type": "fish",
|
45
|
+
"name": "小杂鱼~♡",
|
46
|
+
"price": 100,
|
47
|
+
"props": [],
|
48
|
+
"description": "杂鱼,杂鱼~",
|
49
|
+
"can_catch": True,
|
50
|
+
"frequency": 10,
|
51
|
+
"weight": 100,
|
52
|
+
"can_buy": False,
|
53
|
+
"can_sell": True
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"type": "fish",
|
57
|
+
"name": "烤激光鱼",
|
58
|
+
"price": 1000,
|
59
|
+
"props": [],
|
60
|
+
"description": "河里为什么会有烤鱼?",
|
61
|
+
"can_catch": True,
|
62
|
+
"frequency": 20,
|
63
|
+
"weight": 20,
|
64
|
+
"can_buy": False,
|
65
|
+
"can_sell": True
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"type": "fish",
|
69
|
+
"name": "琪露诺",
|
70
|
+
"price": 1000,
|
71
|
+
"props": [],
|
72
|
+
"description": "邪恶的冰之精灵,是个笨蛋。",
|
73
|
+
"can_catch": True,
|
74
|
+
"frequency": 60,
|
75
|
+
"weight": 20,
|
76
|
+
"can_buy": False,
|
77
|
+
"can_sell": True
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"type": "fish",
|
81
|
+
"name": "大傻",
|
82
|
+
"price": 2000,
|
83
|
+
"props": [],
|
84
|
+
"description": "非常能吃大米。",
|
85
|
+
"can_catch": True,
|
86
|
+
"frequency": 30,
|
87
|
+
"weight": 1,
|
88
|
+
"can_buy": False,
|
89
|
+
"can_sell": True
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"type": "item",
|
93
|
+
"name": "钛金鱼竿",
|
94
|
+
"price": 5,
|
95
|
+
"props": [
|
96
|
+
{
|
97
|
+
"type": "rare_fish",
|
98
|
+
"value": 50
|
99
|
+
}
|
100
|
+
],
|
101
|
+
"description": "更坚韧的鱼竿,显著提升钓上大鱼的概率。",
|
102
|
+
"can_catch": False,
|
103
|
+
"can_buy": True,
|
104
|
+
"count": 30,
|
105
|
+
"can_sell": False
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"type": "fish",
|
109
|
+
"name": "大米",
|
110
|
+
"price": 10000,
|
111
|
+
"props": [
|
112
|
+
{
|
113
|
+
"type": "fish",
|
114
|
+
"key": "大傻",
|
115
|
+
"value": 10000
|
116
|
+
}
|
117
|
+
],
|
118
|
+
"description": "Fufu 最爱吃的大米!这是管理员物品。",
|
119
|
+
"can_catch": False,
|
120
|
+
"can_buy": False,
|
121
|
+
"can_sell": False
|
122
|
+
}
|
123
|
+
]
|
124
|
+
|
125
|
+
punish_limit: int = 3
|
126
|
+
|
127
|
+
fishing_limit: int = 60
|
128
|
+
|
129
|
+
fishing_coin_name: str = "绿宝石" # It means Fishing Coin.
|
130
|
+
|
131
|
+
special_fish_enabled: bool = True
|
132
|
+
|
133
|
+
special_fish_price: int = 200
|
134
|
+
|
135
|
+
special_fish_probability: float = 0.01
|
136
|
+
|
137
|
+
fishing_achievement: List[Dict] = [
|
138
|
+
{
|
139
|
+
"type": "fishing_frequency",
|
140
|
+
"name": "腥味十足的生意",
|
141
|
+
"data": 1,
|
142
|
+
"description": "钓到一条鱼。"
|
143
|
+
},
|
144
|
+
{
|
145
|
+
"type": "fishing_frequency",
|
146
|
+
"name": "还是钓鱼大佬",
|
147
|
+
"data": 100,
|
148
|
+
"description": "累计钓鱼一百次。"
|
149
|
+
},
|
150
|
+
{
|
151
|
+
"type": "fish_type",
|
152
|
+
"name": "那是鱼吗?",
|
153
|
+
"data": "小杂鱼~♡",
|
154
|
+
"description": "获得#####。[原文如此]"
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"type": "fish_type",
|
158
|
+
"name": "那一晚, 激光鱼和便携式烤炉都喝醉了",
|
159
|
+
"data": "烤激光鱼",
|
160
|
+
"description": "获得烤激光鱼。"
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"type": "fish_type",
|
164
|
+
"name": "你怎么把 Fufu 钓上来了",
|
165
|
+
"data": "大傻",
|
166
|
+
"description": "获得大傻"
|
167
|
+
},
|
168
|
+
{
|
169
|
+
"type": "fish_type",
|
170
|
+
"name": "⑨",
|
171
|
+
"data": "琪露诺",
|
172
|
+
"description": "发现了湖边的冰之精灵"
|
173
|
+
},
|
174
|
+
]
|
175
|
+
|
176
|
+
|
177
|
+
try:
|
178
|
+
# pydantic v2
|
179
|
+
config = get_plugin_config(Config)
|
180
|
+
except:
|
181
|
+
# pydantic v1
|
182
|
+
config = Config.parse_obj(get_driver().config)
|
@@ -1,7 +1,10 @@
|
|
1
|
+
import asyncio
|
2
|
+
import copy
|
1
3
|
import random
|
2
4
|
import time
|
3
5
|
import json
|
4
6
|
|
7
|
+
from typing import Union
|
5
8
|
from sqlalchemy import select, update, delete
|
6
9
|
from sqlalchemy.sql.expression import func
|
7
10
|
from nonebot_plugin_orm import get_session
|
@@ -11,17 +14,94 @@ from .model import FishingRecord, SpecialFishes
|
|
11
14
|
|
12
15
|
fishing_coin_name = config.fishing_coin_name
|
13
16
|
fish_list = [fish["name"] for fish in config.fishes]
|
17
|
+
can_catch_fishes = {fish["name"]: fish["weight"] for fish in config.fishes if fish["can_catch"]}
|
18
|
+
can_buy_fishes = [fish["name"] for fish in config.fishes if fish["can_catch"]]
|
19
|
+
can_sell_fishes = [fish["name"] for fish in config.fishes if fish["can_sell"]]
|
14
20
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
21
|
+
def adjusted_choice(adjusts: list[dict[str, Union[str, int]]] = None) -> str:
|
22
|
+
|
23
|
+
adjusted_fishes = copy.deepcopy(can_catch_fishes)
|
24
|
+
|
25
|
+
if adjusts:
|
26
|
+
for adjust in adjusts:
|
27
|
+
if adjust.get("key") and adjust["key"] not in adjusted_fishes:
|
28
|
+
continue
|
29
|
+
match adjust["type"]:
|
30
|
+
case "normal_fish":
|
31
|
+
for key, weight in can_catch_fishes:
|
32
|
+
if weight >= 500 and key in adjusted_fishes:
|
33
|
+
adjusted_fishes[key] += adjust["value"]
|
34
|
+
case "rare_fish":
|
35
|
+
for key, weight in can_catch_fishes:
|
36
|
+
if weight < 500 and key in adjusted_fishes:
|
37
|
+
adjusted_fishes[key] += adjust["value"]
|
38
|
+
case "fish":
|
39
|
+
adjusted_fishes[adjust["key"]] += adjust["value"]
|
40
|
+
case "rm_fish":
|
41
|
+
adjusted_fishes.pop(adjust["key"])
|
42
|
+
case "special_fish":
|
43
|
+
pass
|
44
|
+
case _:
|
45
|
+
pass
|
46
|
+
|
47
|
+
adjusted_fishes_list = list(adjusted_fishes.keys())
|
48
|
+
adjusted_weights = list(adjusted_fishes.values())
|
49
|
+
|
18
50
|
choices = random.choices(
|
19
|
-
|
20
|
-
weights=
|
51
|
+
adjusted_fishes_list,
|
52
|
+
weights=adjusted_weights,
|
53
|
+
)
|
54
|
+
return choices[0]
|
55
|
+
|
56
|
+
|
57
|
+
async def get_fish(user_id: int, tools: list = None) -> str:
|
58
|
+
probability_add = 0
|
59
|
+
adjusts: list[dict[str, Union[str, int]]] = []
|
60
|
+
|
61
|
+
if tools:
|
62
|
+
for tool in tools:
|
63
|
+
adjusts += get_props(tool)
|
64
|
+
|
65
|
+
for adjust in adjusts:
|
66
|
+
if adjust["type"] == "special_fish":
|
67
|
+
probability_add += adjust["value"]
|
68
|
+
|
69
|
+
if await can_catch_special_fish(probability_add):
|
70
|
+
special_fish_name = await random_get_a_special_fish()
|
71
|
+
await save_special_fish(user_id, special_fish_name)
|
72
|
+
result = f"你钓到了别人放生的 {special_fish_name}"
|
73
|
+
return result
|
74
|
+
fish = adjusted_choice(adjusts)
|
75
|
+
sleep_time = get_frequency(fish)
|
76
|
+
result = f"钓到了一条{fish}, 你把它收进了背包里"
|
77
|
+
await asyncio.sleep(sleep_time)
|
78
|
+
await save_fish(user_id, fish)
|
79
|
+
return result
|
80
|
+
|
81
|
+
|
82
|
+
def get_type(fish_name: str) -> list:
|
83
|
+
"""获取鱼的类型"""
|
84
|
+
config_fishes = config.fishes
|
85
|
+
return next(
|
86
|
+
(
|
87
|
+
fish["type"]
|
88
|
+
for fish in config_fishes
|
89
|
+
if fish["name"] == fish_name
|
90
|
+
),
|
91
|
+
"fish"
|
21
92
|
)
|
22
|
-
return choices[0]["name"], choices[0]["frequency"]
|
23
|
-
|
24
93
|
|
94
|
+
def get_props(fish_name: str) -> list:
|
95
|
+
"""获取鱼的属性"""
|
96
|
+
config_fishes = config.fishes
|
97
|
+
return next(
|
98
|
+
(
|
99
|
+
fish["props"]
|
100
|
+
for fish in config_fishes
|
101
|
+
if fish["name"] == fish_name
|
102
|
+
),
|
103
|
+
[]
|
104
|
+
)
|
25
105
|
def get_price(fish_name: str) -> int:
|
26
106
|
"""获取鱼的价格"""
|
27
107
|
config_fishes = config.fishes
|
@@ -33,6 +113,18 @@ def get_price(fish_name: str) -> int:
|
|
33
113
|
),
|
34
114
|
0
|
35
115
|
)
|
116
|
+
|
117
|
+
def get_frequency(fish_name: str) -> int:
|
118
|
+
"""获取鱼的冷却"""
|
119
|
+
config_fishes = config.fishes
|
120
|
+
return next(
|
121
|
+
(
|
122
|
+
fish["frequency"]
|
123
|
+
for fish in config_fishes
|
124
|
+
if fish["name"] == fish_name
|
125
|
+
),
|
126
|
+
60
|
127
|
+
)
|
36
128
|
|
37
129
|
|
38
130
|
async def random_get_a_special_fish() -> str:
|
@@ -166,11 +258,11 @@ async def save_fish(user_id: str, fish_name: str) -> None:
|
|
166
258
|
await session.commit()
|
167
259
|
|
168
260
|
|
169
|
-
async def can_catch_special_fish():
|
261
|
+
async def can_catch_special_fish(probability_add: int):
|
170
262
|
session = get_session()
|
171
263
|
async with session.begin():
|
172
264
|
records = await session.execute(select(SpecialFishes))
|
173
|
-
return len(records.all()) != 0 and random.random() <= config.special_fish_probability
|
265
|
+
return len(records.all()) != 0 and random.random() <= config.special_fish_probability + probability_add
|
174
266
|
|
175
267
|
|
176
268
|
async def save_special_fish(user_id: str, fish_name: str) -> None:
|
@@ -284,8 +376,10 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
284
376
|
spec_fishes = json.loads(fishes_record.special_fishes)
|
285
377
|
if fish_name in loads_fishes and loads_fishes[fish_name] > 0:
|
286
378
|
fish_price = get_price(fish_name)
|
379
|
+
if fish_name not in can_sell_fishes:
|
380
|
+
return f"这个 {fish_name} 不可以卖哦~"
|
287
381
|
if loads_fishes[fish_name] < quantity:
|
288
|
-
return f"{fish_name}
|
382
|
+
return f"你没有那么多 {fish_name}"
|
289
383
|
loads_fishes[fish_name] -= quantity
|
290
384
|
if loads_fishes[fish_name] == 0:
|
291
385
|
del loads_fishes[fish_name]
|
@@ -303,7 +397,7 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
303
397
|
elif fish_name in spec_fishes and spec_fishes[fish_name] > 0:
|
304
398
|
fish_price = config.special_fish_price
|
305
399
|
if spec_fishes[fish_name] < quantity:
|
306
|
-
return f"{fish_name}
|
400
|
+
return f"你没有那么多 {fish_name}"
|
307
401
|
spec_fishes[fish_name] -= quantity
|
308
402
|
if spec_fishes[fish_name] == 0:
|
309
403
|
del spec_fishes[fish_name]
|
@@ -317,7 +411,7 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
317
411
|
await session.execute(user_update)
|
318
412
|
await session.commit()
|
319
413
|
return (f"你以 {fish_price} {fishing_coin_name} / 条的价格卖出了 {quantity} 条 {fish_name}, "
|
320
|
-
f"
|
414
|
+
f"获得了 {fish_price * quantity} {fishing_coin_name}")
|
321
415
|
else:
|
322
416
|
return "查无此鱼"
|
323
417
|
else:
|
@@ -342,11 +436,16 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
342
436
|
fishes_record = await session.scalar(select_user)
|
343
437
|
if fishes_record:
|
344
438
|
user_coin = fishes_record.coin
|
345
|
-
spec_fishes = fishes_record.special_fishes
|
439
|
+
spec_fishes = json.loads(fishes_record.special_fishes)
|
346
440
|
if fish_name in spec_fishes and spec_fishes[fish_name] > 0:
|
347
441
|
spec_fishes[fish_name] -= 1
|
348
442
|
if spec_fishes[fish_name] == 0:
|
349
443
|
del spec_fishes[fish_name]
|
444
|
+
new_record = SpecialFishes(
|
445
|
+
user_id=user_id,
|
446
|
+
fish=fish_name
|
447
|
+
)
|
448
|
+
session.add(new_record)
|
350
449
|
dump_fishes = json.dumps(spec_fishes)
|
351
450
|
user_update = update(FishingRecord).where(
|
352
451
|
FishingRecord.user_id == user_id
|
@@ -357,6 +456,9 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
357
456
|
await session.commit()
|
358
457
|
return f"你再次放生了 {fish_name}, 未来或许会被有缘人钓到呢"
|
359
458
|
else:
|
459
|
+
if fish_name in fish_list:
|
460
|
+
return "普通鱼不能放生哦~"
|
461
|
+
|
360
462
|
if user_coin < config.special_fish_price // 2:
|
361
463
|
special_fish_coin_less = str(config.special_fish_price // 2 - fishes_record.coin)
|
362
464
|
return f"你没有足够的 {fishing_coin_name}, 还需 {special_fish_coin_less} {fishing_coin_name}"
|
@@ -380,13 +482,24 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
380
482
|
async def lottery(user_id: str) -> str:
|
381
483
|
"""算法来自于 https://github.com/fossifer/minesweeperbot/blob/master/cards.py"""
|
382
484
|
session = get_session()
|
485
|
+
time_now = int(time.time())
|
486
|
+
fishing_limit = config.fishing_limit
|
383
487
|
async with session.begin():
|
384
488
|
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
385
489
|
fishes_record = await session.scalar(select_user)
|
386
490
|
if fishes_record:
|
387
491
|
user_coin = fishes_record.coin
|
388
|
-
if user_coin <=
|
389
|
-
|
492
|
+
if user_coin <= 30:
|
493
|
+
new_coin = random.randrange(1, 50)
|
494
|
+
user_update = update(FishingRecord).where(
|
495
|
+
FishingRecord.user_id == user_id
|
496
|
+
).values(
|
497
|
+
time=time_now + fishing_limit,
|
498
|
+
coin=fishes_record.coin + new_coin,
|
499
|
+
)
|
500
|
+
await session.execute(user_update)
|
501
|
+
await session.commit()
|
502
|
+
return f"你穷得连河神都看不下去了,给了你 {new_coin} {fishing_coin_name} w(゚Д゚)w"
|
390
503
|
new_coin = abs(user_coin) / 3
|
391
504
|
new_coin = random.randrange(5000, 15000) / 10000 * new_coin
|
392
505
|
new_coin = int(new_coin) if new_coin > 1 else 1
|
@@ -394,11 +507,14 @@ async def lottery(user_id: str) -> str:
|
|
394
507
|
user_update = update(FishingRecord).where(
|
395
508
|
FishingRecord.user_id == user_id
|
396
509
|
).values(
|
510
|
+
time=time_now + fishing_limit,
|
397
511
|
coin=fishes_record.coin + new_coin,
|
398
512
|
)
|
399
513
|
await session.execute(user_update)
|
400
514
|
await session.commit()
|
401
515
|
return f'你{"获得" if new_coin >= 0 else "血亏"}了 {abs(new_coin)} {fishing_coin_name}'
|
516
|
+
else:
|
517
|
+
return "河神没有回应你……"
|
402
518
|
|
403
519
|
|
404
520
|
async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
@@ -407,6 +523,15 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
407
523
|
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
408
524
|
record = await session.scalar(select_user)
|
409
525
|
if record:
|
526
|
+
if fish_name == 'coin' or fish_name == fishing_coin_name:
|
527
|
+
user_update = update(FishingRecord).where(
|
528
|
+
FishingRecord.user_id == user_id
|
529
|
+
).values(
|
530
|
+
coin=record.coin + quantity,
|
531
|
+
)
|
532
|
+
await session.execute(user_update)
|
533
|
+
await session.commit()
|
534
|
+
return f"使用滥权之力成功为 {user_id} {"增加" if quantity >= 0 else "减少"} {abs(quantity)} {fishing_coin_name} ヾ(≧▽≦*)o"
|
410
535
|
loads_fishes = json.loads(record.fishes)
|
411
536
|
spec_fishes = json.loads(record.special_fishes)
|
412
537
|
if fish_name in fish_list:
|
@@ -435,7 +560,7 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
435
560
|
)
|
436
561
|
await session.execute(user_update)
|
437
562
|
await session.commit()
|
438
|
-
return f"
|
563
|
+
return f"使用滥权之力成功将 {fish_name} 添加到 {user_id} 的背包之中 ヾ(≧▽≦*)o"
|
439
564
|
return "未查找到用户信息, 无法执行滥权操作 w(゚Д゚)w"
|
440
565
|
|
441
566
|
|
@@ -460,4 +585,55 @@ async def get_board() -> list:
|
|
460
585
|
top_users_list.append((user.user_id, user.coin))
|
461
586
|
top_users_list.sort(key=lambda user: user[1], reverse=True)
|
462
587
|
return top_users_list
|
463
|
-
return []
|
588
|
+
return []
|
589
|
+
|
590
|
+
async def get_shop() -> str | None:
|
591
|
+
pass
|
592
|
+
|
593
|
+
async def check_tools(user_id: str, tools: list) -> str | None:
|
594
|
+
# 这是工具吗?
|
595
|
+
for tool in tools:
|
596
|
+
props = get_props(tool)
|
597
|
+
if not props or props == []:
|
598
|
+
return f"搞啥嘞!{tool}既不是工具也不是鱼饵!"
|
599
|
+
|
600
|
+
# 如果有两个工具,是一个工具一个鱼饵吗?
|
601
|
+
if len(tools) == 2:
|
602
|
+
if get_type(tool[0]) == get_type(tool[1]):
|
603
|
+
return "你为啥要用两个类型一样的东西?"
|
604
|
+
|
605
|
+
# 有吗?有吗?
|
606
|
+
session = get_session()
|
607
|
+
async with session.begin():
|
608
|
+
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
609
|
+
fishes_record = await session.scalar(select_user)
|
610
|
+
if fishes_record:
|
611
|
+
loads_fishes = json.loads(fishes_record.fishes)
|
612
|
+
for tool in tools:
|
613
|
+
if tool not in loads_fishes:
|
614
|
+
return f"你哪来的 {tool}?"
|
615
|
+
|
616
|
+
return None
|
617
|
+
|
618
|
+
async def remove_tools(user_id: str, tools: list[str]) -> None:
|
619
|
+
session = get_session()
|
620
|
+
async with session.begin():
|
621
|
+
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
622
|
+
fishes_record = await session.scalar(select_user)
|
623
|
+
if fishes_record:
|
624
|
+
loads_fishes = json.loads(fishes_record.fishes)
|
625
|
+
for tool in tools:
|
626
|
+
loads_fishes[tool] -= 1
|
627
|
+
if loads_fishes[tool] == 0:
|
628
|
+
del loads_fishes[tool]
|
629
|
+
dump_fishes = json.dumps(loads_fishes)
|
630
|
+
user_update = update(FishingRecord).where(
|
631
|
+
FishingRecord.user_id == user_id
|
632
|
+
).values(
|
633
|
+
fishes=dump_fishes
|
634
|
+
)
|
635
|
+
await session.execute(user_update)
|
636
|
+
await session.commit()
|
637
|
+
else:
|
638
|
+
pass
|
639
|
+
# raise ValueError("?你的 Check 是怎么通过的?")
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"""Update version
|
2
|
+
|
3
|
+
迁移 ID: 68463f3e5f33
|
4
|
+
父迁移: 7609e6d106dd
|
5
|
+
创建时间: 2024-04-13 01:21:12.144452
|
6
|
+
|
7
|
+
"""
|
8
|
+
from __future__ import annotations
|
9
|
+
|
10
|
+
from collections.abc import Sequence
|
11
|
+
|
12
|
+
from alembic import op
|
13
|
+
import sqlalchemy as sa
|
14
|
+
|
15
|
+
|
16
|
+
revision: str = '68463f3e5f33'
|
17
|
+
down_revision: str | Sequence[str] | None = '7609e6d106dd'
|
18
|
+
branch_labels: str | Sequence[str] | None = None
|
19
|
+
depends_on: str | Sequence[str] | None = None
|
20
|
+
|
21
|
+
|
22
|
+
def upgrade(name: str = "") -> None:
|
23
|
+
if name:
|
24
|
+
return
|
25
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
26
|
+
pass
|
27
|
+
# ### end Alembic commands ###
|
28
|
+
|
29
|
+
|
30
|
+
def downgrade(name: str = "") -> None:
|
31
|
+
if name:
|
32
|
+
return
|
33
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
34
|
+
pass
|
35
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,14 @@
|
|
1
|
+
nonebot_plugin_fishing2/__init__.py,sha256=LGGNW_FLqXSerQIXMTPtCYLAU9vWkBxLkuVdcwr4fOg,9466
|
2
|
+
nonebot_plugin_fishing2/config.py,sha256=bdGguNMMiEaGSq7JY02lU9NUBgL2bQXTJFsYEH8OSbM,5080
|
3
|
+
nonebot_plugin_fishing2/data_source.py,sha256=HWP_E9zM-iXrBdtiV_gnPn6tPuOdH9fb9u6bVbcdTw4,25684
|
4
|
+
nonebot_plugin_fishing2/model.py,sha256=_DtmxiQhJDiIvY1XOMQZ0HA-ruWY0bexWX9frdhnk0Q,752
|
5
|
+
nonebot_plugin_fishing2/migrations/68463f3e5f33_.py,sha256=WnaV5T1uCHvYWcnepHqV9kOurDYddFUvXXfA2Rtd5Ok,776
|
6
|
+
nonebot_plugin_fishing2/migrations/7609e6d106dd_init_db.py,sha256=tpuIfsS6yPsnGIeMPo16exsEfYZ_urgYAqlCyQ8aw-Y,1386
|
7
|
+
nonebot_plugin_fishing2/migrations/c5ab992c9af3_add_achievements.py,sha256=KVj9ADeP03zfW4ZBDmnghbWdxLor3u1yKeho0GaddCI,1119
|
8
|
+
nonebot_plugin_fishing2/migrations/e9015df43907_add_special_fishes_field.py,sha256=R4p9vPD5lgg4vmY2KUgF2qIlraxhPYkL93lM5l7wMZw,1094
|
9
|
+
nonebot_plugin_fishing2/migrations/f70bdeaec7a4_add_specialfishes_table.py,sha256=DUqv9MTaOSZCBj_9oT2eY3pmWeMnyH0cPj9GyYa5Sag,1194
|
10
|
+
nonebot_plugin_fishing2-0.0.2.dist-info/licenses/LICENSE,sha256=yuLTg7OdKnH7rznCsJ31UJwI4B8_oEP4f_zE7bJS75w,1091
|
11
|
+
nonebot_plugin_fishing2-0.0.2.dist-info/METADATA,sha256=cJOFaKVJjlOGs-G3ipRpSm3a7hSWfGKMi0J8MhUhaLA,4667
|
12
|
+
nonebot_plugin_fishing2-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
nonebot_plugin_fishing2-0.0.2.dist-info/top_level.txt,sha256=nSgqw96Nh44l966KEYkw0rbdyEJyzi2V7jCZ1kCZIps,24
|
14
|
+
nonebot_plugin_fishing2-0.0.2.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
nonebot_plugin_fishing2
|
@@ -1,165 +0,0 @@
|
|
1
|
-
from nonebot import on_command, require
|
2
|
-
|
3
|
-
require("nonebot_plugin_orm") # noqa
|
4
|
-
|
5
|
-
from nonebot.plugin import PluginMetadata
|
6
|
-
from nonebot.adapters import Event, Message
|
7
|
-
from nonebot.params import CommandArg
|
8
|
-
from nonebot.permission import SUPERUSER
|
9
|
-
|
10
|
-
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, PrivateMessageEvent, Message, MessageSegment, ActionFailed
|
11
|
-
|
12
|
-
import asyncio
|
13
|
-
|
14
|
-
from typing import Union
|
15
|
-
|
16
|
-
from .config import Config, config
|
17
|
-
from .data_source import (
|
18
|
-
choice,
|
19
|
-
can_fishing,
|
20
|
-
can_catch_special_fish,
|
21
|
-
can_free_fish,
|
22
|
-
get_stats,
|
23
|
-
save_fish,
|
24
|
-
save_special_fish,
|
25
|
-
get_backpack,
|
26
|
-
sell_fish,
|
27
|
-
get_balance,
|
28
|
-
free_fish,
|
29
|
-
random_get_a_special_fish,
|
30
|
-
lottery,
|
31
|
-
give,
|
32
|
-
check_achievement,
|
33
|
-
get_achievements,
|
34
|
-
get_board
|
35
|
-
)
|
36
|
-
|
37
|
-
fishing_coin_name = config.fishing_coin_name
|
38
|
-
|
39
|
-
__plugin_meta__ = PluginMetadata(
|
40
|
-
name="赛博钓鱼",
|
41
|
-
description="你甚至可以电子钓鱼",
|
42
|
-
usage=f'''钓鱼帮助
|
43
|
-
▶ 钓鱼:有 {config.fishing_limit}s 的冷却,时间随上一条鱼稀有度变化
|
44
|
-
▶ 卖鱼 [鱼名] [数量]:卖鱼获得{fishing_coin_name}
|
45
|
-
▶ 放生 [鱼名]:给一条鱼取名并放生
|
46
|
-
▶ 祈愿:向神祈愿,随机获取/损失{fishing_coin_name}
|
47
|
-
▶ 背包:查看背包中的{fishing_coin_name}与物品
|
48
|
-
▶ 成就:查看拥有的成就
|
49
|
-
▶ 钓鱼排行榜:查看{fishing_coin_name}排行榜
|
50
|
-
''',
|
51
|
-
type="application",
|
52
|
-
homepage="https://github.com/ALittleBot/nonebot-plugin-fishing",
|
53
|
-
config=Config,
|
54
|
-
supported_adapters=None,
|
55
|
-
)
|
56
|
-
|
57
|
-
fishing_help = on_command("fishing_help", aliases={"钓鱼帮助"}, priority=3,block=True)
|
58
|
-
fishing = on_command("fishing", aliases={"钓鱼"}, priority=5)
|
59
|
-
backpack = on_command("backpack", aliases={"背包", "钓鱼背包"}, priority=5)
|
60
|
-
sell = on_command("sell", aliases={"卖鱼", "出售"}, priority=5)
|
61
|
-
free_fish_cmd = on_command("free_fish", aliases={"放生", "钓鱼放生"}, priority=5)
|
62
|
-
lottery_cmd = on_command("lottery", aliases={"祈愿"}, priority=5)
|
63
|
-
achievement_cmd = on_command("achievement", aliases={"成就", "钓鱼成就"}, priority=5)
|
64
|
-
give_cmd = on_command("give", aliases={"赐予"}, permission=SUPERUSER, priority=5)
|
65
|
-
board_cmd = on_command("board", aliases={"排行榜", "钓鱼排行榜"}, priority=5)
|
66
|
-
|
67
|
-
|
68
|
-
@fishing_help.handle()
|
69
|
-
async def _():
|
70
|
-
await fishing_help.finish(__plugin_meta__.usage)
|
71
|
-
|
72
|
-
@fishing.handle()
|
73
|
-
async def _(event: Event):
|
74
|
-
user_id = event.get_user_id()
|
75
|
-
if not await can_fishing(user_id):
|
76
|
-
await fishing.finish("河累了, 休息一下吧")
|
77
|
-
await fishing.send("正在钓鱼…")
|
78
|
-
if await can_catch_special_fish():
|
79
|
-
special_fish_name = await random_get_a_special_fish()
|
80
|
-
result = f"你钓到了别人放生的 {special_fish_name}"
|
81
|
-
await save_special_fish(user_id, special_fish_name)
|
82
|
-
await fishing.finish(result)
|
83
|
-
choice_result = choice()
|
84
|
-
fish = choice_result[0]
|
85
|
-
sleep_time = choice_result[1]
|
86
|
-
result = f"钓到了一条{fish}, 你把它收进了背包里"
|
87
|
-
await save_fish(user_id, fish)
|
88
|
-
await asyncio.sleep(sleep_time)
|
89
|
-
achievements = await check_achievement(user_id)
|
90
|
-
if achievements is not None:
|
91
|
-
for achievement in achievements:
|
92
|
-
await fishing.send(achievement)
|
93
|
-
await fishing.finish(MessageSegment.at(user_id) + " " + result)
|
94
|
-
|
95
|
-
|
96
|
-
@backpack.handle()
|
97
|
-
async def _(event: Event):
|
98
|
-
user_id = event.get_user_id()
|
99
|
-
await backpack.finish(MessageSegment.at(user_id) + " \n" + await get_stats(user_id) + "\n" + await get_balance(user_id) + "\n" + await get_backpack(user_id))
|
100
|
-
|
101
|
-
|
102
|
-
@sell.handle()
|
103
|
-
async def _(event: Event, arg: Message = CommandArg()):
|
104
|
-
fish_info = arg.extract_plain_text()
|
105
|
-
user_id = event.get_user_id()
|
106
|
-
if fish_info == "":
|
107
|
-
await sell.finish(MessageSegment.at(user_id) + " " + "请输入要卖出的鱼的名字和数量 (数量为1时可省略), 如 /卖鱼 小鱼 1")
|
108
|
-
if len(fish_info.split()) == 1:
|
109
|
-
await sell.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_info))
|
110
|
-
else:
|
111
|
-
fish_name, fish_quantity = fish_info.split()
|
112
|
-
await sell.finish(MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_name, int(fish_quantity)))
|
113
|
-
|
114
|
-
|
115
|
-
@free_fish_cmd.handle()
|
116
|
-
async def _(event: Event, arg: Message = CommandArg()):
|
117
|
-
if not can_free_fish():
|
118
|
-
await free_fish_cmd.finish("未开启此功能, 请联系机器人管理员")
|
119
|
-
fish_name = arg.extract_plain_text()
|
120
|
-
user_id = event.get_user_id()
|
121
|
-
if fish_name == "":
|
122
|
-
await free_fish_cmd.finish(MessageSegment.at(user_id) + " " + "请输入要放生的鱼的名字, 如 /放生 测试鱼")
|
123
|
-
await free_fish_cmd.finish(MessageSegment.at(user_id) + " " + await free_fish(user_id, fish_name))
|
124
|
-
|
125
|
-
|
126
|
-
@lottery_cmd.handle()
|
127
|
-
async def _(event: Event):
|
128
|
-
user_id = event.get_user_id()
|
129
|
-
await lottery_cmd.finish(MessageSegment.at(user_id) + " " + await lottery(user_id))
|
130
|
-
|
131
|
-
|
132
|
-
@achievement_cmd.handle()
|
133
|
-
async def _(event: Event):
|
134
|
-
user_id = event.get_user_id()
|
135
|
-
await achievement_cmd.finish(MessageSegment.at(user_id) + " " + await get_achievements(user_id))
|
136
|
-
|
137
|
-
|
138
|
-
@give_cmd.handle()
|
139
|
-
async def _(arg: Message = CommandArg()):
|
140
|
-
info = arg.extract_plain_text().split()
|
141
|
-
if len(info) < 2 or len(info) > 3:
|
142
|
-
await give_cmd.finish("请输入用户的 id 和鱼的名字和数量 (数量为1时可省略), 如 /give 114514 开发鱼 1")
|
143
|
-
else:
|
144
|
-
quantity = int(info[2]) if len(info) == 3 else 1
|
145
|
-
await give_cmd.finish(await give(info[0], info[1], quantity))
|
146
|
-
|
147
|
-
|
148
|
-
@board_cmd.handle()
|
149
|
-
async def _(bot: Bot, event: GroupMessageEvent):
|
150
|
-
group_id = event.group_id
|
151
|
-
top_users_list = await get_board()
|
152
|
-
msg = '钓鱼富豪排行榜:'
|
153
|
-
for index, user in enumerate(top_users_list):
|
154
|
-
try:
|
155
|
-
user_info = await bot.get_group_member_info(group_id=group_id, user_id=user[0])
|
156
|
-
username = user_info['card'] if user_info['card'] is not None and user_info['card'] != '' else user_info['nickname']
|
157
|
-
except ActionFailed:
|
158
|
-
username = "[神秘富豪]"
|
159
|
-
|
160
|
-
msg += f'\n{index + 1}. {username}: {user[1]} {fishing_coin_name}'
|
161
|
-
|
162
|
-
await board_cmd.finish(msg)
|
163
|
-
|
164
|
-
|
165
|
-
|
nonebot_plugin_fishing/config.py
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
from pydantic import BaseModel
|
2
|
-
from typing import List, Dict
|
3
|
-
|
4
|
-
try:
|
5
|
-
# pydantic v2
|
6
|
-
from nonebot import get_plugin_config
|
7
|
-
except ImportError:
|
8
|
-
# pydantic v1
|
9
|
-
from nonebot import get_driver
|
10
|
-
|
11
|
-
|
12
|
-
class Config(BaseModel):
|
13
|
-
fishes: List[Dict] = [
|
14
|
-
{
|
15
|
-
"name": "小鱼",
|
16
|
-
"frequency": 2,
|
17
|
-
"weight": 100,
|
18
|
-
"price": 10
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"name": "尚方宝剑",
|
22
|
-
"frequency": 2,
|
23
|
-
"weight": 50,
|
24
|
-
"price": 20
|
25
|
-
},
|
26
|
-
{
|
27
|
-
"name": "小杂鱼~♡",
|
28
|
-
"frequency": 10,
|
29
|
-
"weight": 10,
|
30
|
-
"price": 100
|
31
|
-
},
|
32
|
-
{
|
33
|
-
"name": "烤激光鱼",
|
34
|
-
"frequency": 20,
|
35
|
-
"weight": 1,
|
36
|
-
"price": 1000
|
37
|
-
},
|
38
|
-
{
|
39
|
-
"name": "大傻",
|
40
|
-
"frequency": 30,
|
41
|
-
"weight": 1,
|
42
|
-
"price": 2000
|
43
|
-
}
|
44
|
-
]
|
45
|
-
|
46
|
-
fishing_limit: int = 30
|
47
|
-
|
48
|
-
fishing_coin_name: str = "绿宝石" # It means Fishing Coin.
|
49
|
-
|
50
|
-
special_fish_enabled: bool = True
|
51
|
-
|
52
|
-
special_fish_price: int = 200
|
53
|
-
|
54
|
-
special_fish_probability: float = 0.01
|
55
|
-
|
56
|
-
fishing_achievement: List[Dict] = [
|
57
|
-
{
|
58
|
-
"type": "fishing_frequency",
|
59
|
-
"name": "腥味十足的生意",
|
60
|
-
"data": 1,
|
61
|
-
"description": "钓到一条鱼。"
|
62
|
-
},
|
63
|
-
{
|
64
|
-
"type": "fishing_frequency",
|
65
|
-
"name": "还是钓鱼大佬",
|
66
|
-
"data": 100,
|
67
|
-
"description": "累计钓鱼一百次。"
|
68
|
-
},
|
69
|
-
{
|
70
|
-
"type": "fish_type",
|
71
|
-
"name": "那是鱼吗?",
|
72
|
-
"data": "小杂鱼~♡",
|
73
|
-
"description": "获得#####。[原文如此]"
|
74
|
-
},
|
75
|
-
{
|
76
|
-
"type": "fish_type",
|
77
|
-
"name": "那一晚, 激光鱼和便携式烤炉都喝醉了",
|
78
|
-
"data": "烤激光鱼",
|
79
|
-
"description": "获得烤激光鱼。"
|
80
|
-
},
|
81
|
-
{
|
82
|
-
"type": "fish_type",
|
83
|
-
"name": "你怎么把 Fufu 钓上来了",
|
84
|
-
"data": "大傻",
|
85
|
-
"description": "获得大傻"
|
86
|
-
}
|
87
|
-
]
|
88
|
-
|
89
|
-
|
90
|
-
try:
|
91
|
-
# pydantic v2
|
92
|
-
config = get_plugin_config(Config)
|
93
|
-
except:
|
94
|
-
# pydantic v1
|
95
|
-
config = Config.parse_obj(get_driver().config)
|
@@ -1,39 +0,0 @@
|
|
1
|
-
"""add achievements
|
2
|
-
|
3
|
-
迁移 ID: 1be1c9b715a9
|
4
|
-
父迁移: e9015df43907
|
5
|
-
创建时间: 2024-09-22 17:12:51.193361
|
6
|
-
|
7
|
-
"""
|
8
|
-
from __future__ import annotations
|
9
|
-
|
10
|
-
from collections.abc import Sequence
|
11
|
-
|
12
|
-
from alembic import op
|
13
|
-
import sqlalchemy as sa
|
14
|
-
|
15
|
-
|
16
|
-
revision: str = '1be1c9b715a9'
|
17
|
-
down_revision: str | Sequence[str] | None = 'e9015df43907'
|
18
|
-
branch_labels: str | Sequence[str] | None = None
|
19
|
-
depends_on: str | Sequence[str] | None = None
|
20
|
-
|
21
|
-
|
22
|
-
def upgrade(name: str = "") -> None:
|
23
|
-
if name:
|
24
|
-
return
|
25
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
26
|
-
with op.batch_alter_table('nonebot_plugin_fishing_fishingrecord', schema=None) as batch_op:
|
27
|
-
batch_op.add_column(sa.Column('achievements', sa.TEXT(), nullable=False))
|
28
|
-
|
29
|
-
# ### end Alembic commands ###
|
30
|
-
|
31
|
-
|
32
|
-
def downgrade(name: str = "") -> None:
|
33
|
-
if name:
|
34
|
-
return
|
35
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
36
|
-
with op.batch_alter_table('nonebot_plugin_fishing_fishingrecord', schema=None) as batch_op:
|
37
|
-
batch_op.drop_column('achievements')
|
38
|
-
|
39
|
-
# ### end Alembic commands ###
|
@@ -1,14 +0,0 @@
|
|
1
|
-
nonebot_plugin_fishing/__init__.py,sha256=u8T_bhDTSWlUOqv8GUchjJ0T-v-AwvenbZHtahYDt9Y,6334
|
2
|
-
nonebot_plugin_fishing/config.py,sha256=jJm-KORMyLhNMOhmxqdat381QeOi4CsHyvU3ZSgyO0o,2369
|
3
|
-
nonebot_plugin_fishing/data_source.py,sha256=4uHuquboXQHfKNbZmhJC2p3ASzAEZD8i_5a3Ck_qJnk,18938
|
4
|
-
nonebot_plugin_fishing/model.py,sha256=_DtmxiQhJDiIvY1XOMQZ0HA-ruWY0bexWX9frdhnk0Q,752
|
5
|
-
nonebot_plugin_fishing/migrations/1be1c9b715a9_add_achievements.py,sha256=NELMtqzBf1A1EMsypn83ZIUTaqN27lRmX0H-D2BrOTg,1119
|
6
|
-
nonebot_plugin_fishing/migrations/7609e6d106dd_init_db.py,sha256=tpuIfsS6yPsnGIeMPo16exsEfYZ_urgYAqlCyQ8aw-Y,1386
|
7
|
-
nonebot_plugin_fishing/migrations/c5ab992c9af3_add_achievements.py,sha256=KVj9ADeP03zfW4ZBDmnghbWdxLor3u1yKeho0GaddCI,1119
|
8
|
-
nonebot_plugin_fishing/migrations/e9015df43907_add_special_fishes_field.py,sha256=R4p9vPD5lgg4vmY2KUgF2qIlraxhPYkL93lM5l7wMZw,1094
|
9
|
-
nonebot_plugin_fishing/migrations/f70bdeaec7a4_add_specialfishes_table.py,sha256=DUqv9MTaOSZCBj_9oT2eY3pmWeMnyH0cPj9GyYa5Sag,1194
|
10
|
-
nonebot_plugin_fishing2-0.0.1.dist-info/licenses/LICENSE,sha256=yuLTg7OdKnH7rznCsJ31UJwI4B8_oEP4f_zE7bJS75w,1091
|
11
|
-
nonebot_plugin_fishing2-0.0.1.dist-info/METADATA,sha256=Jr-jeWY5HxDtca1GGRSL1X52guWKRaZBO4DIA3LlrBM,4667
|
12
|
-
nonebot_plugin_fishing2-0.0.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
13
|
-
nonebot_plugin_fishing2-0.0.1.dist-info/top_level.txt,sha256=vuWOK_pk0nchZlJtKePr16LLEgIEjBkPf9aQNSlSsoU,23
|
14
|
-
nonebot_plugin_fishing2-0.0.1.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
nonebot_plugin_fishing
|
File without changes
|
{nonebot_plugin_fishing → nonebot_plugin_fishing2}/migrations/c5ab992c9af3_add_achievements.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.2.dist-info}/licenses/LICENSE
RENAMED
File without changes
|