nonebot-plugin-fishing2 0.0.1__py3-none-any.whl → 0.0.3__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 +302 -0
- nonebot_plugin_fishing2/config.py +201 -0
- {nonebot_plugin_fishing → nonebot_plugin_fishing2}/data_source.py +310 -20
- nonebot_plugin_fishing2/migrations/68463f3e5f33_.py +35 -0
- {nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.3.dist-info}/METADATA +2 -2
- nonebot_plugin_fishing2-0.0.3.dist-info/RECORD +14 -0
- {nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.3.dist-info}/WHEEL +1 -1
- nonebot_plugin_fishing2-0.0.3.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.3.dist-info}/licenses/LICENSE +0 -0
@@ -1,9 +1,13 @@
|
|
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
|
10
|
+
from nonebot.adapters.onebot.v11 import MessageSegment
|
7
11
|
from nonebot_plugin_orm import get_session
|
8
12
|
|
9
13
|
from .config import config
|
@@ -11,17 +15,130 @@ from .model import FishingRecord, SpecialFishes
|
|
11
15
|
|
12
16
|
fishing_coin_name = config.fishing_coin_name
|
13
17
|
fish_list = [fish["name"] for fish in config.fishes]
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
can_catch_fishes = {fish["name"]: fish["weight"] for fish in config.fishes if fish["can_catch"]}
|
19
|
+
can_buy_fishes = [fish["name"] for fish in config.fishes if fish["can_buy"]]
|
20
|
+
can_sell_fishes = [fish["name"] for fish in config.fishes if fish["can_sell"]]
|
21
|
+
|
22
|
+
def get_info(fish_name: str) -> list[MessageSegment]:
|
23
|
+
message = []
|
24
|
+
for fish in config.fishes:
|
25
|
+
if fish.get("name") == fish_name:
|
26
|
+
message1 = ""
|
27
|
+
message1 += f'▶ 名称:{fish_name}\n'
|
28
|
+
message1 += f'▶ 基准价格:{fish["price"]} {fishing_coin_name}\n'
|
29
|
+
message1 += f'▶ 描述:{fish["description"]}\n'
|
30
|
+
message1 += f'▶ {"可钓鱼获取" if fish["can_catch"] else "不可钓鱼获取"},'
|
31
|
+
message1 += f'{"可购买" if fish["can_buy"] else "不可购买"},'
|
32
|
+
message1 += f'{"可出售" if fish["can_sell"] else "不可出售"}'
|
33
|
+
message.append(MessageSegment.text(message1))
|
34
|
+
if fish["can_catch"]:
|
35
|
+
message2 = ""
|
36
|
+
message2 += f'▶ 钓鱼信息:\n'
|
37
|
+
message2 += f' ▷ 基础权重:{fish["weight"]},'
|
38
|
+
message2 += f'上钩时间:{fish["frequency"]}s'
|
39
|
+
message.append(MessageSegment.text(message2))
|
40
|
+
if fish["can_buy"]:
|
41
|
+
message3 = ""
|
42
|
+
message3 += f'▶ 商店信息:\n'
|
43
|
+
message3 += f' ▷ 出售价格:{fish["price"] * 2},'
|
44
|
+
message3 += f'单份数量:{fish.get("amount") if fish.get("amount") else 1}'
|
45
|
+
message.append(MessageSegment.text(message3))
|
46
|
+
if fish.get("props") and fish["props"] != []:
|
47
|
+
message4 = ""
|
48
|
+
message4 += f'▶ 道具信息:\n'
|
49
|
+
message4 += f' ▷ 道具类型:{"鱼饵" if fish["type"] == "fish" else "道具"}\n'
|
50
|
+
message4 += print_props(fish["props"])
|
51
|
+
message.append(MessageSegment.text(message4))
|
52
|
+
return message
|
53
|
+
|
54
|
+
def adjusted_choice(adjusts: list[dict[str, Union[str, int]]] = None) -> str:
|
55
|
+
|
56
|
+
adjusted_fishes = copy.deepcopy(can_catch_fishes)
|
57
|
+
|
58
|
+
if adjusts:
|
59
|
+
for adjust in adjusts:
|
60
|
+
if adjust.get("key") and adjust["key"] not in adjusted_fishes:
|
61
|
+
continue
|
62
|
+
match adjust["type"]:
|
63
|
+
case "normal_fish":
|
64
|
+
for key, weight in can_catch_fishes.items():
|
65
|
+
if weight >= 500 and key in adjusted_fishes:
|
66
|
+
adjusted_fishes[key] += adjust["value"]
|
67
|
+
case "rare_fish":
|
68
|
+
for key, weight in can_catch_fishes.items():
|
69
|
+
if weight < 500 and key in adjusted_fishes:
|
70
|
+
adjusted_fishes[key] += adjust["value"]
|
71
|
+
case "fish":
|
72
|
+
adjusted_fishes[adjust["key"]] += adjust["value"]
|
73
|
+
case "rm_fish":
|
74
|
+
adjusted_fishes.pop(adjust["key"])
|
75
|
+
case "special_fish":
|
76
|
+
pass
|
77
|
+
case _:
|
78
|
+
pass
|
79
|
+
|
80
|
+
adjusted_fishes_list = list(adjusted_fishes.keys())
|
81
|
+
adjusted_weights = list(adjusted_fishes.values())
|
82
|
+
|
83
|
+
for i in range(len(adjusted_weights)):
|
84
|
+
if adjusted_weights[i] < 0:
|
85
|
+
adjusted_weights[i] = 0
|
86
|
+
|
18
87
|
choices = random.choices(
|
19
|
-
|
20
|
-
weights=
|
88
|
+
adjusted_fishes_list,
|
89
|
+
weights=adjusted_weights,
|
90
|
+
)
|
91
|
+
return choices[0]
|
92
|
+
|
93
|
+
|
94
|
+
async def get_fish(user_id: int, tools: list = None) -> str:
|
95
|
+
probability_add = 0
|
96
|
+
adjusts: list[dict[str, Union[str, int]]] = []
|
97
|
+
|
98
|
+
if tools:
|
99
|
+
for tool in tools:
|
100
|
+
adjusts += get_props(tool)
|
101
|
+
|
102
|
+
for adjust in adjusts:
|
103
|
+
if adjust["type"] == "special_fish":
|
104
|
+
probability_add += adjust["value"]
|
105
|
+
|
106
|
+
if await can_catch_special_fish(probability_add):
|
107
|
+
special_fish_name = await random_get_a_special_fish()
|
108
|
+
await save_special_fish(user_id, special_fish_name)
|
109
|
+
result = f"你钓到了别人放生的 {special_fish_name}"
|
110
|
+
return result
|
111
|
+
fish = adjusted_choice(adjusts)
|
112
|
+
sleep_time = get_frequency(fish)
|
113
|
+
result = f"钓到了一条{fish}, 你把它收进了背包里"
|
114
|
+
await asyncio.sleep(sleep_time)
|
115
|
+
await save_fish(user_id, fish)
|
116
|
+
return result
|
117
|
+
|
118
|
+
|
119
|
+
def get_type(fish_name: str) -> list:
|
120
|
+
"""获取鱼的类型"""
|
121
|
+
config_fishes = config.fishes
|
122
|
+
return next(
|
123
|
+
(
|
124
|
+
fish["type"]
|
125
|
+
for fish in config_fishes
|
126
|
+
if fish["name"] == fish_name
|
127
|
+
),
|
128
|
+
"fish"
|
21
129
|
)
|
22
|
-
return choices[0]["name"], choices[0]["frequency"]
|
23
|
-
|
24
130
|
|
131
|
+
def get_props(fish_name: str) -> list:
|
132
|
+
"""获取鱼的属性"""
|
133
|
+
config_fishes = config.fishes
|
134
|
+
return next(
|
135
|
+
(
|
136
|
+
fish["props"]
|
137
|
+
for fish in config_fishes
|
138
|
+
if fish["name"] == fish_name
|
139
|
+
),
|
140
|
+
[]
|
141
|
+
)
|
25
142
|
def get_price(fish_name: str) -> int:
|
26
143
|
"""获取鱼的价格"""
|
27
144
|
config_fishes = config.fishes
|
@@ -33,7 +150,38 @@ def get_price(fish_name: str) -> int:
|
|
33
150
|
),
|
34
151
|
0
|
35
152
|
)
|
153
|
+
|
154
|
+
def get_frequency(fish_name: str) -> int:
|
155
|
+
"""获取鱼的冷却"""
|
156
|
+
config_fishes = config.fishes
|
157
|
+
return next(
|
158
|
+
(
|
159
|
+
fish["frequency"]
|
160
|
+
for fish in config_fishes
|
161
|
+
if fish["name"] == fish_name
|
162
|
+
),
|
163
|
+
60
|
164
|
+
)
|
36
165
|
|
166
|
+
def print_props(props: list) -> str:
|
167
|
+
"""打印鱼的属性"""
|
168
|
+
result = " ▷ 道具效果:\n"
|
169
|
+
for i in range(len(props)):
|
170
|
+
prop = props[i]
|
171
|
+
match prop["type"]:
|
172
|
+
case "normal_fish":
|
173
|
+
result += f" {i + 1}. 普通鱼权重{'增加' if prop['value'] > 0 else '减少'}{prop['value']}\n"
|
174
|
+
case "rare_fish":
|
175
|
+
result += f" {i + 1}. 稀有鱼权重{'增加' if prop['value'] > 0 else '减少'}{prop['value']}\n"
|
176
|
+
case "fish":
|
177
|
+
result += f" {i + 1}. {prop['key']}权重{'增加' if prop['value'] > 0 else '减少'}{prop['value']}\n"
|
178
|
+
case "rm_fish":
|
179
|
+
result += f" {i + 1}. 不会钓到{prop['key']}\n"
|
180
|
+
case "special_fish":
|
181
|
+
result += f" {i + 1}. 特殊鱼概率{'增加' if prop['value'] > 0 else '减少'}{prop['value']}\n"
|
182
|
+
case _:
|
183
|
+
pass
|
184
|
+
return result
|
37
185
|
|
38
186
|
async def random_get_a_special_fish() -> str:
|
39
187
|
"""随机返回一条别人放生的鱼"""
|
@@ -166,11 +314,11 @@ async def save_fish(user_id: str, fish_name: str) -> None:
|
|
166
314
|
await session.commit()
|
167
315
|
|
168
316
|
|
169
|
-
async def can_catch_special_fish():
|
317
|
+
async def can_catch_special_fish(probability_add: int):
|
170
318
|
session = get_session()
|
171
319
|
async with session.begin():
|
172
320
|
records = await session.execute(select(SpecialFishes))
|
173
|
-
return len(records.all()) != 0 and random.random() <= config.special_fish_probability
|
321
|
+
return len(records.all()) != 0 and random.random() <= config.special_fish_probability + probability_add
|
174
322
|
|
175
323
|
|
176
324
|
async def save_special_fish(user_id: str, fish_name: str) -> None:
|
@@ -254,10 +402,12 @@ async def get_backpack(user_id: str) -> str:
|
|
254
402
|
fishes_record = await session.scalar(select_user)
|
255
403
|
if fishes_record:
|
256
404
|
load_fishes = json.loads(fishes_record.fishes)
|
405
|
+
sorted_fishes = {key: load_fishes[key] for key in fish_list if key in load_fishes}
|
257
406
|
load_special_fishes = json.loads(fishes_record.special_fishes)
|
258
407
|
if load_special_fishes:
|
259
|
-
|
260
|
-
|
408
|
+
sorted_special_fishes = {key: load_special_fishes[key] for key in sorted(load_special_fishes)}
|
409
|
+
return print_backpack(sorted_fishes, sorted_special_fishes)
|
410
|
+
return "🎒你的背包里空无一物" if sorted_fishes == {} else print_backpack(sorted_fishes)
|
261
411
|
return "🎒你的背包里空无一物"
|
262
412
|
|
263
413
|
|
@@ -275,6 +425,8 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
275
425
|
"""
|
276
426
|
if quantity <= 0:
|
277
427
|
return "你在卖什么 w(゚Д゚)w"
|
428
|
+
if fish_name not in can_sell_fishes:
|
429
|
+
return f"这个 {fish_name} 不可以卖哦~"
|
278
430
|
session = get_session()
|
279
431
|
async with session.begin():
|
280
432
|
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
@@ -285,7 +437,7 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
285
437
|
if fish_name in loads_fishes and loads_fishes[fish_name] > 0:
|
286
438
|
fish_price = get_price(fish_name)
|
287
439
|
if loads_fishes[fish_name] < quantity:
|
288
|
-
return f"{fish_name}
|
440
|
+
return f"你没有那么多 {fish_name}"
|
289
441
|
loads_fishes[fish_name] -= quantity
|
290
442
|
if loads_fishes[fish_name] == 0:
|
291
443
|
del loads_fishes[fish_name]
|
@@ -303,7 +455,7 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
303
455
|
elif fish_name in spec_fishes and spec_fishes[fish_name] > 0:
|
304
456
|
fish_price = config.special_fish_price
|
305
457
|
if spec_fishes[fish_name] < quantity:
|
306
|
-
return f"{fish_name}
|
458
|
+
return f"你没有那么多 {fish_name}"
|
307
459
|
spec_fishes[fish_name] -= quantity
|
308
460
|
if spec_fishes[fish_name] == 0:
|
309
461
|
del spec_fishes[fish_name]
|
@@ -317,11 +469,53 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
317
469
|
await session.execute(user_update)
|
318
470
|
await session.commit()
|
319
471
|
return (f"你以 {fish_price} {fishing_coin_name} / 条的价格卖出了 {quantity} 条 {fish_name}, "
|
320
|
-
f"
|
472
|
+
f"获得了 {fish_price * quantity} {fishing_coin_name}")
|
321
473
|
else:
|
322
474
|
return "查无此鱼"
|
323
475
|
else:
|
324
476
|
return "还没钓鱼就想卖鱼?"
|
477
|
+
|
478
|
+
|
479
|
+
async def buy_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
480
|
+
if quantity <= 0:
|
481
|
+
return "别在渔具店老板面前炫耀自己的鱼 (..-˘ ˘-.#)"
|
482
|
+
if fish_name not in can_buy_fishes:
|
483
|
+
return "商店不卖这个!"
|
484
|
+
|
485
|
+
for fish in config.fishes:
|
486
|
+
if fish["name"] == fish_name:
|
487
|
+
price = fish["price"] * 2
|
488
|
+
amount = fish["amount"] if fish.get("amount") else 1
|
489
|
+
total_price = price * amount * quantity
|
490
|
+
break
|
491
|
+
|
492
|
+
session = get_session()
|
493
|
+
async with session.begin():
|
494
|
+
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
495
|
+
fishes_record = await session.scalar(select_user)
|
496
|
+
if fishes_record := fishes_record:
|
497
|
+
loads_fishes = json.loads(fishes_record.fishes)
|
498
|
+
user_coin = fishes_record.coin
|
499
|
+
if user_coin < total_price:
|
500
|
+
coin_less = str(total_price - fishes_record.coin)
|
501
|
+
return f"你没有足够的 {fishing_coin_name}, 还需 {coin_less} {fishing_coin_name}"
|
502
|
+
user_coin -= total_price
|
503
|
+
try:
|
504
|
+
loads_fishes[fish_name] += amount * quantity
|
505
|
+
except KeyError:
|
506
|
+
loads_fishes[fish_name] = amount * quantity
|
507
|
+
dump_fishes = json.dumps(loads_fishes)
|
508
|
+
user_update = update(FishingRecord).where(
|
509
|
+
FishingRecord.user_id == user_id
|
510
|
+
).values(
|
511
|
+
coin=user_coin,
|
512
|
+
fishes=dump_fishes
|
513
|
+
)
|
514
|
+
await session.execute(user_update)
|
515
|
+
await session.commit()
|
516
|
+
return (f"你用 {total_price} {fishing_coin_name} 买入了 {quantity * amount} {fish_name}")
|
517
|
+
else:
|
518
|
+
return "不想钓鱼的人就别在渔具店逛了~"
|
325
519
|
|
326
520
|
|
327
521
|
async def get_balance(user_id: str) -> str:
|
@@ -342,11 +536,16 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
342
536
|
fishes_record = await session.scalar(select_user)
|
343
537
|
if fishes_record:
|
344
538
|
user_coin = fishes_record.coin
|
345
|
-
spec_fishes = fishes_record.special_fishes
|
539
|
+
spec_fishes = json.loads(fishes_record.special_fishes)
|
346
540
|
if fish_name in spec_fishes and spec_fishes[fish_name] > 0:
|
347
541
|
spec_fishes[fish_name] -= 1
|
348
542
|
if spec_fishes[fish_name] == 0:
|
349
543
|
del spec_fishes[fish_name]
|
544
|
+
new_record = SpecialFishes(
|
545
|
+
user_id=user_id,
|
546
|
+
fish=fish_name
|
547
|
+
)
|
548
|
+
session.add(new_record)
|
350
549
|
dump_fishes = json.dumps(spec_fishes)
|
351
550
|
user_update = update(FishingRecord).where(
|
352
551
|
FishingRecord.user_id == user_id
|
@@ -357,6 +556,9 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
357
556
|
await session.commit()
|
358
557
|
return f"你再次放生了 {fish_name}, 未来或许会被有缘人钓到呢"
|
359
558
|
else:
|
559
|
+
if fish_name in fish_list:
|
560
|
+
return "普通鱼不能放生哦~"
|
561
|
+
|
360
562
|
if user_coin < config.special_fish_price // 2:
|
361
563
|
special_fish_coin_less = str(config.special_fish_price // 2 - fishes_record.coin)
|
362
564
|
return f"你没有足够的 {fishing_coin_name}, 还需 {special_fish_coin_less} {fishing_coin_name}"
|
@@ -380,13 +582,24 @@ async def free_fish(user_id: str, fish_name: str) -> str:
|
|
380
582
|
async def lottery(user_id: str) -> str:
|
381
583
|
"""算法来自于 https://github.com/fossifer/minesweeperbot/blob/master/cards.py"""
|
382
584
|
session = get_session()
|
585
|
+
time_now = int(time.time())
|
586
|
+
fishing_limit = config.fishing_limit
|
383
587
|
async with session.begin():
|
384
588
|
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
385
589
|
fishes_record = await session.scalar(select_user)
|
386
590
|
if fishes_record:
|
387
591
|
user_coin = fishes_record.coin
|
388
|
-
if user_coin <=
|
389
|
-
|
592
|
+
if user_coin <= 30:
|
593
|
+
new_coin = random.randrange(1, 50)
|
594
|
+
user_update = update(FishingRecord).where(
|
595
|
+
FishingRecord.user_id == user_id
|
596
|
+
).values(
|
597
|
+
time=time_now + fishing_limit,
|
598
|
+
coin=fishes_record.coin + new_coin,
|
599
|
+
)
|
600
|
+
await session.execute(user_update)
|
601
|
+
await session.commit()
|
602
|
+
return f"你穷得连河神都看不下去了,给了你 {new_coin} {fishing_coin_name} w(゚Д゚)w"
|
390
603
|
new_coin = abs(user_coin) / 3
|
391
604
|
new_coin = random.randrange(5000, 15000) / 10000 * new_coin
|
392
605
|
new_coin = int(new_coin) if new_coin > 1 else 1
|
@@ -394,11 +607,14 @@ async def lottery(user_id: str) -> str:
|
|
394
607
|
user_update = update(FishingRecord).where(
|
395
608
|
FishingRecord.user_id == user_id
|
396
609
|
).values(
|
610
|
+
time=time_now + fishing_limit,
|
397
611
|
coin=fishes_record.coin + new_coin,
|
398
612
|
)
|
399
613
|
await session.execute(user_update)
|
400
614
|
await session.commit()
|
401
615
|
return f'你{"获得" if new_coin >= 0 else "血亏"}了 {abs(new_coin)} {fishing_coin_name}'
|
616
|
+
else:
|
617
|
+
return "河神没有回应你……"
|
402
618
|
|
403
619
|
|
404
620
|
async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
@@ -407,6 +623,15 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
407
623
|
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
408
624
|
record = await session.scalar(select_user)
|
409
625
|
if record:
|
626
|
+
if fish_name == 'coin' or fish_name == fishing_coin_name:
|
627
|
+
user_update = update(FishingRecord).where(
|
628
|
+
FishingRecord.user_id == user_id
|
629
|
+
).values(
|
630
|
+
coin=record.coin + quantity,
|
631
|
+
)
|
632
|
+
await session.execute(user_update)
|
633
|
+
await session.commit()
|
634
|
+
return f"使用滥权之力成功为 {user_id} {"增加" if quantity >= 0 else "减少"} {abs(quantity)} {fishing_coin_name} ヾ(≧▽≦*)o"
|
410
635
|
loads_fishes = json.loads(record.fishes)
|
411
636
|
spec_fishes = json.loads(record.special_fishes)
|
412
637
|
if fish_name in fish_list:
|
@@ -435,7 +660,7 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
|
|
435
660
|
)
|
436
661
|
await session.execute(user_update)
|
437
662
|
await session.commit()
|
438
|
-
return f"
|
663
|
+
return f"使用滥权之力成功将 {fish_name} 添加到 {user_id} 的背包之中 ヾ(≧▽≦*)o"
|
439
664
|
return "未查找到用户信息, 无法执行滥权操作 w(゚Д゚)w"
|
440
665
|
|
441
666
|
|
@@ -460,4 +685,69 @@ async def get_board() -> list:
|
|
460
685
|
top_users_list.append((user.user_id, user.coin))
|
461
686
|
top_users_list.sort(key=lambda user: user[1], reverse=True)
|
462
687
|
return top_users_list
|
463
|
-
return []
|
688
|
+
return []
|
689
|
+
|
690
|
+
def get_shop() -> list[MessageSegment]:
|
691
|
+
messages: list[MessageSegment] = []
|
692
|
+
|
693
|
+
messages.append(MessageSegment.text("===== 渔具店 ====="))
|
694
|
+
|
695
|
+
for fish in config.fishes:
|
696
|
+
if fish.get("can_buy"):
|
697
|
+
name = fish["name"]
|
698
|
+
price = fish["price"] * 2
|
699
|
+
amount = fish["amount"] if fish.get("amount") else 1
|
700
|
+
total_price = price * amount
|
701
|
+
desc = fish["description"] if fish.get("description") else ""
|
702
|
+
messages.append(MessageSegment.text(f"商品名:{name} \n单份数量:{amount}\n单价:{price} {fishing_coin_name}\n单份总价:{total_price} {fishing_coin_name}\n描述:{desc}"))
|
703
|
+
|
704
|
+
return messages
|
705
|
+
|
706
|
+
|
707
|
+
async def check_tools(user_id: str, tools: list) -> str | None:
|
708
|
+
# 这是工具吗?
|
709
|
+
for tool in tools:
|
710
|
+
props = get_props(tool)
|
711
|
+
if not props or props == []:
|
712
|
+
return f"搞啥嘞!{tool}既不是工具也不是鱼饵!"
|
713
|
+
|
714
|
+
# 如果有两个工具,是一个工具一个鱼饵吗?
|
715
|
+
if len(tools) == 2:
|
716
|
+
if get_type(tools[0]) == get_type(tools[1]):
|
717
|
+
return "你为啥要用两个类型一样的东西?"
|
718
|
+
|
719
|
+
# 有吗?有吗?
|
720
|
+
session = get_session()
|
721
|
+
async with session.begin():
|
722
|
+
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
723
|
+
fishes_record = await session.scalar(select_user)
|
724
|
+
if fishes_record:
|
725
|
+
loads_fishes = json.loads(fishes_record.fishes)
|
726
|
+
for tool in tools:
|
727
|
+
if tool not in loads_fishes:
|
728
|
+
return f"你哪来的 {tool}?"
|
729
|
+
|
730
|
+
return None
|
731
|
+
|
732
|
+
async def remove_tools(user_id: str, tools: list[str]) -> None:
|
733
|
+
session = get_session()
|
734
|
+
async with session.begin():
|
735
|
+
select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
|
736
|
+
fishes_record = await session.scalar(select_user)
|
737
|
+
if fishes_record:
|
738
|
+
loads_fishes = json.loads(fishes_record.fishes)
|
739
|
+
for tool in tools:
|
740
|
+
loads_fishes[tool] -= 1
|
741
|
+
if loads_fishes[tool] == 0:
|
742
|
+
del loads_fishes[tool]
|
743
|
+
dump_fishes = json.dumps(loads_fishes)
|
744
|
+
user_update = update(FishingRecord).where(
|
745
|
+
FishingRecord.user_id == user_id
|
746
|
+
).values(
|
747
|
+
fishes=dump_fishes
|
748
|
+
)
|
749
|
+
await session.execute(user_update)
|
750
|
+
await session.commit()
|
751
|
+
else:
|
752
|
+
pass
|
753
|
+
# 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 ###
|
{nonebot_plugin_fishing2-0.0.1.dist-info → nonebot_plugin_fishing2-0.0.3.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nonebot-plugin-fishing2
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.3
|
4
4
|
Summary: 更好的电子钓鱼
|
5
5
|
Author-email: ALittleBot <160833462+C14H22O@users.noreply.github.com>, Polaris_Light <995905922@qq.com>
|
6
6
|
License-Expression: MIT
|
@@ -139,6 +139,6 @@ FISHES='
|
|
139
139
|
- [x] 增加系统商店,卖出钓到的鱼们
|
140
140
|
- [x] 赛博放生 [#4](https://github.com/C14H22O/nonebot-plugin-fishing/issues/4) (已基本完成)
|
141
141
|
- [ ] 使用 [nonebot_plugin_chikari_economy](https://github.com/mrqx0195/nonebot_plugin_chikari_economy) 经济系统
|
142
|
-
- [
|
142
|
+
- [x] 为鱼竿增加耐久度,耐久度为0时需重新购买鱼竿
|
143
143
|
- [ ] 为钓鱼背包添加排序
|
144
144
|
- [x] 添加成就系统
|
@@ -0,0 +1,14 @@
|
|
1
|
+
nonebot_plugin_fishing2/__init__.py,sha256=i2tmiGGJ4XUOCwi01tyU092Us1Uw-Trp05hg3rXDMbQ,11607
|
2
|
+
nonebot_plugin_fishing2/config.py,sha256=0eTa7GUt9yUiSS2yLCeo8BEteVWh3Zj3d7utvSEPbFw,5698
|
3
|
+
nonebot_plugin_fishing2/data_source.py,sha256=UkcJzCYu1JMYneCYrL4ZqftuAlfPG7bdiXprl5Q_Le0,31357
|
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.3.dist-info/licenses/LICENSE,sha256=yuLTg7OdKnH7rznCsJ31UJwI4B8_oEP4f_zE7bJS75w,1091
|
11
|
+
nonebot_plugin_fishing2-0.0.3.dist-info/METADATA,sha256=dYqboVGyAKQOhG9ZmVgaEVaG3Tf-ss9ezd6sqSPaQRU,4667
|
12
|
+
nonebot_plugin_fishing2-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
nonebot_plugin_fishing2-0.0.3.dist-info/top_level.txt,sha256=nSgqw96Nh44l966KEYkw0rbdyEJyzi2V7jCZ1kCZIps,24
|
14
|
+
nonebot_plugin_fishing2-0.0.3.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
nonebot_plugin_fishing2
|