nonebot-plugin-fishing2 0.1.0__py3-none-any.whl → 0.1.1__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.
@@ -2,6 +2,7 @@ from nonebot import require
2
2
 
3
3
  require("nonebot_plugin_orm") # noqa
4
4
 
5
+ import copy
5
6
  import shlex
6
7
  from typing import Union
7
8
 
@@ -40,6 +41,7 @@ from .data_source import (
40
41
  buy_fish,
41
42
  predict,
42
43
  get_pool,
44
+ remove_special_fish,
43
45
  )
44
46
  from .fish_helper import fish_list, get_fish_by_name
45
47
 
@@ -53,27 +55,28 @@ cool_down = (
53
55
  __plugin_meta__ = PluginMetadata(
54
56
  name="更好的电子钓鱼",
55
57
  description="赛博钓鱼……但是加强版本",
56
- usage=f"""▶ 查询 [物品]:查询某个物品的信息
58
+ usage=f"""▶ 钓鱼帮助:打印本信息
59
+ ▶ 查询 [物品]:查询某个物品的信息
57
60
  ▶ 钓鱼 [鱼竿] [鱼饵]:
58
61
  ▷ 钓鱼后有 {cool_down} 的冷却,频繁钓鱼会触怒河神
59
62
  ▷ {config.no_fish_probability} 概率空军,{config.special_fish_probability} 概率钓到特殊鱼
60
63
  ▷ 加参数可以使用鱼饵或鱼竿,同类物品同时只能使用一种
61
- ▶ 出售 <物品> <数量>:出售物品获得{fishing_coin_name}
62
- 如果卖不出去,尝试用英文双引号框住鱼名
63
- ▶ 购买 <物品> <份数>:购买渔具店的物品
64
+ ▶ 出售 [-i] [-s] <物品或序号> [数量]:出售物品获得{fishing_coin_name}
65
+ -i 按照序号卖鱼 -s 卖特殊鱼
66
+ ▶ 购买 <物品> [份数]:购买物品
64
67
  ▶ 放生 <鱼名>:给一条鱼取名并放生
65
68
  ▷ 不要放生奇怪名字的鱼
66
69
  ▶ 商店:看看渔具店都有些啥
67
- 祈愿:向神祈愿,随机获取/损失{fishing_coin_name}
70
+ 祈愿:向神祈愿{fishing_coin_name}
68
71
  ▶ 背包:查看背包中的{fishing_coin_name}与物品
69
72
  ▶ 成就:查看拥有的成就
70
73
  ▶ 钓鱼排行榜:查看{fishing_coin_name}排行榜
71
74
  """,
72
75
  type="application",
73
- homepage="https://github.com/FDCraft/nonebot-plugin-fishing2",
76
+ homepage="https://github.com/GLDYM/nonebot-plugin-fishing2",
74
77
  config=Config,
75
78
  supported_adapters={"~onebot.v11"},
76
- extra={"author": "Polaris_Light", "version": "0.1.0", "priority": 5},
79
+ extra={"author": "Polaris_Light", "version": "0.1.1", "priority": 5},
77
80
  )
78
81
 
79
82
 
@@ -91,18 +94,36 @@ sell = on_command("sell", aliases={"卖鱼", "出售", "售卖"}, force_whitespa
91
94
  free_fish_cmd = on_command("free_fish", aliases={"放生", "钓鱼放生"}, force_whitespace=True, priority=5)
92
95
  lottery_cmd = on_command("lottery", aliases={"祈愿"}, force_whitespace=True, priority=5)
93
96
  achievement_cmd = on_command("achievement", aliases={"成就", "钓鱼成就"}, force_whitespace=True, priority=5)
94
- give_cmd = on_command("give", aliases={"赐予"}, force_whitespace=True, priority=5)
95
97
  board_cmd = on_command("board", aliases={"排行榜", "钓鱼排行榜"}, force_whitespace=True, priority=5)
96
98
 
97
99
  # hidden cmd
100
+ give_cmd = on_command("give", aliases={"赐予"}, force_whitespace=True, priority=5)
98
101
  predict_cmd = on_command("predict", aliases={"钓鱼预测"}, force_whitespace=True, priority=5)
99
102
  pool_cmd = on_command("pool", aliases={"鱼池"}, force_whitespace=True, priority=5)
103
+ remove_cmd = on_command("remove", aliases={"捞鱼"}, force_whitespace=True, priority=5)
100
104
  # fmt:on
101
105
 
102
106
 
103
107
  @fishing_help.handle()
104
- async def _():
105
- await fishing_help.finish(__plugin_meta__.usage)
108
+ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
109
+ user_id = event.get_user_id()
110
+ is_superuser = str(user_id) in bot.config.superusers
111
+ is_self = event.self_id == user_id
112
+
113
+ if not is_superuser and not is_self:
114
+ await fishing_help.finish(__plugin_meta__.usage)
115
+ else:
116
+ messages: list[MessageSegment] = []
117
+ messages.append(MessageSegment.text(__plugin_meta__.usage))
118
+ message2 = """以下为管理员命令:
119
+ ▶ 背包 [QQ或at]:让我看看
120
+ ▶ 赐予 [-i] [-s] <QQ或at> <物品或序号> [数量]:神秘力量
121
+ ▶ 钓鱼预测 [鱼竿] [鱼饵]:预测钓鱼
122
+ ▶ 鱼池 [鱼名长度最大值] [单页长度最大值]:查看所有特殊鱼
123
+ ▶ 捞鱼 [-i] <物品或序号>:捞出鱼池内特殊鱼
124
+ """
125
+ messages.append(MessageSegment.text(message2))
126
+ await forward_send(bot, event, messages)
106
127
 
107
128
 
108
129
  @shop.handle()
@@ -138,14 +159,19 @@ async def _(
138
159
 
139
160
 
140
161
  @fishing.handle()
141
- async def _(bot: Bot, event: Event, matcher: Matcher, arg: Message = CommandArg()):
162
+ async def _(
163
+ bot: Bot,
164
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
165
+ matcher: Matcher,
166
+ arg: Message = CommandArg(),
167
+ ):
142
168
  user_id = event.get_user_id()
143
169
  if user_id in block_user_list:
144
170
  await fishing.finish()
145
171
 
146
172
  tools = shlex.split((arg.extract_plain_text()))[:2]
147
173
 
148
- logger.debug(f"Fishing: {user_id} try to use {tools}")
174
+ logger.info(f"Fishing: {user_id} try to use {tools}")
149
175
 
150
176
  check_result = await check_tools(user_id, tools)
151
177
  if check_result:
@@ -199,26 +225,85 @@ async def _(
199
225
 
200
226
 
201
227
  @pool_cmd.handle()
202
- async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
228
+ async def _(
229
+ bot: Bot,
230
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
231
+ arg: Message = CommandArg(),
232
+ ):
203
233
  user_id = event.get_user_id()
204
234
  is_superuser = str(user_id) in bot.config.superusers
205
235
  is_self = event.self_id == user_id
206
236
  if not is_superuser and not is_self:
207
237
  return None
208
238
 
209
- messages: list[MessageSegment] = await get_pool()
239
+ args = shlex.split(arg.extract_plain_text())
240
+
241
+ match len(args):
242
+ case 0:
243
+ messages = await get_pool()
244
+ case 1:
245
+ if not args[0].isdigit():
246
+ await pool_cmd.finish(MessageSegment.text("你完全不看帮助是吗  ̄へ ̄"))
247
+ messages = await get_pool(int(args[0]))
248
+ case 2:
249
+ if not args[0].isdigit() or not args[1].isdigit():
250
+ await pool_cmd.finish(MessageSegment.text("你完全不看帮助是吗  ̄へ ̄"))
251
+ messages = await get_pool(int(args[0]), int(args[1]))
210
252
 
211
253
  await forward_send(bot, event, messages)
212
254
  return None
213
255
 
214
256
 
257
+ @remove_cmd.handle()
258
+ async def _(
259
+ bot: Bot,
260
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
261
+ arg: Message = CommandArg(),
262
+ ):
263
+ user_id = event.get_user_id()
264
+ is_superuser = str(user_id) in bot.config.superusers
265
+ is_self = event.self_id == user_id
266
+ if not is_superuser and not is_self:
267
+ return None
268
+
269
+ args = shlex.split(arg.extract_plain_text())
270
+ as_index = False
271
+ for arg in copy.deepcopy(args):
272
+ if arg in ["-i", "--index"]:
273
+ as_index = True
274
+ args.remove(arg)
275
+
276
+ name_or_index = args[0]
277
+ result = await remove_special_fish(name_or_index, as_index)
278
+ await remove_cmd.finish(result)
279
+
280
+
215
281
  @backpack.handle()
216
- async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
282
+ async def _(
283
+ bot: Bot,
284
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
285
+ arg: Message = CommandArg(),
286
+ ):
217
287
  user_id = event.get_user_id()
288
+ is_superuser = str(user_id) in bot.config.superusers
289
+ is_self = event.self_id == user_id
290
+ if not is_superuser and not is_self:
291
+ user_id = user_id
292
+ else:
293
+ args = shlex.split(arg.extract_plain_text())
294
+ target = await get_at(event)
295
+ if target:
296
+ args.insert(0, target)
297
+ if len(args) >= 1:
298
+ user_id = args[0]
299
+ else:
300
+ user_id = user_id
301
+
218
302
  if not config.backpack_forward:
219
303
  await backpack.finish(
220
- MessageSegment.at(user_id)
221
- + " \n"
304
+ (MessageSegment.at(user_id) + " \n")
305
+ if isinstance(event, GroupMessageEvent)
306
+ else ""
222
307
  + await get_stats(user_id)
223
308
  + "\n"
224
309
  + await get_balance(user_id)
@@ -227,7 +312,8 @@ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
227
312
  )
228
313
  else:
229
314
  messages: list[MessageSegment] = []
230
- messages.append(MessageSegment.at(user_id))
315
+ if isinstance(event, GroupMessageEvent):
316
+ messages.append(MessageSegment.at(user_id))
231
317
  messages.append(await get_stats(user_id))
232
318
  messages.append(await get_balance(user_id))
233
319
  backpacks = await get_backpack(user_id)
@@ -236,7 +322,9 @@ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
236
322
 
237
323
 
238
324
  @buy.handle()
239
- async def _(event: Event, arg: Message = CommandArg()):
325
+ async def _(
326
+ event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
327
+ ):
240
328
  args = arg.extract_plain_text().split(" ")
241
329
  args = [x for x in args if x != ""]
242
330
 
@@ -261,29 +349,49 @@ async def _(event: Event, arg: Message = CommandArg()):
261
349
 
262
350
 
263
351
  @sell.handle()
264
- async def _(event: Event, arg: Message = CommandArg()):
352
+ async def _(
353
+ event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
354
+ ):
265
355
  args = shlex.split(arg.extract_plain_text())
266
-
267
356
  user_id = event.get_user_id()
357
+ as_index = False
358
+ as_special = False
359
+
360
+ logger.info(f"Sell: {user_id} sells :{args}")
361
+
268
362
  if args == []:
269
363
  await sell.finish(
270
364
  MessageSegment.at(user_id)
271
365
  + " "
272
366
  + "请输入要卖出的鱼的名字和数量 (数量为1时可省略), 如 /卖鱼 小鱼 1"
273
367
  )
368
+
369
+ for arg in copy.deepcopy(args):
370
+ if arg in ["-i", "--index"]:
371
+ as_index = True
372
+ args.remove(arg)
373
+ if arg in ["-s", "--spec", "--special"]:
374
+ as_special = True
375
+ args.remove(arg)
376
+
274
377
  if len(args) == 1:
275
- fish_name = args[0]
276
- await sell.finish(
277
- MessageSegment.at(user_id) + " " + await sell_fish(user_id, fish_name)
278
- )
378
+ name_or_index = args[0]
379
+ fish_quantity = 1
279
380
  else:
280
- fish_name, fish_quantity = args[0], args[1]
281
- result = await sell_fish(user_id, fish_name, int(fish_quantity))
282
- await sell.finish(MessageSegment.at(user_id) + " " + result)
381
+ name_or_index, fish_quantity = args[0], args[1]
382
+
383
+ result = await sell_fish(
384
+ user_id, name_or_index, int(fish_quantity), as_index, as_special
385
+ )
386
+ await sell.finish(MessageSegment.at(user_id) + " " + result)
283
387
 
284
388
 
285
389
  @free_fish_cmd.handle()
286
- async def _(bot: Bot, event: Event, arg: Message = CommandArg()):
390
+ async def _(
391
+ bot: Bot,
392
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
393
+ arg: Message = CommandArg(),
394
+ ):
287
395
  if not config.special_fish_enabled:
288
396
  await free_fish_cmd.finish("未开启此功能, 请联系机器人管理员")
289
397
 
@@ -296,7 +404,7 @@ async def _(bot: Bot, event: Event, arg: Message = CommandArg()):
296
404
  or "\u200d" in fish_name
297
405
  or "\u2060" in fish_name
298
406
  or "\ufeff" in fish_name
299
- ):
407
+ ): # TODO: 检测特殊字符
300
408
  if isinstance(event, GroupMessageEvent):
301
409
  group_id = event.group_id
302
410
  await bot.set_group_ban(group_id=group_id, user_id=user_id, duration=1800)
@@ -314,7 +422,9 @@ async def _(bot: Bot, event: Event, arg: Message = CommandArg()):
314
422
 
315
423
 
316
424
  @lottery_cmd.handle()
317
- async def _(bot: Bot, event: Event, matcher: Matcher):
425
+ async def _(
426
+ bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent], matcher: Matcher
427
+ ):
318
428
  user_id = event.get_user_id()
319
429
  try:
320
430
  await punish(bot, event, matcher, user_id)
@@ -345,17 +455,27 @@ async def _(
345
455
  if not is_superuser and not is_self:
346
456
  return None
347
457
 
348
- target = await get_at(event)
349
458
  args = shlex.split(arg.extract_plain_text())
459
+
460
+ for arg in copy.deepcopy(args):
461
+ if arg in ["-i", "--index"]:
462
+ as_index = True
463
+ args.remove(arg)
464
+ if arg in ["-s", "--spec", "--special"]:
465
+ as_special = True
466
+ args.remove(arg)
467
+
468
+ target = await get_at(event)
350
469
  if target:
351
470
  args.insert(0, target)
471
+
352
472
  if len(args) < 2 or len(args) > 3:
353
473
  await give_cmd.finish(
354
474
  "请输入用户的 id 和鱼的名字和数量 (数量为1时可省略), 如 /give 114514 开发鱼 1"
355
475
  )
356
476
  else:
357
477
  quantity = int(args[2]) if len(args) == 3 else 1
358
- result = await give(args[0], args[1], quantity)
478
+ result = await give(args[0], args[1], quantity, as_index, as_special)
359
479
  achievements = await check_achievement(args[0])
360
480
  if achievements is not None:
361
481
  for achievement in achievements:
@@ -390,7 +510,12 @@ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
390
510
  await board_cmd.finish(msg)
391
511
 
392
512
 
393
- async def punish(bot: Bot, event: Event, matcher: Matcher, user_id: int):
513
+ async def punish(
514
+ bot: Bot,
515
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
516
+ matcher: Matcher,
517
+ user_id: int,
518
+ ):
394
519
  global punish_user_dict
395
520
 
396
521
  if not await can_fishing(user_id):
@@ -4,7 +4,7 @@ import random
4
4
  import time
5
5
  import json
6
6
 
7
- from typing import Union
7
+ from collections.abc import Hashable
8
8
  from sqlalchemy import select, update, delete
9
9
  from sqlalchemy.sql.expression import func
10
10
  from nonebot.adapters.onebot.v11 import MessageSegment
@@ -15,6 +15,23 @@ from .model import FishingRecord, SpecialFishes
15
15
  from .fish_helper import *
16
16
 
17
17
 
18
+ def get_key_by_index(
19
+ dict: dict, index: int, default: Hashable | None = None
20
+ ) -> Hashable | None:
21
+ """Utils: get the key of OrderedDict by index.
22
+
23
+ Args:
24
+ dict (dict)
25
+ index (int)
26
+ default (Hashable | None, optional): default value. Defaults to None.
27
+
28
+ Returns:
29
+ Hashable | None: a key of dict.
30
+ """
31
+ key_list = list(dict.keys())
32
+ return key_list[index] if index < len(key_list) else default
33
+
34
+
18
35
  async def can_fishing(user_id: str) -> bool:
19
36
  time_now = int(time.time())
20
37
  session = get_session()
@@ -395,17 +412,44 @@ async def save_special_fish(user_id: str, fish_name: str) -> None:
395
412
  await session.commit()
396
413
 
397
414
 
398
- async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
415
+ async def sell_fish(
416
+ user_id: str,
417
+ name_or_index: str,
418
+ quantity: int = 1,
419
+ as_index: bool = False,
420
+ as_special: bool = False,
421
+ ) -> str:
399
422
  if quantity <= 0:
400
423
  return "你在卖什么 w(゚Д゚)w"
424
+
401
425
  session = get_session()
402
426
  async with session.begin():
403
427
  select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
404
428
  fishes_record = await session.scalar(select_user)
405
429
  if fishes_record := fishes_record:
406
430
  loads_fishes = json.loads(fishes_record.fishes)
431
+ loads_fishes = {
432
+ key: loads_fishes[key] for key in fish_list if key in loads_fishes
433
+ }
434
+
407
435
  spec_fishes = json.loads(fishes_record.special_fishes)
408
- if fish_name in loads_fishes and loads_fishes[fish_name] > 0:
436
+ spec_fishes = dict(sorted(spec_fishes.items()))
437
+
438
+ if as_index:
439
+ if not name_or_index.isdigit():
440
+ return "你完全不看帮助是吗  ̄へ ̄"
441
+ load_dict = loads_fishes if not as_special else spec_fishes
442
+ fish_name = get_key_by_index(load_dict, int(name_or_index))
443
+ if not fish_name:
444
+ return "查无此鱼"
445
+ else:
446
+ fish_name = name_or_index
447
+
448
+ if (
449
+ not as_special
450
+ and fish_name in loads_fishes
451
+ and loads_fishes[fish_name] > 0
452
+ ):
409
453
  if fish_name not in can_sell_fishes:
410
454
  return f"这个 {fish_name} 不可以卖哦~"
411
455
  if loads_fishes[fish_name] < quantity:
@@ -425,6 +469,7 @@ async def sell_fish(user_id: str, fish_name: str, quantity: int = 1) -> str:
425
469
  )
426
470
  await session.execute(user_update)
427
471
  await session.commit()
472
+
428
473
  return (
429
474
  f"你以 {fish_price} {fishing_coin_name} / 条的价格卖出了 {quantity} 条 {fish_name}, "
430
475
  f"你获得了 {fish_price * quantity} {fishing_coin_name}"
@@ -584,13 +629,20 @@ async def lottery(user_id: str) -> str:
584
629
  return "河神没有回应你……"
585
630
 
586
631
 
587
- async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
632
+ async def give(
633
+ user_id: str,
634
+ name_or_index: str,
635
+ quantity: int = 1,
636
+ as_index: bool = False,
637
+ as_special: bool = False,
638
+ ) -> str:
588
639
  session = get_session()
589
640
  async with session.begin():
590
641
  select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
591
642
  record = await session.scalar(select_user)
592
643
  if record:
593
- if fish_name == "coin" or fish_name == fishing_coin_name:
644
+
645
+ if name_or_index == "coin" or name_or_index == fishing_coin_name:
594
646
  user_update = (
595
647
  update(FishingRecord)
596
648
  .where(FishingRecord.user_id == user_id)
@@ -601,13 +653,27 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
601
653
  await session.execute(user_update)
602
654
  await session.commit()
603
655
  return f"使用滥权之力成功为 {user_id} {"增加" if quantity >= 0 else "减少"} {abs(quantity)} {fishing_coin_name} ヾ(≧▽≦*)o"
656
+
604
657
  loads_fishes = json.loads(record.fishes)
605
658
  spec_fishes = json.loads(record.special_fishes)
606
- if fish_name in fish_list:
659
+
660
+ if as_index:
661
+ if not name_or_index.isdigit():
662
+ return "你完全不看帮助是吗  ̄へ ̄"
663
+ load_dict = loads_fishes if not as_special else spec_fishes
664
+ fish_name = get_key_by_index(load_dict, int(name_or_index))
665
+ if not fish_name:
666
+ return "查无此鱼,你再看看这人背包呢?"
667
+ else:
668
+ fish_name = name_or_index
669
+
670
+ if not as_special and fish_name in fish_list:
607
671
  try:
608
672
  loads_fishes[fish_name] += quantity
609
673
  except KeyError:
610
674
  loads_fishes[fish_name] = quantity
675
+ if loads_fishes[fish_name] <= 0:
676
+ del loads_fishes[fish_name]
611
677
  dump_fishes = json.dumps(loads_fishes)
612
678
  user_update = (
613
679
  update(FishingRecord)
@@ -621,6 +687,8 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
621
687
  spec_fishes[fish_name] += quantity
622
688
  except KeyError:
623
689
  spec_fishes[fish_name] = quantity
690
+ if spec_fishes[fish_name] <= 0:
691
+ del spec_fishes[fish_name]
624
692
  dump_fishes = json.dumps(spec_fishes)
625
693
  user_update = (
626
694
  update(FishingRecord)
@@ -629,26 +697,24 @@ async def give(user_id: str, fish_name: str, quantity: int = 1) -> str:
629
697
  )
630
698
  await session.execute(user_update)
631
699
  await session.commit()
700
+
701
+ fish_name = (
702
+ fish_name[:20] + "..." + str(len(fish_name) - 20)
703
+ if len(fish_name) > 20
704
+ else fish_name
705
+ )
632
706
  return (
633
- f"使用滥权之力成功将 {fish_name} 添加到 {user_id} 的背包之中 ヾ(≧▽≦*)o"
707
+ f"使用滥权之力成功为 {user_id} {"增加" if quantity >= 0 else "减少"} {abs(quantity)} {fish_name} ヾ(≧▽≦*)o"
634
708
  )
635
709
  return "未查找到用户信息, 无法执行滥权操作 w(゚Д゚)w"
636
710
 
637
711
 
638
- async def get_all_special_fish() -> list[str]:
712
+ async def get_all_special_fish() -> dict[str, int]:
639
713
  session = get_session()
640
714
  async with session.begin():
641
715
  random_select = select(SpecialFishes.fish).order_by(SpecialFishes.fish.asc())
642
716
  data = await session.scalars(random_select)
643
- result = data.all()
644
- return result
645
-
646
-
647
- async def get_pool() -> list[MessageSegment]:
648
-
649
- messages: list[MessageSegment] = []
650
- pool = await get_all_special_fish()
651
- messages.append(MessageSegment.text(f"现在鱼池里面有 {len(pool)} 条鱼。"))
717
+ pool = data.all()
652
718
 
653
719
  result = dict()
654
720
  for fish in pool:
@@ -657,14 +723,65 @@ async def get_pool() -> list[MessageSegment]:
657
723
  except KeyError:
658
724
  result[fish] = 1
659
725
 
726
+ return result
727
+
728
+
729
+ async def remove_special_fish(name_or_index: str, as_index: bool = False) -> str | None:
730
+ pool = await get_all_special_fish()
731
+
732
+ if as_index:
733
+ if not name_or_index.isdigit():
734
+ return "你完全不看帮助是吗  ̄へ ̄"
735
+ fish_name = get_key_by_index(pool, int(name_or_index))
736
+ if not fish_name:
737
+ return "查无此鱼"
738
+ else:
739
+ fish_name = name_or_index
740
+ if fish_name not in pool:
741
+ return "查无此鱼"
742
+
743
+ session = get_session()
744
+ async with session.begin():
745
+ delete_fishes = delete(SpecialFishes).where(SpecialFishes.fish == fish_name)
746
+ await session.execute(delete_fishes)
747
+ await session.commit()
748
+
749
+ fish_name = (
750
+ fish_name[:20] + "..." + str(len(fish_name) - 20)
751
+ if len(fish_name) > 20
752
+ else fish_name
753
+ )
754
+
755
+ return f"已成功捞出 {fish_name}"
756
+
757
+
758
+ async def get_pool(name_limit: int = 30, page_limit: int = 200) -> list[MessageSegment]:
759
+ messages: list[MessageSegment] = []
760
+ pool = await get_all_special_fish()
761
+ messages.append(
762
+ MessageSegment.text(f"现在鱼池里面有 {sum(list(pool.values()))} 条鱼。")
763
+ )
764
+
660
765
  msg = "鱼池列表:\n"
661
- for fish, num in result.items():
662
- if len(msg) > 300:
663
- msg += f"{fish} x {num}"
766
+ i = 0
767
+ j = 1
768
+ for fish, num in pool.items():
769
+ if len(msg) > page_limit:
770
+ fish = (
771
+ fish[:name_limit] + "..." + str(len(fish) - name_limit)
772
+ if len(fish) > name_limit
773
+ else fish
774
+ )
775
+ msg += f"{i}. {fish} x {num}\n"
776
+ msg += f"【第 {j} 页结束】"
664
777
  messages.append(MessageSegment.text(msg))
665
778
  msg = ""
779
+ i += 1
780
+ j += 1
666
781
  else:
667
- msg += f"{fish} x {num}\n"
782
+ fish = fish[:name_limit] + "..." if len(fish) > name_limit else fish
783
+ msg += f"{i}. {fish} x {num}\n"
784
+ i += 1
668
785
  else:
669
786
  messages.append(MessageSegment.text(msg))
670
787
 
@@ -697,33 +814,35 @@ async def get_backpack(user_id: str) -> list[str]:
697
814
  select_user = select(FishingRecord).where(FishingRecord.user_id == user_id)
698
815
  fishes_record = await session.scalar(select_user)
699
816
  if fishes_record:
700
- load_fishes = json.loads(fishes_record.fishes)
701
- sorted_fishes = {
702
- key: load_fishes[key] for key in fish_list if key in load_fishes
817
+ loads_fishes = json.loads(fishes_record.fishes)
818
+ loads_fishes = {
819
+ key: loads_fishes[key] for key in fish_list if key in loads_fishes
703
820
  }
704
- load_special_fishes = json.loads(fishes_record.special_fishes)
705
- if load_special_fishes:
706
- sorted_special_fishes = {
707
- key: load_special_fishes[key] for key in sorted(load_special_fishes)
708
- }
709
- return print_backpack(sorted_fishes, sorted_special_fishes)
821
+ spec_fishes: dict = json.loads(fishes_record.special_fishes)
822
+ if spec_fishes:
823
+ spec_fishes = dict(sorted(spec_fishes.items()))
824
+ return print_backpack(loads_fishes, spec_fishes)
710
825
  return (
711
826
  ["🎒你的背包里空无一物"]
712
- if sorted_fishes == {}
713
- else print_backpack(sorted_fishes)
827
+ if loads_fishes == {}
828
+ else print_backpack(loads_fishes)
714
829
  )
715
830
  return ["🎒你的背包里空无一物"]
716
831
 
717
832
 
718
- def print_backpack(backpack: dict, special_backpack=None) -> list[str]:
719
- result = [
720
- f"{fish_name}×{str(quantity)}" for fish_name, quantity in backpack.items()
721
- ]
833
+ def print_backpack(backpack: dict, special_backpack: dict = None) -> list[str]:
834
+ i = 0
835
+ result = []
836
+ for fish_name, quantity in backpack.items():
837
+ result.append(f"{i}. {fish_name}×{str(quantity)}")
838
+ i += 1
839
+
722
840
  if special_backpack:
723
- special_result = [
724
- f"{fish_name}×{str(quantity)}"
725
- for fish_name, quantity in special_backpack.items()
726
- ]
841
+ i = 0
842
+ special_result: list[str] = []
843
+ for fish_name, quantity in special_backpack.items():
844
+ special_result.append(f"{i}. {fish_name}×{str(quantity)}")
845
+ i += 1
727
846
  return [
728
847
  "🎒普通鱼:\n" + "\n".join(result),
729
848
  "🎒特殊鱼:\n" + "\n".join(special_result),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nonebot-plugin-fishing2
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: 更好的电子钓鱼
5
5
  License: MIT
6
6
  Keywords: fishing
@@ -21,16 +21,12 @@ Requires-Dist: nonebot-plugin-orm (>=0.7.1)
21
21
  Requires-Dist: nonebot2 (>=2.2.1)
22
22
  Requires-Dist: pydantic (>=1.10)
23
23
  Requires-Dist: sqlalchemy (>=2.0.27)
24
- Project-URL: Homepage, https://github.com/FDCraft/nonebot-plugin-fishing2
24
+ Project-URL: Homepage, https://github.com/GLDYM/nonebot-plugin-fishing2
25
25
  Description-Content-Type: text/markdown
26
26
 
27
27
  <div align="center">
28
- <a href="https://v2.nonebot.dev/store"><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
29
- <br>
30
- <p><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg" width="240" alt="NoneBotPluginText"></p>
31
- </div>
32
-
33
- <div align="center">
28
+ <a href="https://v2.nonebot.dev/store">
29
+ <img src="https://raw.githubusercontent.com/fllesser/nonebot-plugin-template/refs/heads/resource/.docs/NoneBotPlugin.svg" width="310" alt="logo"></a>
34
30
 
35
31
  # nonebot-plugin-fishing2
36
32
 
@@ -147,14 +143,7 @@ FISHES='
147
143
 
148
144
  ### 指令表
149
145
 
150
- 在群聊或私聊发送“钓鱼帮助”查看本插件的帮助,或者使用[NoneBot-Plugin-PicMenu-Next](https://github.com/lgc-NB2Dev/nonebot-plugin-picmenu-next)等帮助插件查看。
151
-
152
- ### 管理员指令表
153
-
154
- | 指令 | 范围 | 说明 |
155
- |:--------:|:----:|:----------------------------------------------:|
156
- | 钓鱼预测 | 所有 | 对钓鱼进行模拟,查看各鱼的概率与期望,便于填表 |
157
- | 鱼池 | 所有 | 查看数据库里面的所有特殊鱼 |
146
+ 在群聊或私聊发送“钓鱼帮助”查看本插件的帮助,或者使用[NoneBot-Plugin-PicMenu-Next](https://github.com/lgc-NB2Dev/nonebot-plugin-picmenu-next)等帮助插件查看。管理员指令默认隐藏,只能由 SUPERUSER 发送“钓鱼帮助”查看。
158
147
 
159
148
  ### 赛博放生
160
149
 
@@ -170,7 +159,7 @@ FISHES='
170
159
  - [x] 为钓鱼背包添加排序
171
160
  - [x] 添加成就系统
172
161
  - [x] 买装备!
173
- - [ ] 支持卖与普通鱼同名的特殊鱼
174
- - [ ] 管理员命令:捞鱼
162
+ - [x] 支持卖与普通鱼同名的特殊鱼
163
+ - [x] 管理员命令:捞鱼
175
164
  - [ ] 屏蔽词库
176
165
 
@@ -1,6 +1,6 @@
1
- nonebot_plugin_fishing2/__init__.py,sha256=F-CFOiu-FwvAxofCbeGLqPjI81_gfQNQhsoWu59sH5s,16436
1
+ nonebot_plugin_fishing2/__init__.py,sha256=P-rLNXG2ZmdfzU7UXSwWrnh4jT8OI2fsm3LPy6COrh8,20200
2
2
  nonebot_plugin_fishing2/config.py,sha256=xYDdq9Rwce8vfg-M91lUd2TfZDQnToHlI77GdpLFp-U,9751
3
- nonebot_plugin_fishing2/data_source.py,sha256=-8fttiui-tCr3r9-c3U7_PLdxbryW-f_uJFXhhHl1Sc,30778
3
+ nonebot_plugin_fishing2/data_source.py,sha256=fbIWF4nJ1GVQ17UCue_RcEPxi_2oRmByhkveAXI_6oU,34488
4
4
  nonebot_plugin_fishing2/fish_helper.py,sha256=Rf3SX4UcM0-E6apLUbHB40I4onK-8qPZmZrsVBMnZ3I,6054
5
5
  nonebot_plugin_fishing2/migrations/68463f3e5f33_.py,sha256=WnaV5T1uCHvYWcnepHqV9kOurDYddFUvXXfA2Rtd5Ok,776
6
6
  nonebot_plugin_fishing2/migrations/7609e6d106dd_init_db.py,sha256=tpuIfsS6yPsnGIeMPo16exsEfYZ_urgYAqlCyQ8aw-Y,1386
@@ -8,7 +8,7 @@ nonebot_plugin_fishing2/migrations/c5ab992c9af3_add_achievements.py,sha256=KVj9A
8
8
  nonebot_plugin_fishing2/migrations/e9015df43907_add_special_fishes_field.py,sha256=R4p9vPD5lgg4vmY2KUgF2qIlraxhPYkL93lM5l7wMZw,1094
9
9
  nonebot_plugin_fishing2/migrations/f70bdeaec7a4_add_specialfishes_table.py,sha256=DUqv9MTaOSZCBj_9oT2eY3pmWeMnyH0cPj9GyYa5Sag,1194
10
10
  nonebot_plugin_fishing2/model.py,sha256=_DtmxiQhJDiIvY1XOMQZ0HA-ruWY0bexWX9frdhnk0Q,752
11
- nonebot_plugin_fishing2-0.1.0.dist-info/LICENSE,sha256=n-2xoOXX434-tBisMKX2-_FycV2VrmIiTP1rZvuW_fY,1091
12
- nonebot_plugin_fishing2-0.1.0.dist-info/METADATA,sha256=g5XWZCLnZ9nGAwW5GUXaEF8g_2yHLe7XEGH0mFxY6Ag,7793
13
- nonebot_plugin_fishing2-0.1.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
14
- nonebot_plugin_fishing2-0.1.0.dist-info/RECORD,,
11
+ nonebot_plugin_fishing2-0.1.1.dist-info/LICENSE,sha256=n-2xoOXX434-tBisMKX2-_FycV2VrmIiTP1rZvuW_fY,1091
12
+ nonebot_plugin_fishing2-0.1.1.dist-info/METADATA,sha256=-sV5ctEfIgmreAt6aDgmEPA6GRUeskeBk4XEpeV2JQ4,7355
13
+ nonebot_plugin_fishing2-0.1.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
14
+ nonebot_plugin_fishing2-0.1.1.dist-info/RECORD,,