nonebot-plugin-fishing2 0.1.1__py3-none-any.whl → 1.0.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.
@@ -1,591 +1,601 @@
1
- from nonebot import require
2
-
3
- require("nonebot_plugin_orm") # noqa
4
-
5
- import copy
6
- import shlex
7
- from typing import Union
8
-
9
- from nonebot import on_command, logger
10
- from nonebot.plugin import PluginMetadata
11
- from nonebot.adapters import Event, Message
12
- from nonebot.params import CommandArg
13
- from nonebot.matcher import Matcher
14
-
15
- from nonebot.adapters.onebot.v11 import (
16
- Bot,
17
- GroupMessageEvent,
18
- PrivateMessageEvent,
19
- Message,
20
- MessageSegment,
21
- ActionFailed,
22
- )
23
-
24
- from .config import Config, config
25
- from .data_source import (
26
- can_fishing,
27
- get_fish,
28
- get_stats,
29
- get_backpack,
30
- sell_fish,
31
- get_balance,
32
- free_fish,
33
- lottery,
34
- give,
35
- check_achievement,
36
- get_achievements,
37
- get_board,
38
- check_tools,
39
- remove_tools,
40
- get_shop,
41
- buy_fish,
42
- predict,
43
- get_pool,
44
- remove_special_fish,
45
- )
46
- from .fish_helper import fish_list, get_fish_by_name
47
-
48
- fishing_coin_name = config.fishing_coin_name
49
- cool_down = (
50
- f"{config.fishing_cooldown_time_min}s~{config.fishing_cooldown_time_max}s"
51
- if config.fishing_cooldown_time_min != config.fishing_cooldown_time_max
52
- else f"{config.fishing_cooldown_time_min}s"
53
- ) # 浮动 CD 法力无边,有效遏制频繁钓鱼
54
-
55
- __plugin_meta__ = PluginMetadata(
56
- name="更好的电子钓鱼",
57
- description="赛博钓鱼……但是加强版本",
58
- usage=f"""▶ 钓鱼帮助:打印本信息
59
- ▶ 查询 [物品]:查询某个物品的信息
60
- ▶ 钓鱼 [鱼竿] [鱼饵]:
61
- ▷ 钓鱼后有 {cool_down} 的冷却,频繁钓鱼会触怒河神
62
- ▷ {config.no_fish_probability} 概率空军,{config.special_fish_probability} 概率钓到特殊鱼
63
- ▷ 加参数可以使用鱼饵或鱼竿,同类物品同时只能使用一种
64
- ▶ 出售 [-i] [-s] <物品或序号> [数量]:出售物品获得{fishing_coin_name}
65
- ▷ -i 按照序号卖鱼 -s 卖特殊鱼
66
- ▶ 购买 <物品> [份数]:购买物品
67
- ▶ 放生 <鱼名>:给一条鱼取名并放生
68
- ▷ 不要放生奇怪名字的鱼
69
- ▶ 商店:看看渔具店都有些啥
70
- ▶ 祈愿:向神祈愿{fishing_coin_name}
71
- ▶ 背包:查看背包中的{fishing_coin_name}与物品
72
- ▶ 成就:查看拥有的成就
73
- ▶ 钓鱼排行榜:查看{fishing_coin_name}排行榜
74
- """,
75
- type="application",
76
- homepage="https://github.com/GLDYM/nonebot-plugin-fishing2",
77
- config=Config,
78
- supported_adapters={"~onebot.v11"},
79
- extra={"author": "Polaris_Light", "version": "0.1.1", "priority": 5},
80
- )
81
-
82
-
83
- block_user_list = []
84
- punish_user_dict = {}
85
-
86
- # fmt:off
87
- fishing_help = on_command("fishing_help", aliases={"钓鱼帮助"}, force_whitespace=True, priority=3, block=True)
88
- fishing_lookup = on_command("fishing_lookup",aliases={"查看", "查询"},force_whitespace=True,priority=3,block=True,)
89
- fishing = on_command("fishing", aliases={"钓鱼"}, force_whitespace=True, priority=5)
90
- backpack = on_command("backpack", aliases={"背包", "钓鱼背包"}, force_whitespace=True, priority=5)
91
- shop = on_command("shop", aliases={"商店"}, force_whitespace=True, priority=5)
92
- buy = on_command("buy", aliases={"购买"}, force_whitespace=True, priority=5)
93
- sell = on_command("sell", aliases={"卖鱼", "出售", "售卖"}, force_whitespace=True, priority=5)
94
- free_fish_cmd = on_command("free_fish", aliases={"放生", "钓鱼放生"}, force_whitespace=True, priority=5)
95
- lottery_cmd = on_command("lottery", aliases={"祈愿"}, force_whitespace=True, priority=5)
96
- achievement_cmd = on_command("achievement", aliases={"成就", "钓鱼成就"}, force_whitespace=True, priority=5)
97
- board_cmd = on_command("board", aliases={"排行榜", "钓鱼排行榜"}, force_whitespace=True, priority=5)
98
-
99
- # hidden cmd
100
- give_cmd = on_command("give", aliases={"赐予"}, force_whitespace=True, priority=5)
101
- predict_cmd = on_command("predict", aliases={"钓鱼预测"}, force_whitespace=True, priority=5)
102
- pool_cmd = on_command("pool", aliases={"鱼池"}, force_whitespace=True, priority=5)
103
- remove_cmd = on_command("remove", aliases={"捞鱼"}, force_whitespace=True, priority=5)
104
- # fmt:on
105
-
106
-
107
- @fishing_help.handle()
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)
127
-
128
-
129
- @shop.handle()
130
- async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
131
- messages = get_shop()
132
- await forward_send(bot, event, messages)
133
- return None
134
-
135
-
136
- @fishing_lookup.handle()
137
- async def _(
138
- bot: Bot,
139
- event: Union[GroupMessageEvent, PrivateMessageEvent],
140
- arg: Message = CommandArg(),
141
- ):
142
- user_id = event.get_user_id()
143
- arg = arg.extract_plain_text()
144
- if not arg or arg == "":
145
- await fishing_lookup.finish(
146
- "请输入要查询的物品\n可查询物品:" + "、".join(fish_list)
147
- )
148
- if arg == "空军":
149
- await fishing_lookup.finish(
150
- MessageSegment.at(user_id)
151
- + " 在钓鱼活动中,空军指钓鱼者一无所获,没有钓到任何鱼,空手而归。"
152
- )
153
- elif arg not in fish_list:
154
- await fishing_lookup.finish(MessageSegment.at(user_id) + " 查无此鱼。")
155
-
156
- messages = get_fish_by_name(arg).print_info()
157
- await forward_send(bot, event, messages)
158
- return None
159
-
160
-
161
- @fishing.handle()
162
- async def _(
163
- bot: Bot,
164
- event: Union[GroupMessageEvent, PrivateMessageEvent],
165
- matcher: Matcher,
166
- arg: Message = CommandArg(),
167
- ):
168
- user_id = event.get_user_id()
169
- if user_id in block_user_list:
170
- await fishing.finish()
171
-
172
- tools = shlex.split((arg.extract_plain_text()))[:2]
173
-
174
- logger.info(f"Fishing: {user_id} try to use {tools}")
175
-
176
- check_result = await check_tools(user_id, tools)
177
- if check_result:
178
- await fishing.finish(MessageSegment.at(user_id) + " " + check_result)
179
-
180
- await punish(bot, event, matcher, user_id)
181
- block_user_list.append(user_id)
182
- try:
183
- await remove_tools(user_id, tools)
184
- await fishing.send(
185
- MessageSegment.at(user_id) + f'\n你使用了{"、".join(tools)}\n'
186
- if tools != []
187
- else "" + "正在钓鱼…"
188
- )
189
- result = await get_fish(user_id, tools)
190
- achievements = await check_achievement(user_id)
191
- if achievements is not None:
192
- for achievement in achievements:
193
- await fishing.send(achievement)
194
- except Exception as e:
195
- result = "河神睡着了……"
196
- logger.error(e)
197
- finally:
198
- block_user_list.remove(user_id)
199
- punish_user_dict.pop(user_id, None)
200
- await fishing.finish(MessageSegment.at(user_id) + " " + result)
201
-
202
-
203
- @predict_cmd.handle()
204
- async def _(
205
- bot: Bot,
206
- event: Union[GroupMessageEvent, PrivateMessageEvent],
207
- arg: Message = CommandArg(),
208
- ):
209
- user_id = event.get_user_id()
210
-
211
- is_superuser = str(user_id) in bot.config.superusers
212
- is_self = event.self_id == user_id
213
- if not is_superuser and not is_self:
214
- return None
215
-
216
- tools = shlex.split(arg.extract_plain_text())[:2]
217
-
218
- tools = [x for x in tools if x != ""]
219
-
220
- check_result = await check_tools(user_id, tools, check_have=False)
221
- if check_result:
222
- await predict_cmd.finish(MessageSegment.at(user_id) + " " + check_result)
223
- result = predict(tools)
224
- await predict_cmd.finish(result)
225
-
226
-
227
- @pool_cmd.handle()
228
- async def _(
229
- bot: Bot,
230
- event: Union[GroupMessageEvent, PrivateMessageEvent],
231
- arg: Message = CommandArg(),
232
- ):
233
- user_id = event.get_user_id()
234
- is_superuser = str(user_id) in bot.config.superusers
235
- is_self = event.self_id == user_id
236
- if not is_superuser and not is_self:
237
- return None
238
-
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]))
252
-
253
- await forward_send(bot, event, messages)
254
- return None
255
-
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
-
281
- @backpack.handle()
282
- async def _(
283
- bot: Bot,
284
- event: Union[GroupMessageEvent, PrivateMessageEvent],
285
- arg: Message = CommandArg(),
286
- ):
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
-
302
- if not config.backpack_forward:
303
- await backpack.finish(
304
- (MessageSegment.at(user_id) + " \n")
305
- if isinstance(event, GroupMessageEvent)
306
- else ""
307
- + await get_stats(user_id)
308
- + "\n"
309
- + await get_balance(user_id)
310
- + "\n"
311
- + "\n\n".join(await get_backpack(user_id))
312
- )
313
- else:
314
- messages: list[MessageSegment] = []
315
- if isinstance(event, GroupMessageEvent):
316
- messages.append(MessageSegment.at(user_id))
317
- messages.append(await get_stats(user_id))
318
- messages.append(await get_balance(user_id))
319
- backpacks = await get_backpack(user_id)
320
- messages += [MessageSegment.text(msg) for msg in backpacks]
321
- await forward_send(bot, event, messages)
322
-
323
-
324
- @buy.handle()
325
- async def _(
326
- event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
327
- ):
328
- args = arg.extract_plain_text().split(" ")
329
- args = [x for x in args if x != ""]
330
-
331
- user_id = event.get_user_id()
332
- if args == []:
333
- await buy.finish(
334
- MessageSegment.at(user_id)
335
- + " "
336
- + "请输入要买入物品的名字和份数 (份数为1时可省略), 如 /购买 钛金鱼竿 1"
337
- )
338
- if len(args) == 1:
339
- fish_name = args[0]
340
- result = await buy_fish(user_id, fish_name)
341
- else:
342
- fish_name, fish_quantity = args[0], args[1]
343
- result = await buy_fish(user_id, fish_name, int(fish_quantity))
344
- achievements = await check_achievement(user_id)
345
- if achievements is not None:
346
- for achievement in achievements:
347
- await fishing.send(achievement)
348
- await buy.finish(MessageSegment.at(user_id) + " " + result)
349
-
350
-
351
- @sell.handle()
352
- async def _(
353
- event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
354
- ):
355
- args = shlex.split(arg.extract_plain_text())
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
-
362
- if args == []:
363
- await sell.finish(
364
- MessageSegment.at(user_id)
365
- + " "
366
- + "请输入要卖出的鱼的名字和数量 (数量为1时可省略), 如 /卖鱼 小鱼 1"
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
-
377
- if len(args) == 1:
378
- name_or_index = args[0]
379
- fish_quantity = 1
380
- else:
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)
387
-
388
-
389
- @free_fish_cmd.handle()
390
- async def _(
391
- bot: Bot,
392
- event: Union[GroupMessageEvent, PrivateMessageEvent],
393
- arg: Message = CommandArg(),
394
- ):
395
- if not config.special_fish_enabled:
396
- await free_fish_cmd.finish("未开启此功能, 请联系机器人管理员")
397
-
398
- fish_name = arg.extract_plain_text()
399
- user_id = event.get_user_id()
400
-
401
- if (
402
- "\u200b" in fish_name
403
- or "\u200c" in fish_name
404
- or "\u200d" in fish_name
405
- or "\u2060" in fish_name
406
- or "\ufeff" in fish_name
407
- ): # TODO: 检测特殊字符
408
- if isinstance(event, GroupMessageEvent):
409
- group_id = event.group_id
410
- await bot.set_group_ban(group_id=group_id, user_id=user_id, duration=1800)
411
- await free_fish_cmd.finish(
412
- MessageSegment.at(user_id) + " " + "你 TM 在放生什么?滚滚滚"
413
- )
414
-
415
- if fish_name == "":
416
- await free_fish_cmd.finish(
417
- MessageSegment.at(user_id) + " " + "请输入要放生的鱼的名字, 如 /放生 测试鱼"
418
- )
419
- await free_fish_cmd.finish(
420
- MessageSegment.at(user_id) + " " + await free_fish(user_id, fish_name)
421
- )
422
-
423
-
424
- @lottery_cmd.handle()
425
- async def _(
426
- bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent], matcher: Matcher
427
- ):
428
- user_id = event.get_user_id()
429
- try:
430
- await punish(bot, event, matcher, user_id)
431
- result = await lottery(user_id)
432
- except:
433
- result = "河神睡着了……"
434
- finally:
435
- punish_user_dict.pop(user_id, None)
436
- await lottery_cmd.finish(MessageSegment.at(user_id) + " " + result)
437
-
438
-
439
- @achievement_cmd.handle()
440
- async def _(event: Event):
441
- user_id = event.get_user_id()
442
- await achievement_cmd.finish(
443
- MessageSegment.at(user_id) + " " + await get_achievements(user_id)
444
- )
445
-
446
-
447
- @give_cmd.handle()
448
- async def _(
449
- bot: Bot,
450
- event: Union[GroupMessageEvent, PrivateMessageEvent],
451
- arg: Message = CommandArg(),
452
- ):
453
- is_superuser = str(event.user_id) in bot.config.superusers
454
- is_self = event.self_id == event.user_id
455
- if not is_superuser and not is_self:
456
- return None
457
-
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)
469
- if target:
470
- args.insert(0, target)
471
-
472
- if len(args) < 2 or len(args) > 3:
473
- await give_cmd.finish(
474
- "请输入用户的 id 和鱼的名字和数量 (数量为1时可省略), /give 114514 开发鱼 1"
475
- )
476
- else:
477
- quantity = int(args[2]) if len(args) == 3 else 1
478
- result = await give(args[0], args[1], quantity, as_index, as_special)
479
- achievements = await check_achievement(args[0])
480
- if achievements is not None:
481
- for achievement in achievements:
482
- await fishing.send(achievement)
483
- await give_cmd.finish(result)
484
-
485
-
486
- @board_cmd.handle()
487
- async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
488
- top_users_list = await get_board()
489
- msg = "钓鱼富豪排行榜:"
490
- for index, user in enumerate(top_users_list):
491
- try:
492
- if isinstance(event, GroupMessageEvent):
493
- group_id = event.group_id
494
- user_info = await bot.get_group_member_info(
495
- group_id=group_id, user_id=user[0]
496
- )
497
- username = (
498
- user_info["card"]
499
- if user_info["card"] is not None and user_info["card"] != ""
500
- else user_info["nickname"]
501
- )
502
- elif isinstance(event, PrivateMessageEvent):
503
- user_info = await bot.get_stranger_info(user_id=user[0])
504
- username = user_info["nickname"]
505
- except ActionFailed:
506
- username = "[神秘富豪]"
507
-
508
- msg += f"\n{index + 1}. {username}: {user[1]} {fishing_coin_name}"
509
-
510
- await board_cmd.finish(msg)
511
-
512
-
513
- async def punish(
514
- bot: Bot,
515
- event: Union[GroupMessageEvent, PrivateMessageEvent],
516
- matcher: Matcher,
517
- user_id: int,
518
- ):
519
- global punish_user_dict
520
-
521
- if not await can_fishing(user_id):
522
- try:
523
- punish_user_dict[user_id] += 1
524
- except KeyError:
525
- punish_user_dict[user_id] = 1
526
-
527
- if punish_user_dict[user_id] < config.punish_limit - 1:
528
- await matcher.finish(
529
- MessageSegment.at(user_id) + " " + "河累了,休息一下吧"
530
- )
531
- elif punish_user_dict[user_id] == config.punish_limit - 1:
532
- await matcher.finish(MessageSegment.at(user_id) + " " + "河神快要不耐烦了")
533
- elif punish_user_dict[user_id] == config.punish_limit:
534
- groud_id = event.group_id if isinstance(event, GroupMessageEvent) else None
535
- try:
536
- await bot.set_group_ban(
537
- group_id=groud_id, user_id=user_id, duration=1800
538
- )
539
- except ActionFailed:
540
- pass
541
- await matcher.finish(
542
- MessageSegment.at(user_id) + " " + "河神生气了,降下了惩罚"
543
- )
544
- else:
545
- await matcher.finish()
546
-
547
-
548
- async def forward_send(
549
- bot: Bot,
550
- event: Union[GroupMessageEvent, PrivateMessageEvent],
551
- messages: list[MessageSegment],
552
- ) -> None:
553
- if isinstance(event, GroupMessageEvent):
554
- await bot.send_group_forward_msg(
555
- group_id=event.group_id,
556
- messages=[
557
- {
558
- "type": "node",
559
- "data": {
560
- "name": "花花",
561
- "uin": bot.self_id,
562
- "content": msg,
563
- },
564
- }
565
- for msg in messages
566
- ],
567
- )
568
- else:
569
- await bot.send_private_forward_msg(
570
- user_id=event.user_id,
571
- messages=[
572
- {
573
- "type": "node",
574
- "data": {
575
- "name": "花花",
576
- "uin": bot.self_id,
577
- "content": msg,
578
- },
579
- }
580
- for msg in messages
581
- ],
582
- )
583
-
584
-
585
- async def get_at(event: Union[GroupMessageEvent, PrivateMessageEvent]) -> int:
586
- if isinstance(event, GroupMessageEvent):
587
- msg = event.get_message()
588
- for msg_seg in msg:
589
- if msg_seg.type == "at":
590
- return msg_seg.data["qq"]
591
- return None
1
+ from nonebot import require
2
+
3
+ require("nonebot_plugin_orm") # noqa
4
+
5
+ import copy
6
+ import shlex
7
+ from typing import Union
8
+
9
+ from nonebot import on_command, logger
10
+ from nonebot.plugin import PluginMetadata
11
+ from nonebot.adapters import Event, Message
12
+ from nonebot.params import CommandArg
13
+ from nonebot.matcher import Matcher
14
+
15
+ from nonebot.adapters.onebot.v11 import (
16
+ Bot,
17
+ GroupMessageEvent,
18
+ PrivateMessageEvent,
19
+ Message,
20
+ MessageSegment,
21
+ ActionFailed,
22
+ )
23
+
24
+ from .config import Config, config
25
+ from .data_source import (
26
+ can_fishing,
27
+ get_fish,
28
+ get_stats,
29
+ get_backpack,
30
+ sell_fish,
31
+ get_balance,
32
+ free_fish,
33
+ lottery,
34
+ give,
35
+ check_achievement,
36
+ get_achievements,
37
+ get_board,
38
+ check_tools,
39
+ remove_tools,
40
+ get_shop,
41
+ buy_fish,
42
+ predict,
43
+ get_pool,
44
+ remove_special_fish,
45
+ )
46
+ from .fish_helper import fish_list, get_fish_by_name
47
+
48
+ fishing_coin_name = config.fishing_coin_name
49
+ cool_down = (
50
+ f"{config.fishing_cooldown_time_min}s~{config.fishing_cooldown_time_max}s"
51
+ if config.fishing_cooldown_time_min != config.fishing_cooldown_time_max
52
+ else f"{config.fishing_cooldown_time_min}s"
53
+ ) # 浮动 CD 法力无边,有效遏制频繁钓鱼
54
+
55
+ __plugin_meta__ = PluginMetadata(
56
+ name="更好的电子钓鱼",
57
+ description="赛博钓鱼……但是加强版本",
58
+ usage=f"""▶ 钓鱼帮助:打印本信息
59
+ ▶ 查询 [物品]:查询某个物品的信息
60
+ ▶ 钓鱼 [鱼竿] [鱼饵]:
61
+ ▷ 钓鱼后有 {cool_down} 的冷却,频繁钓鱼会触怒河神
62
+ ▷ {config.no_fish_probability} 概率空军,{config.special_fish_probability} 概率钓到特殊鱼
63
+ ▷ 加参数可以使用鱼饵或鱼竿,同类物品同时只能使用一种
64
+ ▶ 出售 [-i] [-s] <物品或序号> [数量]:出售物品获得{fishing_coin_name}
65
+ ▷ -i 按照序号卖鱼 -s 卖特殊鱼
66
+ ▶ 购买 <物品> [份数]:购买物品
67
+ ▶ 放生 <鱼名>:给一条鱼取名并放生
68
+ ▷ 不要放生奇怪名字的鱼
69
+ ▶ 商店:看看渔具店都有些啥
70
+ ▶ 祈愿:向神祈愿{fishing_coin_name}
71
+ ▶ 背包:查看背包中的{fishing_coin_name}与物品
72
+ ▶ 成就:查看拥有的成就
73
+ ▶ 钓鱼排行榜:查看{fishing_coin_name}排行榜
74
+ """,
75
+ type="application",
76
+ homepage="https://github.com/GLDYM/nonebot-plugin-fishing2",
77
+ config=Config,
78
+ supported_adapters={"~onebot.v11"},
79
+ extra={"author": "Polaris_Light", "version": "1.0.0", "priority": 5},
80
+ )
81
+
82
+
83
+ block_user_list = []
84
+ punish_user_dict = {}
85
+
86
+ # fmt:off
87
+ fishing_help = on_command("fishing_help", aliases={"钓鱼帮助"}, force_whitespace=True, priority=3, block=True)
88
+ fishing_lookup = on_command("fishing_lookup",aliases={"查看", "查询"},force_whitespace=True,priority=3,block=True,)
89
+ fishing = on_command("fishing", aliases={"钓鱼"}, force_whitespace=True, priority=5)
90
+ backpack = on_command("backpack", aliases={"背包", "钓鱼背包"}, force_whitespace=True, priority=5)
91
+ shop = on_command("shop", aliases={"商店"}, force_whitespace=True, priority=5)
92
+ buy = on_command("buy", aliases={"购买"}, force_whitespace=True, priority=5)
93
+ sell = on_command("sell", aliases={"卖鱼", "出售", "售卖"}, force_whitespace=True, priority=5)
94
+ free_fish_cmd = on_command("free_fish", aliases={"放生", "钓鱼放生"}, force_whitespace=True, priority=5)
95
+ lottery_cmd = on_command("lottery", aliases={"祈愿"}, force_whitespace=True, priority=5)
96
+ achievement_cmd = on_command("achievement", aliases={"成就", "钓鱼成就"}, force_whitespace=True, priority=5)
97
+ board_cmd = on_command("board", aliases={"排行榜", "钓鱼排行榜"}, force_whitespace=True, priority=5)
98
+
99
+ # hidden cmd
100
+ give_cmd = on_command("give", aliases={"赐予"}, force_whitespace=True, priority=5)
101
+ predict_cmd = on_command("predict", aliases={"钓鱼预测"}, force_whitespace=True, priority=5)
102
+ pool_cmd = on_command("pool", aliases={"鱼池"}, force_whitespace=True, priority=5)
103
+ remove_cmd = on_command("remove", aliases={"捞鱼"}, force_whitespace=True, priority=5)
104
+ # fmt:on
105
+
106
+
107
+ @fishing_help.handle()
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)
127
+
128
+
129
+ @shop.handle()
130
+ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
131
+ messages = get_shop()
132
+ await forward_send(bot, event, messages)
133
+ return None
134
+
135
+
136
+ @fishing_lookup.handle()
137
+ async def _(
138
+ bot: Bot,
139
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
140
+ arg: Message = CommandArg(),
141
+ ):
142
+ user_id = event.get_user_id()
143
+ arg = arg.extract_plain_text()
144
+ if not arg or arg == "":
145
+ await fishing_lookup.finish(
146
+ "请输入要查询的物品\n可查询物品:" + "、".join(fish_list)
147
+ )
148
+ if arg == "空军":
149
+ await fishing_lookup.finish(
150
+ MessageSegment.at(user_id)
151
+ + " 在钓鱼活动中,空军指钓鱼者一无所获,没有钓到任何鱼,空手而归。"
152
+ )
153
+ elif arg not in fish_list:
154
+ await fishing_lookup.finish(MessageSegment.at(user_id) + " 查无此鱼。")
155
+
156
+ messages = get_fish_by_name(arg).print_info()
157
+ await forward_send(bot, event, messages)
158
+ return None
159
+
160
+
161
+ @fishing.handle()
162
+ async def _(
163
+ bot: Bot,
164
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
165
+ matcher: Matcher,
166
+ arg: Message = CommandArg(),
167
+ ):
168
+ user_id = event.get_user_id()
169
+ if user_id in block_user_list:
170
+ await fishing.finish()
171
+
172
+ tools = shlex.split((arg.extract_plain_text()))[:2]
173
+
174
+ logger.info(f"Fishing: {user_id} try to use {tools}")
175
+
176
+ check_result = await check_tools(user_id, tools)
177
+ if check_result:
178
+ await fishing.finish(MessageSegment.at(user_id) + " " + check_result)
179
+
180
+ await punish(bot, event, matcher, user_id)
181
+ block_user_list.append(user_id)
182
+ try:
183
+ await remove_tools(user_id, tools)
184
+ await fishing.send(
185
+ MessageSegment.at(user_id) + f'\n你使用了{"、".join(tools)}\n'
186
+ if tools != []
187
+ else "" + "正在钓鱼…"
188
+ )
189
+ result = await get_fish(user_id, tools)
190
+ achievements = await check_achievement(user_id)
191
+ if achievements is not None:
192
+ for achievement in achievements:
193
+ await fishing.send(achievement)
194
+ except Exception as e:
195
+ result = "河神睡着了……"
196
+ logger.error(e)
197
+ finally:
198
+ block_user_list.remove(user_id)
199
+ punish_user_dict.pop(user_id, None)
200
+ await fishing.finish(MessageSegment.at(user_id) + " " + result)
201
+
202
+
203
+ @predict_cmd.handle()
204
+ async def _(
205
+ bot: Bot,
206
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
207
+ arg: Message = CommandArg(),
208
+ ):
209
+ user_id = event.get_user_id()
210
+
211
+ is_superuser = str(user_id) in bot.config.superusers
212
+ is_self = event.self_id == user_id
213
+ if not is_superuser and not is_self:
214
+ return None
215
+
216
+ tools = shlex.split(arg.extract_plain_text())[:2]
217
+
218
+ tools = [x for x in tools if x != ""]
219
+
220
+ check_result = await check_tools(user_id, tools, check_have=False)
221
+ if check_result:
222
+ await predict_cmd.finish(MessageSegment.at(user_id) + " " + check_result)
223
+ result = predict(tools)
224
+ await predict_cmd.finish(result)
225
+
226
+
227
+ @pool_cmd.handle()
228
+ async def _(
229
+ bot: Bot,
230
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
231
+ arg: Message = CommandArg(),
232
+ ):
233
+ user_id = event.get_user_id()
234
+ is_superuser = str(user_id) in bot.config.superusers
235
+ is_self = event.self_id == user_id
236
+ if not is_superuser and not is_self:
237
+ return None
238
+
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]))
252
+
253
+ await forward_send(bot, event, messages)
254
+ return None
255
+
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
+
281
+ @backpack.handle()
282
+ async def _(
283
+ bot: Bot,
284
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
285
+ arg: Message = CommandArg(),
286
+ ):
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
+
302
+ if not config.backpack_forward:
303
+ await backpack.finish(
304
+ (MessageSegment.at(user_id) + " \n")
305
+ if isinstance(event, GroupMessageEvent)
306
+ else ""
307
+ + await get_stats(user_id)
308
+ + "\n"
309
+ + await get_balance(user_id)
310
+ + "\n"
311
+ + "\n\n".join(await get_backpack(user_id))
312
+ )
313
+ else:
314
+ messages: list[MessageSegment] = []
315
+ if isinstance(event, GroupMessageEvent):
316
+ messages.append(MessageSegment.at(user_id))
317
+ messages.append(await get_stats(user_id))
318
+ messages.append(await get_balance(user_id))
319
+ try:
320
+ backpacks = await get_backpack(user_id)
321
+ await forward_send(bot, event, messages + [MessageSegment.text(msg) for msg in backpacks])
322
+ except ActionFailed:
323
+ backpacks = await get_backpack(user_id, 40)
324
+ await forward_send(bot, event, messages + [MessageSegment.text(msg) for msg in backpacks])
325
+
326
+
327
+
328
+ @buy.handle()
329
+ async def _(
330
+ event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
331
+ ):
332
+ args = arg.extract_plain_text().split(" ")
333
+ args = [x for x in args if x != ""]
334
+
335
+ user_id = event.get_user_id()
336
+ if args == []:
337
+ await buy.finish(
338
+ MessageSegment.at(user_id)
339
+ + " "
340
+ + "请输入要买入物品的名字和份数 (份数为1时可省略), 如 /购买 钛金鱼竿 1"
341
+ )
342
+ if len(args) == 1:
343
+ fish_name = args[0]
344
+ result = await buy_fish(user_id, fish_name)
345
+ else:
346
+ fish_name, fish_quantity = args[0], args[1]
347
+ result = await buy_fish(user_id, fish_name, int(fish_quantity))
348
+ achievements = await check_achievement(user_id)
349
+ if achievements is not None:
350
+ for achievement in achievements:
351
+ await fishing.send(achievement)
352
+ await buy.finish(MessageSegment.at(user_id) + " " + result)
353
+
354
+
355
+ @sell.handle()
356
+ async def _(
357
+ event: Union[GroupMessageEvent, PrivateMessageEvent], arg: Message = CommandArg()
358
+ ):
359
+ args = shlex.split(arg.extract_plain_text())
360
+ user_id = event.get_user_id()
361
+ as_index = False
362
+ as_special = False
363
+
364
+ logger.info(f"Sell: {user_id} sells :{args}")
365
+
366
+ if args == []:
367
+ await sell.finish(
368
+ MessageSegment.at(user_id)
369
+ + " "
370
+ + "请输入要卖出的鱼的名字和数量 (数量为1时可省略), 如 /卖鱼 小鱼 1"
371
+ )
372
+
373
+ for arg in copy.deepcopy(args):
374
+ if arg in ["-i", "--index"]:
375
+ as_index = True
376
+ args.remove(arg)
377
+ if arg in ["-s", "--spec", "--special"]:
378
+ as_special = True
379
+ args.remove(arg)
380
+
381
+ if len(args) == 1:
382
+ name_or_index = args[0]
383
+ fish_quantity = 1
384
+ else:
385
+ name_or_index, fish_quantity = args[0], args[1]
386
+
387
+ result = await sell_fish(
388
+ user_id, name_or_index, int(fish_quantity), as_index, as_special
389
+ )
390
+ await sell.finish(MessageSegment.at(user_id) + " " + result)
391
+
392
+
393
+ @free_fish_cmd.handle()
394
+ async def _(
395
+ bot: Bot,
396
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
397
+ arg: Message = CommandArg(),
398
+ ):
399
+ if not config.special_fish_enabled:
400
+ await free_fish_cmd.finish("未开启此功能, 请联系机器人管理员")
401
+
402
+ fish_name = arg.extract_plain_text()
403
+ user_id = event.get_user_id()
404
+
405
+ if (
406
+ len(fish_name) > 500
407
+ or "\u200b" in fish_name
408
+ or "\u200c" in fish_name
409
+ or "\u200d" in fish_name
410
+ or "\u2060" in fish_name
411
+ or "\ufeff" in fish_name
412
+ ): # TODO: 检测特殊字符
413
+ if isinstance(event, GroupMessageEvent):
414
+ group_id = event.group_id
415
+ try:
416
+ await bot.set_group_ban(group_id=group_id, user_id=user_id, duration=1800)
417
+ except ActionFailed:
418
+ pass
419
+ await free_fish_cmd.finish(
420
+ MessageSegment.at(user_id) + " " + "你 TM 在放生什么?滚滚滚"
421
+ )
422
+
423
+ if fish_name == "":
424
+ await free_fish_cmd.finish(
425
+ MessageSegment.at(user_id) + " " + "请输入要放生的鱼的名字, 如 /放生 测试鱼"
426
+ )
427
+ await free_fish_cmd.finish(
428
+ MessageSegment.at(user_id) + " " + await free_fish(user_id, fish_name)
429
+ )
430
+
431
+
432
+ @lottery_cmd.handle()
433
+ async def _(
434
+ bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent], matcher: Matcher
435
+ ):
436
+ user_id = event.get_user_id()
437
+ try:
438
+ await punish(bot, event, matcher, user_id)
439
+ result = await lottery(user_id)
440
+ except:
441
+ result = "河神睡着了……"
442
+ finally:
443
+ punish_user_dict.pop(user_id, None)
444
+ await lottery_cmd.finish(MessageSegment.at(user_id) + " " + result)
445
+
446
+
447
+ @achievement_cmd.handle()
448
+ async def _(event: Event):
449
+ user_id = event.get_user_id()
450
+ await achievement_cmd.finish(
451
+ MessageSegment.at(user_id) + " " + await get_achievements(user_id)
452
+ )
453
+
454
+
455
+ @give_cmd.handle()
456
+ async def _(
457
+ bot: Bot,
458
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
459
+ arg: Message = CommandArg(),
460
+ ):
461
+ is_superuser = str(event.user_id) in bot.config.superusers
462
+ is_self = event.self_id == event.user_id
463
+ if not is_superuser and not is_self:
464
+ return None
465
+
466
+ args = shlex.split(arg.extract_plain_text())
467
+ as_index = False
468
+ as_special = False
469
+
470
+ for arg in copy.deepcopy(args):
471
+ if arg in ["-i", "--index"]:
472
+ as_index = True
473
+ args.remove(arg)
474
+ if arg in ["-s", "--spec", "--special"]:
475
+ as_special = True
476
+ args.remove(arg)
477
+
478
+ target = await get_at(event)
479
+ if target:
480
+ args.insert(0, target)
481
+
482
+ if len(args) < 2 or len(args) > 3:
483
+ await give_cmd.finish(
484
+ "请输入用户的 id 和鱼的名字和数量 (数量为1时可省略), 如 /give 114514 开发鱼 1"
485
+ )
486
+ else:
487
+ quantity = int(args[2]) if len(args) == 3 else 1
488
+ result = await give(args[0], args[1], quantity, as_index, as_special)
489
+ achievements = await check_achievement(args[0])
490
+ if achievements is not None:
491
+ for achievement in achievements:
492
+ await fishing.send(achievement)
493
+ await give_cmd.finish(result)
494
+
495
+
496
+ @board_cmd.handle()
497
+ async def _(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
498
+ top_users_list = await get_board()
499
+ msg = "钓鱼富豪排行榜:"
500
+ for index, user in enumerate(top_users_list):
501
+ try:
502
+ if isinstance(event, GroupMessageEvent):
503
+ group_id = event.group_id
504
+ user_info = await bot.get_group_member_info(
505
+ group_id=group_id, user_id=user[0]
506
+ )
507
+ username = (
508
+ user_info["card"]
509
+ if user_info["card"] is not None and user_info["card"] != ""
510
+ else user_info["nickname"]
511
+ )
512
+ elif isinstance(event, PrivateMessageEvent):
513
+ user_info = await bot.get_stranger_info(user_id=user[0])
514
+ username = user_info["nickname"]
515
+ except ActionFailed:
516
+ username = "[神秘富豪]"
517
+
518
+ msg += f"\n{index + 1}. {username}: {user[1]} {fishing_coin_name}"
519
+
520
+ await board_cmd.finish(msg)
521
+
522
+
523
+ async def punish(
524
+ bot: Bot,
525
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
526
+ matcher: Matcher,
527
+ user_id: int,
528
+ ):
529
+ global punish_user_dict
530
+
531
+ if not await can_fishing(user_id):
532
+ try:
533
+ punish_user_dict[user_id] += 1
534
+ except KeyError:
535
+ punish_user_dict[user_id] = 1
536
+
537
+ if punish_user_dict[user_id] < config.punish_limit - 1:
538
+ await matcher.finish(
539
+ MessageSegment.at(user_id) + " " + "河累了,休息一下吧"
540
+ )
541
+ elif punish_user_dict[user_id] == config.punish_limit - 1:
542
+ await matcher.finish(MessageSegment.at(user_id) + " " + "河神快要不耐烦了")
543
+ elif punish_user_dict[user_id] == config.punish_limit:
544
+ groud_id = event.group_id if isinstance(event, GroupMessageEvent) else None
545
+ try:
546
+ await bot.set_group_ban(
547
+ group_id=groud_id, user_id=user_id, duration=1800
548
+ )
549
+ except ActionFailed:
550
+ pass
551
+ await matcher.finish(
552
+ MessageSegment.at(user_id) + " " + "河神生气了,降下了惩罚"
553
+ )
554
+ else:
555
+ await matcher.finish()
556
+
557
+
558
+ async def forward_send(
559
+ bot: Bot,
560
+ event: Union[GroupMessageEvent, PrivateMessageEvent],
561
+ messages: list[MessageSegment],
562
+ ) -> None:
563
+ if isinstance(event, GroupMessageEvent):
564
+ await bot.send_group_forward_msg(
565
+ group_id=event.group_id,
566
+ messages=[
567
+ {
568
+ "type": "node",
569
+ "data": {
570
+ "name": "花花",
571
+ "uin": bot.self_id,
572
+ "content": msg,
573
+ },
574
+ }
575
+ for msg in messages
576
+ ],
577
+ )
578
+ else:
579
+ await bot.send_private_forward_msg(
580
+ user_id=event.user_id,
581
+ messages=[
582
+ {
583
+ "type": "node",
584
+ "data": {
585
+ "name": "花花",
586
+ "uin": bot.self_id,
587
+ "content": msg,
588
+ },
589
+ }
590
+ for msg in messages
591
+ ],
592
+ )
593
+
594
+
595
+ async def get_at(event: Union[GroupMessageEvent, PrivateMessageEvent]) -> int:
596
+ if isinstance(event, GroupMessageEvent):
597
+ msg = event.get_message()
598
+ for msg_seg in msg:
599
+ if msg_seg.type == "at":
600
+ return msg_seg.data["qq"]
601
+ return None