-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
2404 lines (2036 loc) · 100 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import re
import nonebot
import aiohttp, asyncio
import time, datetime
from collections import Counter
from pathlib import Path
import ssl
from nonebot import require, on_command, on_regex
from nonebot.adapters.onebot.v11 import Bot, Event
from nonebot.adapters.onebot.v11 import Message, MessageSegment
from nonebot.typing import T_State
from nonebot.params import CommandArg
from nonebot.exception import FinishedException
require("nonebot_plugin_htmlrender")
from nonebot_plugin_htmlrender import (
md_to_pic,
get_new_page
)
from playwright.async_api import TimeoutError
from .data import DATA
from .data_medal import DATA_MEDAL
from nonebot.plugin import PluginMetadata
help_text = f"""
插件功能:(tip:命令如果有英文的,大小写都可以支持)
/查 昵称关键词或uid(uid需要以:或:或uid:或UID:或uid:打头)
/查直播 昵称关键词或uid 场次数(默认不写为全部)
/查舰团 昵称关键词或uid
/查昵称 昵称关键词或uid
/查收益 昵称关键词或uid 收益类型(默认1: 礼物,2: 上舰,3: SC) 倒叙第n场(从0开始)
/查观看 昵称关键词或uid
/查观看2 昵称关键词或uid
/查弹幕 查询的目标人昵称关键词或uid 查询的主播昵称关键词或uid 页数 条数
/查弹幕2 查询的目标人昵称关键词或uid 页数 条数
/查牌子 主播牌子关键词
/查人气 昵称关键词或uid
/查装扮 昵称关键词或uid
/营收 日/周/月榜 人数(不填默认100)
/涨粉 日/周/月榜 人数(不填默认100)
/DD风云榜 人数(不填默认10)
/v详情 昵称关键词或uid
/v直播势
/v急上升
/v急下降
/v舰团
/vdd
/v宏观
/dmk查用户 昵称关键词或uid
/dmk查直播 昵称关键词或uid
/dmk分析 昵称关键词或uid
/blg查弹幕 昵称关键词或uid
/blg查入场 昵称关键词或uid
/blg查礼物 昵称关键词或uid
/blg直播记录 昵称关键词或uid
/blg直播间sc 昵称关键词或uid
/icu查直播 昵称关键词或uid
/icu查直播 昵称关键词或uid
/lap查用户 昵称关键词或uid
/lap查牌子 昵称关键词或uid
/lap查充电 昵称关键词或uid
/lapdd排行榜 搜索类型(默认0: 月供,1: 总督,2: 提督,3:舰长)
/斗虫 主播1的昵称关键词或uid 主播2的昵称关键词或uid 主播n的昵称关键词或uid(主播数得至少2个) 日期起始偏移值(就是以今天开始前推n天,例如:2,就是前天) 日期结束偏移值
/vtb网站 或 /vtb资源
/eh查直播 或 /诶嘿查直播
调用的相关API源自b站官方接口、danmakus.com、ddstats.ericlamm.xyz、biligank.com、laplace.live、vtbs.fun、stats.nailv.live
""".strip()
__plugin_meta__ = PluginMetadata(
name = 'b站用户信息查询',
description = '适用于nonebot2 v11的b站用户信息查询插件【粉丝、舰团信息;直播收益数据;直播观看信息;关键词搜昵称、UID等;主播营收榜单】',
usage = help_text
)
# 请求头 需要在env配置cookie
header1 = {
'content-type': 'text/plain; charset=utf-8',
'cookie': '',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.186.400 QQBrowser/11.3.5195.400'
}
# 获取env配置
try:
nonebot.logger.debug(nonebot.get_driver().config.searchbiliinfo_cookie)
header1["cookie"] = nonebot.get_driver().config.searchbiliinfo_cookie
except:
header1["cookie"] = ""
nonebot.logger.warning("searchBiliInfo的cookie没有配置,部分功能受限。")
nonebot.logger.debug("cookie=" + header1["cookie"])
# 所有的命令都在这哦,要改命令触发关键词的请自便
catch_str = on_command("查", priority=2)
catch_str1 = on_command("查弹幕")
catch_str11 = on_command("查弹幕2")
catch_str2 = on_command("查观看")
catch_str26 = on_command("查观看2")
catch_str3 = on_command("查直播")
catch_str4 = on_command('查收益')
catch_str5 = on_command('查舰团')
catch_str6 = on_command('查昵称')
catch_str12 = on_command('查牌子')
catch_str22 = on_command('查人气')
catch_str35 = on_command('查装扮', aliases={"查装扮"})
catch_str7 = on_command('营收')
catch_str9 = on_command('涨粉')
catch_str8 = on_command("vtb网站", aliases={"VTB网站", "Vtb网站", "vtb资源", "VTB资源"})
catch_str10 = on_command('DD风云榜', aliases={"风云榜", "dd风云榜"})
catch_str13 = on_command('V详情', aliases={"v详情", "v详细", "V详细"})
catch_str29 = on_command('V直播势', aliases={"v直播势"})
catch_str30 = on_command('V急上升', aliases={"v急上升"})
catch_str31 = on_command('V急下降', aliases={"v急下降"})
catch_str32 = on_command('V舰团', aliases={"v舰团"})
catch_str33 = on_command('VDD风云榜', aliases={"vdd风云榜", "vdd", "VDD"})
catch_str34 = on_command('V宏观', aliases={"v宏观"})
catch_str14 = on_command('dmk查用户', aliases={"DMK查用户", "danmakus查用户"})
catch_str15 = on_command('dmk查直播', aliases={"DMK查直播", "danmakus查直播"})
catch_str39 = on_command('dmk分析', aliases={"DMK分析", "danmakus分析"})
catch_str16 = on_command('blg查弹幕', aliases={"BLG查弹幕", "biligank查弹幕"})
catch_str17 = on_command('blg查入场', aliases={"BLG查入场", "biligank查入场"})
catch_str18 = on_command('blg查礼物', aliases={"BLG查礼物", "biligank查礼物"})
catch_str19 = on_command('blg直播记录', aliases={"BLG直播记录", "biligank直播记录"})
catch_str20 = on_command('blg直播间sc', aliases={"BLG直播间sc", "blg直播间SC", "BLG直播间SC", "biligank直播间sc"})
catch_str21 = on_command('icu查直播', aliases={"ICU查直播", "matsuri查直播"})
catch_str23 = on_command('lap查用户', aliases={"LAP查用户"})
catch_str24 = on_command('lap查牌子', aliases={"LAP查牌子"})
catch_str27 = on_command('lap查充电', aliases={"LAP查充电"})
catch_str36 = on_command('lapdd排行榜', aliases={"lapdd", "LAPDD排行榜", "LAPDD"})
catch_str25 = on_command('zero查用户', aliases={"ZERO查用户"})
catch_str28 = on_command('zero被关注', aliases={"ZERO被关注"})
#catch_str37 = on_regex(r"(?P<option>斗虫|主播pk|主播PK) (?P<usernames>(?:[\u4e00-\u9fa5\w\d]{1,30} ){1,})(?:#(?P<start_offset>\d*) (?P<end_offset>\d*))?")
#catch_str37 = on_regex(r"(?P<option>斗虫|主播pk|主播PK) (?P<usernames>(?:[\u4e00-\u9fa5\w\d]{1,30} ){1,})(?:#(?P<start_offset>\d*) (?P<end_offset>\d*))?")
catch_str37 = on_regex(r"(?P<option>斗虫|主播pk|主播PK) (?P<usernames>(?:[\u4e00-\u9fa5\w\d]{1,30}(?: )?){1,})(?:#(?P<start_offset>\d*) (?P<end_offset>\d*))?")
catch_str38 = on_command('eh查直播', aliases={"诶嘿查直播", "eihei查直播"})
# 查
@catch_str.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
temp = await data_preprocess(content)
if 0 == temp["code"]:
content = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到用户名为:' + content + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str.finish(Message(f'{msg}'), reply_message=True)
# 传入uid获取用户基本信息
url = 'https://account.bilibili.com/api/member/getCardByMid?mid=' + content
base_info_json = await common_get_return_json(url)
if base_info_json == None:
msg = '查询UID:' + content + '的用户信息失败,可能是网络问题或者API寄了喵'
await catch_str.finish(Message(f'{msg}'), reply_message=True)
# 获取用户信息失败
if base_info_json['code'] != 0:
nonebot.logger.info(base_info_json)
msg = '获取uid:' + content + ',用户信息失败。\nError code:' + str(base_info_json['code'])
await catch_str.finish(Message(f'{msg}'), reply_message=True)
# 获取用户直播间id
room_id = await get_room_id(content)
# 没有直播间 默认为0
if room_id == 0:
guard_info_json = {"data": {"info": {"num": 0}}}
else:
url = 'https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=' + str(room_id) + \
'&page=1&ruid=' + content + '&page_size=0'
guard_info_json = await common_get_return_json(url)
if guard_info_json == None:
msg = "请求失败喵~可能是网络问题或者API寄了喵~"
await catch_str.finish(Message(f'{msg}'), reply_message=True)
try:
msg = '用户名:' + base_info_json['card']['name'] + \
'\nUID:' + str(base_info_json['card']['mid']) + \
'\n房间号:' + str(room_id) + \
'\n粉丝数:' + str(base_info_json['card']['fans']) + \
'\n舰团数:' + str(guard_info_json['data']['info']['num']) + \
'\n主页:' + 'https://space.bilibili.com/' + str(base_info_json['card']['mid']) + \
'\n直播间:' + 'https://live.bilibili.com/' + str(room_id)
except:
msg = "数据解析异常,请重试。(如果多次重试都失败,建议提issue待开发者修复)"
await catch_str.finish(Message(f'{msg}'), reply_message=True)
# 查弹幕
@catch_str1.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 以空格分割 用户uid 目标uid 页数 条数
content = content.split()
src_uid = ""
tgt_uid = ""
page = "0"
page_size = "3"
if len(content) >= 2:
src_uid, tgt_uid, *args = content
page = args[0] if args else "0"
page_size = args[1] if len(args) > 1 else "3"
else:
msg = '传参错误,命令格式【/查弹幕 用户uid或昵称 目标uid或昵称 页数(可不填,默认0) 条数(可不填,默认3)】'
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
temp = await data_preprocess(src_uid)
if 0 == temp["code"]:
src_uid = temp["uid"]
else:
msg = '查询不到用户名为:' + src_uid + ' 的相关信息。\nError code:' + str(temp["code"])
nonebot.logger.info(temp)
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
temp = await data_preprocess(tgt_uid)
if 0 == temp["code"]:
tgt_uid = temp["uid"]
else:
msg = '查询不到用户名为:' + tgt_uid + ' 的相关信息。\nError code:' + str(temp["code"])
nonebot.logger.info(temp)
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
nonebot.logger.debug("src_uid:" + src_uid + " tgt_uid:" + tgt_uid)
await catch_str1.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/search/user/detail?uid=' + src_uid + '&target=' + tgt_uid + \
'&pagenum=' + page + '&pagesize=' + page_size
info_json = await common_get_return_json(url)
if info_json == None:
msg = '果咩,查询信息失败喵~API寄了喵'
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
try:
# 判断返回代码
if info_json['code'] != 200:
msg = '查询出错。Error code:' + str(temp["code"])
nonebot.logger.info(info_json)
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
msg = '果咩,查询信息失败喵~请检查拼写或者是API寄了'
nonebot.logger.info(e)
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
data_len = 0
out_str = "#查弹幕\n\n查询用户UID:" + src_uid + \
" 目标UID:" + tgt_uid + \
" 页数:" + page + \
" 条数:" + page_size + "\n\n" + \
"| 时间 | 内容 |\n" \
"| :-----| :-----|\n"
try:
for i in range(len(info_json['data']['data'])):
title = await filter_markdown(info_json['data']['data'][i]['live']['title'])
out_str += '| 标题 | ' + title + ' |\n'
for j in range(len(info_json['data']['data'][i]['danmakus'])):
date = await timestamp_to_date(info_json['data']['data'][i]['danmakus'][j]['sendDate'])
if info_json['data']['data'][i]['danmakus'][j]['type'] in [0, 1, 2, 3]:
message = await filter_markdown(info_json['data']['data'][i]['danmakus'][j]['message'])
elif info_json['data']['data'][i]['danmakus'][j]['type'] == 4:
message = "【进入直播间】"
else:
message = "【其他消息】"
out_str += '| ' + str(date) + '| ' + message + '|\n'
data_len += 1
out_str += '| -- | -- |\n'
out_str += '\n数据源自:danmakus.com\n'
# nonebot.logger.info("\n" + out_str)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '返回数据解析异常,寄~(请查日志排查问题)'
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
# 随便定的一个上限值 可以自行修改
if data_len < 1000:
output = await md_to_pic(md=out_str, width=1100)
await catch_str1.send(MessageSegment.image(output))
else:
msg = '果咩,弹幕数大于1000,发不出去喵~(可自行修改源码中的数量上限)'
await catch_str1.finish(Message(f'{msg}'), reply_message=True)
# 查弹幕2
@catch_str11.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 以空格分割 用户uid 页数 条数
content = content.split()
src_uid = ""
tgt_uid = ""
page = "0"
page_size = "3"
if content:
src_uid, *args = content
page = args[0] if args else "0"
page_size = args[1] if len(args) > 1 else "3"
else:
msg = '传参错误,命令格式【/查弹幕2 用户uid或昵称 页数(可不填,默认0) 条数(可不填,默认3)】'
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
temp = await data_preprocess(src_uid)
if 0 == temp["code"]:
src_uid = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到用户名为:' + src_uid + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
nonebot.logger.debug("src_uid:" + src_uid + " tgt_uid:" + tgt_uid)
await catch_str11.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/search/user/detail?uid=' + src_uid + '&target=' + tgt_uid + \
'&pagenum=' + page + '&pagesize=' + page_size
info_json = await common_get_return_json(url)
if info_json == None:
msg = '果咩,查询信息失败喵~API寄了喵'
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
try:
# 判断返回代码
if info_json['code'] != 200:
msg = '查询出错。接口返回:\n' + json.dumps(info_json, indent=2, ensure_ascii=False)
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '果咩,查询信息失败喵~请检查拼写或者是API寄了'
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
data_len = 0
out_str = "#查弹幕2\n\n查询用户UID:" + src_uid + \
" 目标UID:" + tgt_uid + \
" 页数:" + page + \
" 条数:" + page_size + "\n\n" + \
"| 时间 | 内容 |\n" \
"| :-----| :-----|\n"
try:
for i in range(len(info_json['data']['data'])):
name = info_json['data']['data'][i]['channel']['name']
title = await filter_markdown(info_json['data']['data'][i]['live']['title'])
out_str += '| 主播——标题 | ' + name + '——' + title + ' |\n'
for j in range(len(info_json['data']['data'][i]['danmakus'])):
date = await timestamp_to_date(info_json['data']['data'][i]['danmakus'][j]['sendDate'])
if info_json['data']['data'][i]['danmakus'][j]['type'] in [0, 1, 2, 3]:
message = await filter_markdown(info_json['data']['data'][i]['danmakus'][j]['message'])
elif info_json['data']['data'][i]['danmakus'][j]['type'] == 4:
message = "【进入直播间】"
else:
message = "【其他消息】"
out_str += '| ' + str(date) + '| ' + message + '|\n'
data_len += 1
out_str += '| -- | -- |\n'
out_str += '\n数据源自:danmakus.com\n'
# nonebot.logger.info("\n" + out_str)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '返回数据解析异常,寄~(请查日志排查问题)'
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
if data_len < 1000:
output = await md_to_pic(md=out_str, width=1100)
await catch_str11.send(MessageSegment.image(output))
else:
msg = '果咩,弹幕数大于1000,发不出去喵~(可自行修改源码中的数量上限)'
await catch_str11.finish(Message(f'{msg}'), reply_message=True)
# 查观看
@catch_str2.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
temp = await data_preprocess(content)
if 0 == temp["code"]:
content = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到用户名为:' + content + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str.finish(Message(f'{msg}'), reply_message=True)
await catch_str.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/search/user/channel?uid=' + content
user_info_json = await common_get_return_json(url)
if user_info_json == None:
msg = '果咩,查询用户信息失败喵~API寄了喵'
await catch_str2.finish(Message(f'{msg}'), reply_message=True)
try:
# 判断返回代码
if user_info_json['code'] != 200:
msg = '查询用户:' + content + '失败'
await catch_str2.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '果咩,查询用户信息失败喵~请检查拼写或者是API寄了'
await catch_str2.finish(Message(f'{msg}'), reply_message=True)
# 创建一个计数器对象,并对重复的uId进行计数
uid_counter = Counter([(item['uId'], item['name'], item['roomId']) for item in user_info_json['data']])
# 统计不重复的总数
unique_uids = set([item['uId'] for item in user_info_json['data']])
out_str = "#查观看\n\n查询用户UID:" + content + "\n\n" + \
" 观看总数:" + str(len(user_info_json["data"])) + " 主播总数:" + str(len(unique_uids)) + "\n\n" + \
"| 昵称 | UID | 房间号 | 观看次数 |\n" \
"| :-----| :-----| :-----| :-----|\n"
# nonebot.logger.info(out_str)
# 按照降序输出计数器对象的结果
for (uId, name, roomId), count in uid_counter.most_common():
out_str += "| {:<s} | {:<d} | {:<d} | {:<d} |".format(name, uId, roomId, count)
out_str += '\n'
out_str += '\n数据源自:danmakus.com\n'
# nonebot.logger.info("\n" + out_str)
if len(unique_uids) < 2000:
output = await md_to_pic(md=out_str, width=700)
await catch_str2.send(MessageSegment.image(output))
else:
msg = '果咩,dd数大于2000,发不出去喵~(可自行修改源码中的数量上限)'
await catch_str2.finish(Message(f'{msg}'), reply_message=True)
# 查观看2
@catch_str26.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
temp = await data_preprocess(content)
if 0 == temp["code"]:
content = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到:' + content + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
await catch_str26.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/search/user/channel?uid=' + content
user_info_json = await common_get_return_json(url)
if user_info_json == None:
msg = '果咩,查询用户信息失败喵~API寄了喵'
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
try:
# 判断返回代码
if user_info_json['code'] != 200:
msg = '查询用户:' + content + '失败'
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '果咩,查询用户信息失败喵~请检查拼写或者是API寄了'
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
try:
dir_path = Path(__file__).parent
file_path = dir_path / "html" / "composition_page.html"
async with get_new_page(viewport={"width": 1000, "height": 800}) as page:
await page.goto(
"file://" + str(file_path.resolve()),
timeout=2 * 60 * 1000,
wait_until="networkidle",
)
await page.eval_on_selector('html', "generate_chart4('{}', '{}')".format(content, json.dumps(user_info_json)))
await asyncio.sleep(3)
temp_path = "./data/danmakus.com_composition" + await get_current_timestamp_seconds() + ".png"
pic = await page.screenshot(full_page=True, path=temp_path)
await catch_str26.finish(MessageSegment.image(pic))
except TimeoutError as e:
nonebot.logger.info(e)
msg = '打开页面超时喵~可能是网络问题或是对面寄了'
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
except FinishedException:
pass
except Exception as e:
nonebot.logger.info(e)
msg = '打开页面失败喵(看看后台日志吧)'
await catch_str26.finish(Message(f'{msg}'), reply_message=True)
# 查直播
@catch_str3.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 以空格分割 用户uid或昵称 最近n场
content = content.split()
src_uid = ""
info_size = "99999"
if len(content) < 1 or len(content) > 3 or content[0] == "":
msg = '传参错误,命令格式【/查直播 用户uid或昵称 最近场次数】'
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
else:
src_uid = content[0]
if len(content) > 1 and content[1]:
info_size = content[1]
temp = await data_preprocess(src_uid)
if 0 == temp["code"]:
src_uid = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到用户名为:' + src_uid + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
await catch_str3.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/info/channel?cid=' + src_uid
info_json = await common_get_return_json(url)
if info_json == None:
msg = '查询用户:' + src_uid + '失败,API寄了喵'
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
try:
# 判断返回代码
if info_json['code'] != 200:
msg = '查询用户:' + src_uid + '失败,请检查拼写或者是API寄了\nError code:' + str(info_json["code"])
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询用户:' + src_uid + '失败,请检查拼写或者是API寄了'
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
out_str = ""
try:
out_str = "#查直播\n\n昵称:" + info_json["data"]["channel"]["name"] + \
" UID:" + src_uid + \
" 房间号:" + str(info_json["data"]["channel"]["roomId"]) +\
"\n\n 总直播数:" + str(info_json["data"]["channel"]["totalLiveCount"]) + \
" 总弹幕数:" + str(info_json["data"]["channel"]["totalDanmakuCount"]) + \
" 总收益:¥" + str(info_json["data"]["channel"]["totalIncome"]) + \
" 总直播时长:" + str(round(info_json["data"]["channel"]["totalLiveSecond"] / 60 / 60, 2)) + "h\n\n" + \
"| 开始时间 | 时长 | 标题 | 弹幕数 | 观看数 | 互动数 | 总收益 |\n" \
"| :-----| :-----| :-----| :-----| :-----| :-----| :-----|\n"
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '解析数据异常(请查日志排查问题)'
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
for i in range(len(info_json["data"]["lives"])):
# 达到指定数量场次
if i == int(info_size):
break
try:
if info_json["data"]["lives"][i]["stopDate"] is None:
out_str += "| {:<s} | 直播中 | {:<s} | {:<d} | {:<d} | {:<d} | ¥{:<.1f} |".format(
await timestamp_to_date(info_json["data"]["lives"][i]["startDate"]),
info_json["data"]["lives"][i]["title"],
info_json["data"]["lives"][i]["danmakusCount"],
info_json["data"]["lives"][i]["watchCount"],
info_json["data"]["lives"][i]["interactionCount"],
info_json["data"]["lives"][i]["totalIncome"])
else:
out_str += "| {:<s} | {:<.2f}h | {:<s} | {:<d} | {:<d} | {:<d} | ¥{:<.1f} |".format(
await timestamp_to_date(info_json["data"]["lives"][i]["startDate"]),
(info_json["data"]["lives"][i]["stopDate"] - info_json["data"]["lives"][i][
"startDate"]) / 1000 / 3600,
info_json["data"]["lives"][i]["title"],
info_json["data"]["lives"][i]["danmakusCount"],
info_json["data"]["lives"][i]["watchCount"],
info_json["data"]["lives"][i]["interactionCount"],
info_json["data"]["lives"][i]["totalIncome"])
except (KeyError, TypeError, IndexError) as e:
out_str += "| {:<s} | 直播中 | {:<s} | {:<d} | {:<d} | {:<d} | ¥{:<.1f} |".format(
await timestamp_to_date(info_json["data"]["lives"][i]["startDate"]),
info_json["data"]["lives"][i]["title"],
info_json["data"]["lives"][i]["danmakusCount"],
info_json["data"]["lives"][i]["watchCount"],
info_json["data"]["lives"][i]["interactionCount"],
info_json["data"]["lives"][i]["totalIncome"])
out_str += '\n'
# 2000场就算了吧,太多了
if i >= 2000:
break
out_str += '\n数据源自:danmakus.com\n'
# nonebot.logger.info("\n" + out_str)
if len(info_json["data"]["lives"]) < 2000:
output = await md_to_pic(md=out_str, width=1100)
await catch_str3.send(MessageSegment.image(output))
else:
msg = '果咩,直播数大于2000,发不出去喵~'
await catch_str3.finish(Message(f'{msg}'), reply_message=True)
# 查收益
@catch_str4.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 以空格分割 用户uid或昵称 收益类型(默认1: 礼物,2: 上舰,3: SC) 倒叙第n场(从0开始)
content = content.split()
src_uid = ""
live_index = "0"
income_type = "1"
if len(content) < 1 or len(content) > 3 or content[0] == "":
msg = '传参错误,命令格式【/查直播 用户uid或昵称 收益类型(默认1: 礼物,2: 上舰,3: SC) 倒叙第n场(从0开始)】'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
else:
src_uid = content[0]
if len(content) > 1 and content[1]:
income_type = content[1]
if len(content) > 2 and content[2]:
live_index = content[2]
temp = await data_preprocess(src_uid)
if 0 == temp["code"]:
src_uid = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到用户名为:' + src_uid + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str.finish(Message(f'{msg}'), reply_message=True)
# 默认1: 礼物,2: 上舰或舰长,3: SC
# 定义了一个名为INCOME_TYPES的字典,其中包含了每种类型收入对应的代码。
INCOME_TYPES = {
"礼物": "1",
"上舰": "2",
"舰长": "2",
"SC": "3",
"sc": "3",
"Sc": "3",
"1": "1",
"2": "2",
"3": "3"
}
# 使用get()方法来获取字典中对应的值,如果找不到则返回默认值"1"
income_type = INCOME_TYPES.get(income_type, "1")
# nonebot.logger.info("income_type:" + income_type)
INCOME_TYPE_CHS = {
"1": "礼物",
"2": "上舰",
"3": "舰长",
}
income_type_ch = INCOME_TYPE_CHS.get(income_type, "礼物")
await catch_str4.send("正在获取数据中,请耐心等待...", reply_message=True)
url = 'https://danmakus.com/api/info/channel?cid=' + src_uid
live_json = await common_get_return_json(url)
try:
# 判断返回代码
if live_json['code'] != 200:
msg = '查询用户:' + src_uid + ' 直播信息失败,请检查拼写或者是API寄了\nError code:' + str(live_json["code"])
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询用户:' + src_uid + ' 直播信息失败,请检查拼写或者是API寄了'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
try:
live_id = live_json['data']['lives'][int(live_index)]['liveId']
username = live_json["data"]["channel"]["name"]
room_id = str(live_json["data"]["channel"]["roomId"])
totalLiveCount = str(live_json["data"]["channel"]["totalLiveCount"])
totalDanmakuCount = str(live_json["data"]["channel"]["totalDanmakuCount"])
totalIncome = str(live_json["data"]["channel"]["totalIncome"])
totalLivehour = str(round(live_json["data"]["channel"]["totalLiveSecond"] / 60 / 60, 2))
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询用户:' + src_uid + '失败,live_id解析失败,可能原因:场次数不对/无此场次'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
out_str = "#查收益 " + income_type_ch + "\n\n昵称:" + username + " UID:" + src_uid + " 房间号:" + room_id +\
"\n\n 总直播数:" + totalLiveCount + " 总弹幕数:" + totalDanmakuCount + " 总收益:¥" + totalIncome + \
" 总直播时长:" + totalLivehour + "h\n\n" + \
"| 时间 | uid | 昵称 | 内容 | 价格 |\n" \
"| :-----| :-----| :-----| :-----| :-----|\n"
# nonebot.logger.info(out_str)
# 获取当场直播信息
url = 'https://danmakus.com/api/info/live?liveid=' + live_id + '&type=' + income_type + '&uid='
info_json = await common_get_return_json(url)
if info_json == None:
msg = '查询用户:' + src_uid + ' 场次数据失败,API寄了喵'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
try:
if info_json['code'] != 200:
msg = '查询用户:' + src_uid + ' 场次数据失败,请检查拼写或者是API寄了\nError code:' + str(temp["code"])
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询用户:' + src_uid + ' 场次数据失败,请检查拼写或者是API寄了'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
# 遍历弹幕信息
for i in range(len(info_json["data"]["danmakus"])):
out_str += "| {:<s} | {:<d} | {:<s} | {:<s} | ¥{:<.1f} |".format(
await timestamp_to_date(info_json["data"]["danmakus"][i]["sendDate"]),
info_json["data"]["danmakus"][i]["uId"],
info_json["data"]["danmakus"][i]["name"],
await filter_markdown(info_json["data"]["danmakus"][i]["message"]),
info_json["data"]["danmakus"][i]["price"])
out_str += '\n'
# 2000条就算了吧,太多了
if i >= 2000:
break
out_str += '\n数据源自:danmakus.com\n'
# nonebot.logger.info("\n" + out_str)
if len(info_json["data"]["danmakus"]) < 2000:
output = await md_to_pic(md=out_str, width=1100)
await catch_str4.send(MessageSegment.image(output))
else:
msg = '果咩,礼物数大于2000,发不出去喵~(可修改源码增大上限)'
await catch_str4.finish(Message(f'{msg}'), reply_message=True)
@catch_str5.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
username = ""
temp = await data_preprocess(content)
if 0 == temp["code"]:
content = temp["uid"]
else:
nonebot.logger.info(temp)
msg = '查询不到UID:' + content + ' 的相关信息。\nError code:' + str(temp["code"])
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
# 传入uid获取用户基本信息
url = 'https://account.bilibili.com/api/member/getCardByMid?mid=' + content
base_info_json = await common_get_return_json(url)
if base_info_json == None:
msg = '查询UID:' + content + '的用户信息失败,可能是网络问题或者API寄了喵'
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
try:
if base_info_json['code'] != 0:
nonebot.logger.info(base_info_json)
msg = '获取uid:' + content + ',用户信息失败。\nError code:' + str(base_info_json["code"])
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
username = base_info_json["card"]["name"]
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询UID:' + content + '的用户名失败,请检查拼写/API寄了'
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
url = 'https://api.vtbs.moe/v1/guard/' + content
guard_info_json = await common_get_return_json(url)
if guard_info_json == None:
msg = '查询UID:' + content + '失败,API寄了喵,请进行问题排查~'
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
try:
guard_len = len(guard_info_json)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询UID:' + content + '失败,请检查拼写/没有舰团/API寄了'
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
out_str = "#查舰团\n\n查询用户名:" + username + " UID:" + content + " 舰团数:" + str(guard_len) + "\n\n" + \
"| 昵称 | UID | 舰团类型 |\n" \
"| :-----| :-----| :-----|\n"
try:
for i in range(guard_len):
uname = guard_info_json[i]['uname']
mid = guard_info_json[i]['mid']
if guard_info_json[i]['level'] == 0:
level = '总督'
elif guard_info_json[i]['level'] == 1:
level = '提督'
else:
level = '舰长'
out_str += "| {:<s} | {:<d} | {:<s} |".format(uname, mid, level)
out_str += '\n'
out_str += '\n数据源自:vtbs.moe\n'
# nonebot.logger.info("\n" + out_str)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询UID:' + content + '失败,请检查拼写/没有舰团/API寄了'
await catch_str5.finish(Message(f'{msg}'), reply_message=True)
output = await md_to_pic(md=out_str, width=500)
await catch_str5.send(MessageSegment.image(output))
# 查昵称
@catch_str6.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
url = 'https://api.bilibili.com/x/web-interface/search/type?page_size=10&keyword=' + content + \
'&search_type=bili_user'
info_json = await common_get_return_json(url)
# nonebot.logger.info(info_json)
if info_json == None:
msg = '网络出问题了或者接口寄了喵~'
await catch_str6.finish(Message(f'{msg}'), reply_message=True)
try:
result = info_json['data']['result']
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '查询无结果,请检查拼写或是接口寄了'
await catch_str6.finish(Message(f'{msg}'), reply_message=True)
msg = "\n 查询用户名:" + content + "\n" + \
" 显示格式为:【 UID 昵称 粉丝数 】\n"
for i in range(len(result)):
msg += " 【 " + str(result[i]["mid"]) + " " + result[i]["uname"] + " " + str(result[i]["fans"]) + ' 】\n'
await catch_str6.finish(Message(f'{msg}'), reply_message=True)
@catch_str7.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 分别传入 日/周/月榜 和 数量
content = content.split()
date_range = ''
size = '100'
if len(content) == 1:
date_range = content[0]
elif len(content) >= 2:
date_range = content[0]
size = content[1]
await catch_str7.send("正在获取数据中,请耐心等待...", reply_message=True)
date_ranges = ['月榜', '周榜', '日榜']
if date_range in date_ranges:
url = 'https://www.vtbs.fun:8050/rank/income?dateRange=' + await date_range_change(date_range) + '¤t=1&size=' + size
json1 = await common_get_return_json(url)
else:
msg = '命令错误,例如:【/营收 月榜】【/营收 周榜 10】【/营收 日榜 3】'
await catch_str7.finish(Message(f'{msg}'), reply_message=True)
if json1 == None:
msg = '请求失败,可能是网络问题或者接口寄了喵~'
await catch_str7.finish(Message(f'{msg}'), reply_message=True)
try:
if json1["code"] != 200:
nonebot.logger.info(json1)
msg = '请求失败,寄了喵。\nError code:' + str(json1["code"])
await catch_str7.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
nonebot.logger.info(e)
msg = '请求解析失败,接口寄了喵'
await catch_str7.finish(Message(f'{msg}'), reply_message=True)
try:
out_str = "#VTB营收" + date_range + "\n" + \
"| 用户名 | uid | 营收 | 付费人数 | 弹幕总数 | 直播时长 |\n" \
"| :-----| :-----| :-----| :-----| :-----| :-----|\n"
for i in range(len(json1['data'])):
name = json1['data'][i]['name']
danmaku = json1['data'][i]['danmaku']
gold_user = json1['data'][i]['goldUser']
income = json1['data'][i]['income']
mid = json1['data'][i]['mid']
live_time = json1['data'][i]['liveTime']
out_str += '| ' + name + ' | ' + str(mid) + ' | '
if income >= 10000000:
income = round(income / 10000000, 2)
out_str += str(income) + '万 | '
else:
income = round(income / 1000, 2)
out_str += str(income) + '元 | '
out_str += str(gold_user) + '人 | ' + str(danmaku) + '条 | '
live_time = round(live_time / 60 / 60, 2)
out_str += str(live_time) + 'h |' + '\n'
out_str += "\n\n数据源自:vtbs.fun"
# nonebot.logger.info("\n" + out_str)
output = await md_to_pic(md=out_str, width=900)
# 如果需要保存到本地则去除下面2行注释
# output = Image.open(BytesIO(img))
# output.save("md2pic.png", format="PNG")
await catch_str7.send(MessageSegment.image(output))
except FinishedException:
pass
except Exception as e:
nonebot.logger.info(e)
msg = '数据解析失败,寄了喵(请查看日志排查问题)'
await catch_str7.finish(Message(f'{msg}'), reply_message=True)
# VTB涨粉
@catch_str9.handle()
async def _(bot: Bot, event: Event, msg: Message = CommandArg()):
content = msg.extract_plain_text()
# 分别传入 日/周/月榜 和 数量
content = content.split()
date_range = ''
size = '100'
if len(content) == 1:
date_range = content[0]
elif len(content) >= 2:
date_range = content[0]
size = content[1]
await catch_str9.send("正在获取数据中,请耐心等待...", reply_message=True)
date_ranges = ['月榜', '周榜', '日榜']
if date_range in date_ranges:
url = 'https://www.vtbs.fun:8050/rank/incfans?dateRange=' + await date_range_change(date_range) + '¤t=1&size=' + size
# 获取数据喵
json1 = await common_get_return_json(url)
else:
msg = '命令错误,例如:【/涨粉 月榜】【/涨粉 周榜 10】【/涨粉 日榜 3】'
await catch_str9.finish(Message(f'{msg}'), reply_message=True)
if json1 == None:
msg = '请求失败,可能是网络问题或者接口寄了喵~'
await catch_str9.finish(Message(f'{msg}'), reply_message=True)
try:
if json1["code"] != 200:
nonebot.logger.info(json1)
msg = '请求失败,寄了喵。\n接口返回:\nError code:' + str(json1["code"])
await catch_str9.finish(Message(f'{msg}'), reply_message=True)
except (KeyError, TypeError, IndexError) as e:
msg = '请求解析失败,接口寄了喵'
nonebot.logger.info(e)
await catch_str9.finish(Message(f'{msg}'), reply_message=True)
try:
out_str = "#VTB涨粉" + date_range + "\n" + \
"| 用户名 | uid | 涨粉 | 粉丝数 | 舰长数 | 播放量 |\n" \
"| :-----| :-----| :-----| :-----| :-----| :-----|\n"
for i in range(len(json1['data'])):
archiveView = json1['data'][i]['archiveView']
fans = json1['data'][i]['fans']
guards = json1['data'][i]['guards']
incFans = json1['data'][i]['incFans']
mid = json1['data'][i]['mid']
name = json1['data'][i]['name']
out_str += '| ' + name + ' | ' + str(mid) + ' | ' + str(incFans) + ' | '
if fans > 10000:
fans = round(fans / 10000, 2)
out_str += str(fans) + '万 | '
else:
fans = round(fans, 2)
out_str += str(fans) + ' | '
out_str += str(guards) + ' | '
if archiveView >= 100000000:
archiveView = round(archiveView / 100000000, 2)
out_str += str(archiveView) + '亿 |'
elif archiveView >= 10000:
archiveView = round(archiveView / 10000, 2)
out_str += str(archiveView) + '万 |'
else:
archiveView = round(archiveView, 2)
out_str += str(archiveView) + ' |'
out_str += '\n'
out_str += "\n\n数据源自:vtbs.fun"
# nonebot.logger.info("\n" + out_str)