-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdvx_helper.py
1369 lines (1321 loc) · 64.1 KB
/
sdvx_helper.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 os
import math
import random
import xmltodict
import base64
import pymysql
import datetime
import traceback
from PIL import Image, ImageFont, ImageDraw
from io import BytesIO
from hoshino import Service
from hoshino.service import sucmd
from hoshino.typing import CQEvent, CommandSession
from .config import apu_db, bot_db, mail_cfg
from .game_data import id_search_touch, id_search_panel, id_search_stamp, id_search_theme, id_search_bgm
from .utils import takeSecond, circle_corner, get_usericon, fuzzy_search, send_mail
nowdir = os.getcwd()
help_str='''PIGEON TECH 小助手
(英文命令需使用小写)
功能及其对应命令列表:
* 每日签到随机获取积分
- 签到
- /sdvx sign
* 5555积分兑换25游戏次数
- 积分兑换
* 根据用户名查询SDVX ID
- /sdvx user [用户名(必填)]
* 绑定SDVX账号[支持APU/GUGUGU网]
- /sdvx bind [SDVX ID(必填)]
* 查询账号VOLFORCE
- /sdvx b50 [SDVX ID(可选)]
- /sdvx vf [SDVX ID(可选)]
- vf [SDVX ID(可选)]
* 查询最近SDVX成绩
- /sdvx rc
- /sdvx recent
* SDVX随机抽歌
- /sdvx rd [等级(可选)]
- SDVX抽歌 [等级(可选)]
* 根据乐曲id查询SDVX曲目信息
- /sdvx id [乐曲ID(必填)]
* 设置SDVX机台游玩选项
(类型:1-BGM,2-副屏背景,3-打歌面板,4-表情贴纸,5-主题背景)
(贴纸位置为1-8,分别为fxL/R按下时的btA-D)
- /sdvx set [类型] [位置(如果为表情时)] [ID]'''
sv = Service(
name='SDVX小助手',
visible=True,
bundle='娱乐',
help_= help_str.strip())
class ServerDataError(Exception):
pass
# 缓存全部玩家数据
result_playername = []
def get_player_list_cache():
"""
调用该函数可以从数据库中获取最新的全部玩家数据存储至result_playername全局变量\n
"""
global result_playername
db_apu = pymysql.connect(
host=apu_db.host,
port=apu_db.port,
user=apu_db.user,
password=apu_db.password,
database=apu_db.database
)
apu_cursor = db_apu.cursor()
apu_get_player_name = "SELECT f_id,f_name FROM m_user"
try:
apu_cursor.execute(apu_get_player_name)
result_playername = apu_cursor.fetchall()
except:
print("err")
db_apu.close()
# 初始化加载时先执行一次函数获取全局玩家缓存
get_player_list_cache()
# 获取玩家名称
def get_player_name(f_id):
"""
通过SDVXID获取名称
:param f_id: 玩家SDVX ID
:return: 玩家名称
"""
global result_playername
for player in result_playername:
if player[0] == f_id:
player_name = player[1]
return player_name
return False
# 查询积分
@sv.on_fullmatch(('积分','积分查询','查询积分'))
async def chaxun(bot, ev: CQEvent):
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
# 获取Q号/积分/上次签到时间/连续签到天数/上次抽奖时间/单天抽奖次数
apu_cx_sql = "SELECT QQ,jifei,scqdsj,lxqdts,sccjsj,dtcjcs FROM grxx WHERE QQ = %s" % (qqid)
try:
apu_cursor.execute(apu_cx_sql)
result_cx = apu_cursor.fetchall()
if not result_cx:
await bot.send(ev, "查询结果为空", at_sender = True)
else:
point = result_cx[0][1]
cx_qd_date = result_cx[0][2]
cx_lianxu_date = result_cx[0][3]
cx_choujiang_date = result_cx[0][4]
cx_choujiang_lianxu_times = result_cx[0][5]
today = datetime.date.today()
today_str = "%s年%s月%s日" % (today.year, today.month, today.day)
if today_str != cx_choujiang_date:
cx_choujiang_lianxu_times = 0
await bot.send(ev, "QQ: %s\n积分数量: %s\n上次签到时间: %s\n签到次数: %s\n当天已抽奖次数: %s" %(qqid, point, cx_qd_date, cx_lianxu_date, cx_choujiang_lianxu_times), at_sender = True)
except Exception as e:
print(str(e))
db_bot.close()
@sv.on_fullmatch(('签到','簽到','/sdvx sign'))
async def qiandao(bot, ev: CQEvent):
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
groupid = ev.group_id
msgid = ev.message_id
await bot.set_msg_emoji_like(message_id = msgid, emoji_id ='124')
# 获取Q号/积分/上次签到时间/连续签到天数/上次抽奖时间/单天抽奖次数
apu_qd_sql = "SELECT QQ,jifei,scqdsj,lxqdts,sccjsj,dtcjcs FROM grxx WHERE QQ = %s" % (qqid)
try:
apu_cursor.execute(apu_qd_sql)
result_qd = apu_cursor.fetchall()
# 判断结果是否为空,若为空则插入新数据(新用户注册)
if not result_qd:
#插入新数据
add_mem_sql = "INSERT INTO `grxx` (`Qqun`, `QQ`, `jifei`, `scqdsj`, `lxqdts`) VALUES ('%s', '%s', '0', '0', '0')" %(groupid, qqid)
try:
apu_cursor.execute(add_mem_sql)
db_bot.commit()
apu_cursor.execute(apu_qd_sql)
result_qd = apu_cursor.fetchall()
except Exception as e:
await bot.send(ev, '错误:' + str(e))
db_bot.rollback
point = result_qd[0][1]
qd_date = result_qd[0][2]
qd_lianxu_date = result_qd[0][3]
cj_date = result_qd[0][4]
cj_times = result_qd[0][5]
today = datetime.date.today()
today_str = "%s年%s月%s日" % (today.year, today.month, today.day)
if today_str == qd_date:
await bot.set_msg_emoji_like(message_id = msgid, emoji_id ='123')
else:
try:
# UPDATE `grxx` SET `jifei`='5402', `lxqdts`='2' WHERE (`Qqun`='205194089') AND (`QQ`='1085636071')
get_point = random.randint(1,100)
point = point + get_point
qd_lianxu_date += 1
update_sql = "UPDATE `grxx` SET `jifei`='%s' ,`lxqdts`='%s' ,`scqdsj`='%s' WHERE `QQ`='%s'" % (point, qd_lianxu_date, today_str, qqid)
apu_cursor.execute(update_sql)
db_bot.commit()
with Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\签到_new.png") as qd_bg:
font_main = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\ark-pixel-12px-monospaced-zh_cn.otf", 20)
font_point = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\ark-pixel-12px-monospaced-zh_cn.otf", 64)
font_time = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\ark-pixel-12px-monospaced-zh_cn.otf", 10)
draw = ImageDraw.Draw(qd_bg)
point_txt = f'{point}'
p_tl,tt,p_tr,tb = font_main.getbbox(point_txt)
p_x = 365 - (p_tr - p_tl) / 2
draw.text((p_x, 176), point_txt, 'black', font_main) # 绘制总积分
get_point_txt = f'{get_point}'
gp_tl,tt,gp_tr,tb = font_point.getbbox(get_point_txt)
gp_x = 365 - (gp_tr - gp_tl) / 2
draw.text((gp_x, 78), get_point_txt, '#A32828', font_point) # 绘制获得积分
time_txt = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
t_tl,tt,t_tr,tb = font_time.getbbox(time_txt)
t_x = 365 - (t_tr - t_tl) / 2
draw.text((t_x, 201), time_txt, 'black', font_time) # 绘制日期
try:
qq_img = Image.open(BytesIO((await get_usericon(f'{qqid}')).content)).resize((180,180)).convert("RGBA")
except:
qq_img = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png").resize((180,180)).convert("RGBA")
qd_bg.paste(qq_img,(79,31),qq_img)
qd_bg.save(nowdir + f'\\hoshino\\modules\\sdvx_helper\\qd\\{qqid}.png') # 保存图片
data = open(nowdir + f'\\hoshino\\modules\\sdvx_helper\\qd\\{qqid}.png', "rb")
base64_str = base64.b64encode(data.read())
img_b64 = b'base64://' + base64_str
img_b64 = str(img_b64, encoding = "utf-8")
await bot.send(ev, f'[CQ:image,file={img_b64}]', at_sender = True)
# await bot.send(ev, "签到成功!获得 %s 积分\n您当前已签到 %s 天\n当前共有 %s 积分" %(get_point, qd_lianxu_date, point), at_sender=True)
except Exception as e:
await bot.send(ev, '错误:' + str(e))
db_bot.rollback()
except Exception as e:
print(e.args)
await bot.send(ev, '错误:' + str(e))
db_bot.close()
@sv.on_fullmatch(('抽奖'))
async def choujiang(bot, ev:CQEvent):
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
# 获取Q号/积分/上次抽奖时间/单天抽奖次数
apu_cj_sql = "SELECT QQ,jifei,sccjsj,dtcjcs FROM grxx WHERE QQ = %s" % (qqid)
try:
apu_cursor.execute(apu_cj_sql)
result_cx = apu_cursor.fetchall()
if not result_cx:
await bot.send(ev, "请先发送“签到”注册账号后再来进行抽奖~", at_sender = True)
else:
point = result_cx[0][1]
choujiang_time = result_cx[0][2]
if not choujiang_time or choujiang_time == '':
choujiang_time = 0
choujiang_date = datetime.datetime.fromtimestamp(int(choujiang_time)).strftime('%Y年%m月%d日')
choujiang_lianxu_times = result_cx[0][3]
nowtime = int(datetime.datetime.now().timestamp()) # 获取当前时间戳(整数)
today_str = datetime.datetime.today().strftime('%Y年%m月%d日')
if today_str != choujiang_date:
choujiang_lianxu_times = 0
# 抽奖部分
if choujiang_lianxu_times >= 5: # 若单天抽奖次数大于等于5
await bot.send(ev, "小抽怡情,大抽伤身!\n您今天抽奖太多次了,请改天再来吧!", at_sender = True)
elif (nowtime - int(choujiang_time)) < 600: # 若抽奖时间距离上次小于10分钟
msgid = ev.message_id
await bot.set_msg_emoji_like(message_id = msgid, emoji_id ='123')
else: # 若抽奖时间距离上次大于10分钟
msgid = ev.message_id
await bot.set_msg_emoji_like(message_id = msgid, emoji_id ='144')
try:
get_point = random.randint(1,100)
point = point - 50 + get_point
choujiang_lianxu_times += 1
update_sql = "UPDATE `grxx` SET `jifei`='%s' ,`dtcjcs`='%s' ,`sccjsj`='%s' WHERE `QQ`='%s'" % (point, choujiang_lianxu_times, nowtime, qqid)
apu_cursor.execute(update_sql)
db_bot.commit()
image = Image.new('RGB', (400, 200), (255,255,255)) # 设置画布大小及背景色
iwidth, iheight = image.size # 获取画布高宽
draw = ImageDraw.Draw(image)
font_main = ImageFont.truetype(nowdir + f'\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf', 50)
draw.text((10, 5), '抽奖成功', 'black', font_main)
font = ImageFont.truetype(nowdir + f'\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf', 30) # 设置字体及字号
fontx = 10
fonty = 70
draw.text((fontx, fonty), f'获得 {get_point - 50} 金币', 'black', font)
fonty += 40
draw.text((fontx, fonty), f'您今日已抽奖 {choujiang_lianxu_times} 次', 'black', font)
fonty += 40
draw.text((fontx, fonty), f'当前共有 {point} 金币', 'black', font)
image.save(nowdir + f'\\hoshino\\modules\\sdvx_helper\\cj\\{qqid}.jpg') # 保存图片
data = open(nowdir + f'\\hoshino\\modules\\sdvx_helper\\cj\\{qqid}.jpg', "rb")
base64_str = base64.b64encode(data.read())
img_b64 = b'base64://' + base64_str
img_b64 = str(img_b64, encoding = "utf-8")
await bot.send(ev, f'[CQ:image,file={img_b64}]', at_sender = True)
# await bot.send(ev, "抽奖成功!获得 %s 积分\n您今天已抽奖 %s 次\n当前共有 %s 积分" %(get_point, choujiang_lianxu_times, point), at_sender = True)
except Exception as e:
print(str(e))
db_bot.rollback()
except Exception as e:
print(str(e))
traceback.print_exc()
db_bot.close()
@sv.on_fullmatch(('积分兑换'))
async def duihuan(bot, ev: CQEvent):
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
groupid = ev.group_id
# 获取Q号/积分/上次抽奖时间/单天抽奖次数
apu_cj_sql = "SELECT QQ,jifei,sccjsj,dtcjcs FROM grxx WHERE QQ = %s" % (qqid)
try:
apu_cursor.execute(apu_cj_sql)
result_cx = apu_cursor.fetchall()
if not result_cx:
await bot.send(ev, "都没有签到过,怎么兑换呢?", at_sender = True)
else:
point = result_cx[0][1]
if point > 5555:
get_dhm_sql = "SELECT * FROM `dhm` WHERE `dhqq` LIKE '%空%' ORDER BY `zj` LIMIT 1"
apu_cursor.execute(get_dhm_sql)
result_dhm = apu_cursor.fetchall()
if not result_dhm:
await bot.send_private_msg(user_id=qqid, group_id=groupid, message=f'兑换码数量不足,请联系管理员补充。')
else:
try:
zj = result_dhm[0][0]
dhm = result_dhm[0][4]
point -= 5555
update_dhm_sql = f"UPDATE `dhm` SET `dhqq`='{qqid}' WHERE (`zj`='{zj}')"
update_point_sql = f"UPDATE `grxx` SET `jifei`='{point}' WHERE `QQ`='{qqid}'"
apu_cursor.execute(update_dhm_sql)
apu_cursor.execute(update_point_sql)
db_bot.commit()
success = 1
except:
db_bot.rollback()
else:
await bot.send(ev, message='您的积分不够5555点,暂时无法兑换噢~', at_sender=True)
except:
await bot.send(ev, '兑换失败...')
db_bot.close()
if success == 1:
if await send_mail("user",f"{qqid}@qq.com","[BEMALOW_TECH]您的广西卡游戏次数兑换码",f"您的25次游戏次数兑换码为:{dhm}\n请妥善保管"):
await bot.send(ev, message='兑换成功!请在您的QQ邮箱查看您兑换的卡号数据~', at_sender=True)
else:
await bot.send(ev, messgae='兑换成功,但是邮件无法正常发送,请联系管理员处理~', at_sender=True)
# music_db
music_db_dict = {}
music_db_merged_dict = {}
def update_music_db():
"""更新乐曲数据库dict"""
global music_db_dict, music_db_merged_dict
# 使用xmltodict读取music_db中的歌曲数据
with open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\music_db.xml", encoding = 'CP932') as f:
music_db_dict = xmltodict.parse(f.read())
with open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\music_db.merged.xml", encoding = 'CP932') as f:
music_db_merged_dict = xmltodict.parse(f.read())
update_music_db()
# 将全部乐曲的ID、名称、难度、艺术家、更新日期缓存至list
song_name_lst = []
def cache_songname():
"""
调用此函数可以将全部乐曲的ID、名称、难度、艺术家、更新日期缓存至list
"""
global song_name_lst
song_name_lst = []
for music in music_db_dict['mdb']['music']:
songname = music['info']['title_name']
songid = music['@id']
s_artist = music['info']['artist_name']
s_update_time = music['info']['distribution_date']['#text']
s_difficulty_nov = music['difficulty']['novice']['difnum']['#text']
s_difficulty_adv = music['difficulty']['advanced']['difnum']['#text']
s_difficulty_ext = music['difficulty']['exhaust']['difnum']['#text']
s_difficulty_inf = music['difficulty']['infinite']['difnum']['#text']
if 'maximum' in music['difficulty']:
s_difficulty_mxm = music['difficulty']['maximum']['difnum']['#text']
else: s_difficulty_mxm = '-'
if s_difficulty_nov == '0':
s_difficulty_nov = '-'
if s_difficulty_adv == '0':
s_difficulty_adv = '-'
if s_difficulty_ext == '0':
s_difficulty_ext = '-'
if s_difficulty_inf == '0':
s_difficulty_inf = '-'
song_difficulties = [s_difficulty_nov,s_difficulty_adv,s_difficulty_ext,s_difficulty_inf,s_difficulty_mxm]
song_name_lst.append([songid,songname,song_difficulties,s_artist,s_update_time])
for music in music_db_merged_dict['mdb']['music']:
songname = music['info']['title_name']
songid = music['@id']
s_artist = music['info']['artist_name']
s_update_time = music['info']['distribution_date']['#text']
s_difficulty_nov = music['difficulty']['novice']['difnum']['#text']
s_difficulty_adv = music['difficulty']['advanced']['difnum']['#text']
s_difficulty_ext = music['difficulty']['exhaust']['difnum']['#text']
s_difficulty_inf = music['difficulty']['infinite']['difnum']['#text']
if 'maximum' in music['difficulty']:
s_difficulty_mxm = music['difficulty']['maximum']['difnum']['#text']
else: s_difficulty_mxm = '-'
if s_difficulty_nov == '0':
s_difficulty_nov = '-'
if s_difficulty_adv == '0':
s_difficulty_adv = '-'
if s_difficulty_ext == '0':
s_difficulty_ext = '-'
if s_difficulty_inf == '0':
s_difficulty_inf = '-'
song_difficulties = [s_difficulty_nov,s_difficulty_adv,s_difficulty_ext,s_difficulty_inf,s_difficulty_mxm]
song_name_lst.append([songid,songname,song_difficulties,s_artist,s_update_time])
cache_songname()
def sdvx_recent(u_id:int):
'''
:param u_id: 用户id
:return: 用户最近10首游玩记录
'''
db_apu = pymysql.connect(
host=apu_db.host,
port=apu_db.port,
user=apu_db.user,
password=apu_db.password,
database=apu_db.database_6
)
apu_cursor = db_apu.cursor()
try:
recent_playlog_sql = "SELECT * FROM `d_all_playdata` WHERE `f_uid` = '%s' ORDER BY `f_updateDtm` DESC LIMIT 0, 10" % (u_id)
apu_cursor.execute(recent_playlog_sql)
recent_playlog = apu_cursor.fetchall()
db_apu.close()
return recent_playlog
except:
db_apu.close()
raise ServerDataError
# 刷新缓存功能,新增刷新songlist(?)
@sucmd('/sdvx refresh cache',aliases=('更新SDVX数据'))
async def refresh_cache(session: CommandSession):
try:
get_player_list_cache()
await session.send("已刷新全局玩家缓存")
except Exception as e:
await session.send("玩家缓存刷新错误。")
print(f"玩家缓存刷新错误: {e}")
try:
update_music_db()
cache_songname()
await session.send("已更新songlist缓存")
except Exception as e:
await session.send("乐曲songlist缓存更新错误。")
print(f"乐曲songlist缓存更新错误: {e}")
def getsonginfo(f_music_id):
"""
通过乐曲ID返回乐曲名称和难度
:param f_music_id: 乐曲ID
:return: [乐曲名,难度,艺术家,更新时间]
"""
for music in music_db_dict['mdb']['music']:
if music['@id'] == '%s' % (f_music_id):
music_name = music['info']['title_name']
music_difficulty = music['difficulty']
music_artist = music['info']['artist_name']
music_update_time = music['info']['distribution_date']['#text']
return music_name, music_difficulty, music_artist, music_update_time
else:
music_name = "无法找到"
for music in music_db_merged_dict['mdb']['music']:
if music['@id'] == '%s' % (f_music_id):
music_name = music['info']['title_name']
music_difficulty = music['difficulty']
music_artist = music['info']['artist_name']
music_update_time = music['info']['distribution_date']['#text']
return music_name, music_difficulty, music_artist, music_update_time
else:
music_name = "无法找到"
return music_name
def get_grade_fx(f_score):
"""
通过分数计算GRADE系数
(S/AAA+/AAA/AA+/AA/A+/A/B/C/D)
:param f_score: 单曲分数
:return: GRADE加成系数
"""
if f_score >= 9900000:
grade_fx = 1.05
elif 9900000 > f_score >= 9800000:
grade_fx = 1.02
elif 9800000 > f_score >= 9700000:
grade_fx = 1
elif 9700000 > f_score >= 9500000:
grade_fx = 0.97
elif 9500000 > f_score >= 9300000:
grade_fx = 0.94
elif 9300000 > f_score >= 9000000:
grade_fx = 0.91
elif 9000000 > f_score >= 8700000:
grade_fx = 0.88
elif 8700000 > f_score >= 7500000:
grade_fx = 0.85
elif 7500000 > f_score >= 6500000:
grade_fx = 0.82
else:
grade_fx = 0.80
return grade_fx
def grade_fx_2_name(s_grade_fx):
"""将Grade系数转换为具体Grade评分名称"""
if s_grade_fx == 1.05:
s_grade = 'S'
elif s_grade_fx == 1.02:
s_grade = 'AAA+'
elif s_grade_fx == 1:
s_grade = 'AAA'
elif s_grade_fx == 0.97:
s_grade = 'AA+'
elif s_grade_fx == 0.94:
s_grade = 'AA'
elif s_grade_fx == 0.91:
s_grade = 'A+'
elif s_grade_fx == 0.88:
s_grade = 'A'
elif s_grade_fx == 0.85:
s_grade = 'B'
elif s_grade_fx == 0.82:
s_grade = 'C'
else:
s_grade = 'D'
return s_grade
# TODO:添加ID搜索贴纸、打歌面板、副屏面板、背景音乐的功能,暂定命令修改为 "/sdvxid [类型] [ID]" ,其中类型为song(0)/bgm(1)/screen(2)/panel(3)/sticker(4)
@sv.on_prefix(('/sdvxid','/sdvx id','sdvx搜歌'))
async def id_search_song(bot, ev: CQEvent):
input_raw = ev.message.extract_plain_text().split() #list
if len(input_raw) != 2:
await bot.send(ev, '查询格式错误,使用以下命令格式进行查询:“/sdvxid [类型] [ID]”(类型:0-歌曲,1-主题BGM,2-副屏背景,3-打歌面板,4-表情贴纸)')
return
input_type_raw = input_raw[0]
input_id_raw = input_raw[1]
# ID找歌
if input_type_raw == "0":
try:
input_id = int(input_id_raw)
if isinstance(input_id,int):
song_id = input_id
song = getsonginfo(song_id)
song_name = song[0]
if song != "无法找到":
song_diff_nov = song[1]['novice']['difnum']['#text']
song_diff_adv = song[1]['advanced']['difnum']['#text']
song_diff_ext = song[1]['exhaust']['difnum']['#text']
song_diff_inf = song[1]['infinite']['difnum']['#text']
if 'maximum' in song[1]:
song_diff_mxm = song[1]['maximum']['difnum']['#text']
else: song_diff_mxm = 0
song_artist = song[2]
song_update_time = song[3]
try:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\sdvx_jackets\\jk_{input_id_raw.zfill(4)}_1.png", "rb")
except:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png", "rb")
base64_str = base64.b64encode(data.read())
jacket = b'base64://' + base64_str
jacket = str(jacket, encoding = "utf-8")
await bot.send(ev, f'[CQ:image,file={jacket}]id.{song_id}\n乐曲名:{song_name}\n艺术家:{song_artist}\n更新日期:{song_update_time}\n{song_diff_nov}/{song_diff_adv}/{song_diff_ext}/{song_diff_inf}/{song_diff_mxm}')
else:
await bot.send(ev, '无法找到ID为此值的曲目')
except Exception as e:
await bot.send(ev, '输入错误:%s' %e)
# ID找BGM
elif input_type_raw == "1":
#查询bgm
bgm_name = id_search_bgm(input_id_raw)
await bot.send(ev, f'此ID对应的背景BGM为:\n{bgm_name}')
return
elif input_type_raw == "2":
#查询副屏
screen_name = id_search_touch(input_id_raw)
await bot.send(ev, f'此ID对应的副屏背景为:\n{screen_name}')
return
elif input_type_raw == "3":
#查询面板
panel_name = id_search_panel(input_id_raw)
await bot.send(ev, f'此ID对应的打歌面板为:\n{panel_name}')
return
elif input_type_raw == "4":
#查询表情
stamp_name = id_search_stamp(input_id_raw)
await bot.send(ev, f'此ID对应的表情贴纸为:\n{stamp_name}')
return
else:
await bot.send(ev, '查询类型错误,请输入0-4之间的整数。(类型:0-歌曲,1-主题BGM,2-副屏背景,3-打歌面板,4-表情贴纸)')
@sv.on_prefix(('sdvx抽歌','/sdvx rd','SDVX抽歌'))
async def chat_rd_sdvx(bot, ev: CQEvent):
input_difficulty_raw = ev.message.extract_plain_text().strip()
# 检查是否输入值
if len(input_difficulty_raw) == 0:
songs_total = len(song_name_lst)
song_rd_num = random.randint(0,songs_total - 1)
song = song_name_lst[song_rd_num]
s_id = song[0]
s_title = song[1]
s_difficulties = song[2]
s_artist = song[3]
s_update_time = song[4]
try:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\sdvx_jackets\\jk_{s_id.zfill(4)}_1.png", "rb")
except:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png", "rb")
base64_str = base64.b64encode(data.read())
jacket = b'base64://' + base64_str
jacket = str(jacket, encoding = "utf-8")
s_difficulty_nov = s_difficulties[0]
s_difficulty_adv = s_difficulties[1]
s_difficulty_ext = s_difficulties[2]
s_difficulty_inf = s_difficulties[3]
s_difficulty_mxm = s_difficulties[4]
await bot.send(ev, f'[CQ:image,file={jacket}]id.{s_id}\n乐曲名:{s_title}\n艺术家:{s_artist}\n更新日期:{s_update_time}\n{s_difficulty_nov}/{s_difficulty_adv}/{s_difficulty_ext}/{s_difficulty_inf}/{s_difficulty_mxm}')
else:
try:
input_difficulty = int(input_difficulty_raw)
# 将输入字符串转为整数并进入判定流程
if isinstance(input_difficulty,int) and input_difficulty <= 20 and input_difficulty > 0:
s_difficulty_nov = 0
s_difficulty_adv = 0
s_difficulty_ext = 0
s_difficulty_inf = 0
s_difficulty_mxm = 0
diff_str = str(input_difficulty)
# 重复抽歌直到抽出对应等级
while s_difficulty_nov != diff_str and s_difficulty_adv != diff_str and s_difficulty_ext != diff_str and s_difficulty_mxm != diff_str and s_difficulty_inf != diff_str :
songs_total = len(song_name_lst)
song_rd_num = random.randint(0,songs_total - 1)
song = song_name_lst[song_rd_num]
s_id = song[0]
s_title = song[1]
s_difficulties = song[2]
s_artist = song[3]
s_update_time = song[4]
s_difficulty_nov = s_difficulties[0]
s_difficulty_adv = s_difficulties[1]
s_difficulty_ext = s_difficulties[2]
s_difficulty_inf = s_difficulties[3]
s_difficulty_mxm = s_difficulties[4]
try:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\sdvx_jackets\\jk_{s_id.zfill(4)}_1.png", "rb")
except:
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png", "rb")
base64_str = base64.b64encode(data.read())
jacket = b'base64://' + base64_str
jacket = str(jacket, encoding = "utf-8")
await bot.send(ev, f'[CQ:image,file={jacket}]id.{s_id}\n乐曲名:{s_title}\n艺术家:{s_artist}\n更新日期:{s_update_time}\n{s_difficulty_nov}/{s_difficulty_adv}/{s_difficulty_ext}/{s_difficulty_inf}/{s_difficulty_mxm}')
else:
await bot.send(ev, '输入范围不在正常难易度中')
except Exception as e:
print(f"错误:{e}")
await bot.send(ev, '输入值错误,请输入1~20间的整数')
traceback.print_exc()
def getplayerplaylog(playerid):
"""
获取玩家全部最高分记录
:param playerid: 玩家SDVX ID
:return: 玩家全曲记录(最高分的一次)
"""
db_apu = pymysql.connect(
host=apu_db.host,
port=apu_db.port,
user=apu_db.user,
password=apu_db.password,
database=apu_db.database
)
apu_cursor = db_apu.cursor()
get_playlog_sql = "SELECT * FROM `d_user_playdata` WHERE `f_id` = '%s'" % (playerid)
try:
apu_cursor.execute(get_playlog_sql)
playlog = apu_cursor.fetchall()
except Exception as e:
print(str(e))
db_apu.close()
return playlog
def getmusictype(f_music_type:int):
'''
获取难度名称
:param f_music_type: 从数据库获取的原始难度类型
:return: [[难度缩写],[难度全称]]
'''
if f_music_type == 0:
type_name = 'NOV'
type_raw = 'novice'
elif f_music_type == 1:
type_name = 'ADV'
type_raw = 'advanced'
elif f_music_type == 2:
type_name = 'EXT'
type_raw = 'exhaust'
elif f_music_type == 3:
type_name = 'INF'
type_raw = 'infinite'
elif f_music_type == 4:
type_name = 'MXM'
type_raw = 'maximum'
return type_name, type_raw
def volforce(single_player_playlog):
'''
VF计算函数,输入玩家全部游玩分数记录,计算VF值,返回VF与B50
:param single_player_playlog: 由 getplayerplaylog 函数返回的全曲最高分
:return: [vf,[[乐曲ID,单曲vf,乐曲类型,乐曲难度,GRADE系数,通关系数,得分],...]]
'''
single_vf_list = []
# 获取单曲记录并计算单曲VF
for single_play in single_player_playlog:
f_music_id = single_play[1]
f_music_type = single_play[2]
f_score = int(single_play[3])
musictypeinfo = getmusictype(f_music_type)
try:
music_difnum = int(getsonginfo(f_music_id)[1][f'{musictypeinfo[1]}']['difnum']['#text'])
except:
music_difnum = 1
f_clear_type = single_play[5]
# 通过分数计算GRADE系数(S/AAA+/AAA/AA+/AA/A+/A/B/C/D)
grade_fx = get_grade_fx(f_score)
# 通关类型系数(PUC/UC/EXCESSIVE RATE通关/EFFECTIVE RATE通关/未通关)
if f_clear_type == '5':
clearType_fx = 1.1
elif f_clear_type == '4':
clearType_fx = 1.05
elif f_clear_type == '3':
clearType_fx = 1.02
elif f_clear_type == '2':
clearType_fx = 1
else:
clearType_fx = 0.5
# 单曲VF计算公式:Lv x(分数÷1000万)x(GRADE系数)x(通关类型系数)x 2(计算到小数点后一位,去尾)
single_vf = math.floor(music_difnum * (f_score / 10000000) * grade_fx * clearType_fx * 2 * 10) / 10
single_vf_list.append([f_music_id,single_vf,f_music_type,music_difnum,grade_fx,clearType_fx,f_score])
# 降序排序单曲VF并取前五十项计算VF
single_vf_list.sort(key=takeSecond,reverse=True)
single_vf_total = 0
for single_vf_num in single_vf_list[:50]:
single_vf_total = single_vf_num[1] + single_vf_total
vf_total = single_vf_total / 100
return round(vf_total, 3),single_vf_list[:50]
# B50绘图函数,从vf函数返回结果传入包含乐曲id、单曲force、难度类型、lv值、grade、通关类型、分数的b50结果list后
# 使用PIL库制作包含单曲封面,名称、等级、通关类型、grade与单曲Force的图片
@sv.on_prefix(('/sdvx b50','/sdvx vf','vf'))
async def b50_pic(bot, ev: CQEvent):
# 支持根据输入的SDVX ID查询B50
input_id_raw = ev.message.extract_plain_text().strip()
if len(input_id_raw) == 0:
#从数据库直接获取QQ绑定的对应UID
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
apu_getuid_sql = "SELECT QQ,gx_uid FROM grxx WHERE QQ = %s" % (qqid)
try:
apu_cursor.execute(apu_getuid_sql)
result_cx = apu_cursor.fetchall()
if not result_cx:
await bot.send(ev, "无法查询到您的数据,请检查是否通过签到功能注册bot功能", at_sender = True)
elif result_cx[0][1] == None:
await bot.send(ev, "您还没有绑定您的SDVX ID,请先使用 /sdvx bind 进行绑定", at_sender = True)
else:
u_id = result_cx[0][1]
except:
await bot.send(ev, "获取SDVXID时出错,请稍后重试")
db_bot.close()
elif input_id_raw.isdigit() == True:
if 0 < int(input_id_raw) < 100000000:
u_id = int(input_id_raw)
if len(input_id_raw) == 0 or (input_id_raw.isdigit() == True and 0 < int(input_id_raw) < 100000000):
msgid = ev.message_id
await bot.set_msg_emoji_like(message_id = msgid, emoji_id ='424')
u_name = get_player_name(int(u_id))
vf_func_return = volforce(getplayerplaylog(u_id))
vf = vf_func_return[0]
b50 = vf_func_return[1]
rdid = random.randint(0,2)
print(rdid)
with Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\00{rdid}_1.png") as vf_bg:
NOV_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\NOV.png").resize((253,156))
ADV_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\ADV.png").resize((253,156))
EXT_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\EXT.png").resize((253,156))
INF_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\INF.png").resize((253,156))
MXM_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\MXM.png").resize((253,156))
NOINFO_BG = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\NO_INFO.png").resize((253,156))
MARK_COMP = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\mark_comp.tga").resize((50,44))
MARK_COMP_EX = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\mark_comp_ex.tga").resize((50,44))
MARK_UC = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\mark_uc.tga").resize((50,44))
MARK_PUC = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\mark_puc.tga").resize((50,44))
MARK_CRASH = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\mark_crash.tga").resize((50,44))
GRADE_S = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_s.tga").resize((50,44))
GRADE_AAA_PLUS = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_aaa_plus.tga").resize((50,44))
GRADE_AAA = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_aaa.tga").resize((50,44))
GRADE_A = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_a.tga").resize((50,44))
GRADE_A_PLUS = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_a_plus.tga").resize((50,44))
GRADE_AA = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_aa.tga").resize((50,44))
GRADE_AA_PLUS = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_aa_plus.tga").resize((50,44))
GRADE_B = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_b.tga").resize((50,44))
GRADE_C = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_c.tga").resize((50,44))
GRADE_D = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\grade_d.tga").resize((50,44))
x_pos = 81
y_pos = 331
i = 0
draw = ImageDraw.Draw(vf_bg)
# 名字
font_name = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\DIGITAL-REGULAR.TTF", 80)
draw.text((835,70), f'{u_name}', 'white', font_name, stroke_width=2, stroke_fill='black')
# VF数值
font_vf = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\DIGITAL-REGULAR.TTF", 40)
draw.text((835,170),str(vf),"yellow",font_vf, stroke_width=1, stroke_fill="black")
# 日期
nowtime = datetime.datetime.today().isoformat(timespec='seconds')
draw.text((835,206),str(nowtime),"white",font_vf, stroke_width=1, stroke_fill="black")
try:
qq_img = Image.open(BytesIO((await get_usericon(f'{qqid}')).content)).resize((190,190)).convert("RGBA")
except:
qq_img = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png").resize((190,190)).convert("RGBA")
vf_bg.paste(qq_img,(574,63),qq_img)
for single_force in b50:
s_id = single_force[0] #乐曲ID
s_name = getsonginfo(s_id)[0] #从id获取乐曲名用于展示
s_force = single_force[1] #获取单曲VF用于展示
s_music_type_fx = single_force[2] #获取难度类型(用于判断对应难度封面是否存在,若存在则取该难度封面,否则取1难度封面)
s_music_type = getmusictype(s_music_type_fx)[0]
if s_music_type_fx == 0:
s_bg = NOV_BG
elif s_music_type_fx == 1:
s_bg = ADV_BG
elif s_music_type_fx == 2:
s_bg = EXT_BG
elif s_music_type_fx == 3:
s_bg = INF_BG
elif s_music_type_fx == 4:
s_bg = MXM_BG
s_difficulty = single_force[3] #获取难度等级用于展示
s_grade_fx = single_force[4] #获取得分等级GRADE系数,处理后获得GRADE进行展示
s_score = single_force[6]
vf_bg.paste(s_bg,(x_pos,y_pos),s_bg)
x_diff_title = 24
y_diff_title = -1
font_difficulty = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\DIGITAL-REGULAR.TTF", 20)
draw.text((x_pos + x_diff_title, y_pos + y_diff_title), f'{s_music_type} {s_difficulty}', 'white', font_difficulty)
try:
jackets = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\sdvx_jackets\\jk_{str(s_id).zfill(4)}_{s_music_type_fx}.png").resize((120,120))
except:
try:
jackets = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\sdvx_jackets\\jk_{str(s_id).zfill(4)}_1.png").resize((120,120))
except:
jackets = Image.open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\meitu.png").resize((120,120))
jackets = circle_corner(jackets,15)
x_jacket = 10
y_jacket = 26
vf_bg.paste(jackets,(x_pos+x_jacket,y_pos+y_jacket),jackets)
s_name_bool = 0
for single_charter in s_name:
if not(single_charter.isascii() or single_charter == ":"):
s_name_bool = 1
# 不带日文/中文
if s_name_bool == 0:
font_title = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf", 18)
if len(s_name) < 11:
draw.text((x_pos+140, y_pos+30), s_name, 'white', font_title, stroke_width=1, stroke_fill='black')
else:
font_title = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf", 16)
draw.text((x_pos+140, y_pos+30), s_name[0:10] + "...", 'white', font_title, stroke_width=1, stroke_fill='black')
else: # 带日文/中文
font_title = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf", 18)
if len(s_name) < 6:
draw.text((x_pos+140, y_pos+30), s_name, 'white', font_title, stroke_width=1, stroke_fill='black')
else:
font_title = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\NotoSansSC-Regular.otf", 16)
draw.text((x_pos+140, y_pos+30), s_name[0:5] + "...", 'white', font_title, stroke_width=1, stroke_fill='black')
# 乐曲ID
font_id = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\DIGITAL-REGULAR.TTF", 20)
draw.text((x_pos+140,y_pos+53), "VF: "+str(s_force/2), 'white', font_id, stroke_width=1, stroke_fill='black')
# 得分
font_score = ImageFont.truetype(nowdir + f"\\hoshino\\modules\\sdvx_helper\\DIGITAL-REGULAR.TTF", 25)
draw.text((x_pos+140, y_pos+72), str(s_score).zfill(8), 'white', font_score, stroke_width=1, stroke_fill='black')
# 等级
if s_grade_fx == 1.05:
grade_pic = GRADE_S
elif s_grade_fx == 1.02:
grade_pic = GRADE_AAA_PLUS
elif s_grade_fx == 1:
grade_pic = GRADE_AAA
elif s_grade_fx == 0.97:
grade_pic = GRADE_AA_PLUS
elif s_grade_fx == 0.94:
grade_pic = GRADE_AA
elif s_grade_fx == 0.91:
grade_pic = GRADE_A_PLUS
elif s_grade_fx == 0.88:
grade_pic = GRADE_A
elif s_grade_fx == 0.85:
grade_pic = GRADE_B
elif s_grade_fx == 0.82:
grade_pic = GRADE_C
else:
grade_pic = GRADE_D
vf_bg.paste(grade_pic,(x_pos+140,y_pos+102),grade_pic)
# 获取通关类型系数,处理后获得通关类型进行展示
s_clear_type_fx = single_force[5]
if s_clear_type_fx == 1.1:
mark = MARK_PUC
elif s_clear_type_fx == 1.05:
mark = MARK_UC
elif s_clear_type_fx == 1.02:
mark = MARK_COMP_EX
elif s_clear_type_fx == 1:
mark = MARK_COMP
else:
mark = MARK_CRASH
x_mark = 195
vf_bg.paste(mark,(x_pos+x_mark,y_pos+102),mark)
i+=1
if i == 5:
x_pos = 81
y_pos += 166
i = 0
else:
x_pos += 260
vf_bg.save(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\{u_id}.png") # 保存图片
data = open(nowdir + f"\\hoshino\\modules\\sdvx_helper\\pics\\{u_id}.png", "rb")
base64_str = base64.b64encode(data.read())
img_b64 = b'base64://' + base64_str
img_b64 = str(img_b64, encoding = "utf-8")
await bot.send(ev, f'[CQ:image,file={img_b64}]')
else:
await bot.send(ev,'输入值错误,请输入八位纯数字的SDVX ID')
@sv.on_prefix(('/sdvx bind'))
async def sdvx_bind(bot, ev: CQEvent):
get_player_list_cache() # 获取最新的玩家列表至缓存
#绑定SDVX ID到QQ上(使用本地数据库)
input_id_raw = ev.message.extract_plain_text().strip()
if len(input_id_raw) == 0:
await bot.send(ev, '请输入您的SDVX ID!')
elif input_id_raw.isdigit() == True:
if 0 < int(input_id_raw) < 100000000:
input_id = int(input_id_raw)
player_name = get_player_name(input_id)
if player_name:
# 查询是否游玩QQ
recent_data = sdvx_recent(input_id)
recent_song_id = recent_data[0][4]
if recent_song_id != '2062':
songinfo = getsonginfo(recent_song_id)
await bot.send(ev, f'需要绑定的账号最后游玩的歌曲为{songinfo[0]},请先游玩任意难度QQ,并于游玩结算后再立即使用此命令绑定SDVXID。')
return
db_bot = pymysql.connect(
host=bot_db.host,
port=bot_db.port,
user=bot_db.user,
password=bot_db.password,
database=bot_db.database
)
apu_cursor = db_bot.cursor()
qqid = ev.user_id
apu_getuid_sql = "SELECT QQ,gx_uid FROM grxx WHERE QQ = %s" % (qqid)
# 先执行一次查询,查询是否已经签到注册过
try:
apu_cursor.execute(apu_getuid_sql)
result_cx = apu_cursor.fetchall()
apu_bind_sql = "UPDATE `grxx` SET `gx_uid`='%s' WHERE `QQ`='%s'" % (input_id, qqid)
if not result_cx:
await bot.send(ev, "无法查询到您的数据,请检查是否通过签到功能注册bot功能", at_sender = True)
elif result_cx[0][1] == None:
# 在此后进行绑定语句编程
try:
apu_cursor.execute(apu_bind_sql)
db_bot.commit()
await bot.send(ev, f'已为您绑定成功以下ID:{input_id}')
except Exception as e:
await bot.send(ev, f'查询过程中发生错误:{e}')
else:
await bot.send(ev, f'您已经绑定过了,即将为您重新绑定')
try:
apu_cursor.execute(apu_bind_sql)
db_bot.commit()