forked from QingMuCat/nonebot_plugin_xiuxian_2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xiuxian2_handle.py
1340 lines (1188 loc) · 48.4 KB
/
xiuxian2_handle.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
try:
import ujson as json
except ImportError:
import json
import datetime
import random
import sqlite3
from collections import namedtuple
from pathlib import Path
from nonebot.log import logger
from .data_source import jsondata
from .xiuxian_config import XiuConfig
from . import DRIVER
DATABASE = Path() / "data" / "xiuxian"
xiuxian_data = namedtuple("xiuxian_data", ["no", "user_id", "linggen", "level"])
UserDate = namedtuple("UserDate",
["id", "user_id", "stone", "root", "root_type", "level", "power", "create_time", "is_sign", "exp",
"user_name", "level_up_cd", "level_up_rate", "sect_id", "sect_position", "hp", "mp", "atk",
"atkpractice",
"sect_task", "sect_contribution", "sect_elixir_get", "blessed_spot_flag", "blessed_spot_name"])
UserCd = namedtuple("UserCd", ["user_id", "type", "create_time", "scheduled_time"])
SectInfo = namedtuple("SectInfo",
["sect_id", "sect_name", "sect_owner", "sect_scale", "sect_used_stone", "sect_fairyland",
"sect_materials", "mainbuff", "secbuff", "elixir_room_level"])
BuffInfo = namedtuple("BuffInfo",
["id", "user_id", "main_buff", "sec_buff", "faqi_buff", "fabao_weapon", "armor_buff", "atk_buff",
"blessed_spot"])
back = namedtuple("back", ["user_id", "goods_id", "goods_name", "goods_type", "goods_num", "create_time", "update_time",
"remake", "day_num", "all_num", "action_time", "state", "bind_num"])
num = '578043031'
class XiuxianDateManage:
global num
_instance = {}
_has_init = {}
def __new__(cls):
if cls._instance.get(num) is None:
cls._instance[num] = super(XiuxianDateManage, cls).__new__(cls)
return cls._instance[num]
def __init__(self):
if not self._has_init.get(num):
self._has_init[num] = True
self.database_path = DATABASE
if not self.database_path.exists():
self.database_path.mkdir(parents=True)
self.database_path /= "xiuxian.db"
self.conn = sqlite3.connect(self.database_path)
# self._create_file()
else:
self.database_path /= "xiuxian.db"
self.conn = sqlite3.connect(self.database_path)
logger.info(f"修仙数据库已连接!")
self._check_data()
def close(self):
self.conn.close()
logger.info(f"修仙数据库关闭!")
def _create_file(self) -> None:
"""创建数据库文件"""
c = self.conn.cursor()
c.execute('''CREATE TABLE User_xiuxian
(NO INTEGER PRIMARY KEY UNIQUE,
USERID TEXT ,
level INTEGER ,
root INTEGER
);''')
c.execute('''''')
c.execute('''''')
self.conn.commit()
def _check_data(self):
"""检查数据完整性"""
c = self.conn.cursor()
for i in XiuConfig().sql_table:
if i == "user_xiuxian":
try:
c.execute(f"select count(1) from {i}")
except sqlite3.OperationalError:
c.execute("""CREATE TABLE "user_xiuxian" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER NOT NULL,
"stone" integer DEFAULT 0,
"root" TEXT,
"root_type" TEXT,
"level" TEXT,
"power" integer DEFAULT 0,
"create_time" integer,
"is_sign" integer DEFAULT 0,
"exp" integer DEFAULT 0,
"user_name" TEXT DEFAULT NULL,
"level_up_cd" integer DEFAULT NULL,
"level_up_rate" integer DEFAULT 0
);""")
elif i == "user_cd":
try:
c.execute(f"select count(1) from {i}")
except sqlite3.OperationalError:
c.execute("""CREATE TABLE "user_cd" (
"user_id" INTEGER NOT NULL,
"type" integer DEFAULT 0,
"create_time" integer DEFAULT NULL,
"scheduled_time" integer,
PRIMARY KEY ("user_id")
);""")
elif i == "sects":
try:
c.execute(f"select count(1) from {i}")
except sqlite3.OperationalError:
c.execute("""CREATE TABLE "sects" (
"sect_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"sect_name" TEXT NOT NULL,
"sect_owner" integer,
"sect_scale" integer NOT NULL,
"sect_used_stone" integer,
"sect_fairyland" integer
);""")
elif i == "back":
try:
c.execute(f"select count(1) from {i}")
except sqlite3.OperationalError:
pass
c.execute("""CREATE TABLE "back" (
"user_id" INTEGER NOT NULL,
"goods_id" INTEGER NOT NULL,
"goods_name" TEXT,
"goods_type" TEXT,
"goods_num" INTEGER,
"create_time" TEXT,
"update_time" TEXT,
"remake" TEXT,
"day_num" INTEGER DEFAULT 0,
"all_num" INTEGER DEFAULT 0,
"action_time" TEXT,
"state" INTEGER DEFAULT 0
);""")
elif i == "BuffInfo":
try:
c.execute(f"select count(1) from {i}")
except sqlite3.OperationalError:
c.execute("""CREATE TABLE "BuffInfo" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" integer DEFAULT 0,
"main_buff" integer DEFAULT 0,
"sec_buff" integer DEFAULT 0,
"faqi_buff" integer DEFAULT 0,
"fabao_weapon" integer DEFAULT 0
);""")
for i in XiuConfig().sql_user_xiuxian:
try:
c.execute(f"select {i} from user_xiuxian")
except sqlite3.OperationalError:
sql = f"ALTER TABLE user_xiuxian ADD COLUMN {i} INTEGER DEFAULT 0;"
print(sql)
c.execute(sql)
for s in XiuConfig().sql_sects:
try:
c.execute(f"select {s} from sects")
except sqlite3.OperationalError:
sql = f"ALTER TABLE sects ADD COLUMN {s} INTEGER DEFAULT 0;"
print(sql)
c.execute(sql)
for m in XiuConfig().sql_buff:
try:
c.execute(f"select {m} from BuffInfo")
except sqlite3.OperationalError:
sql = f"ALTER TABLE BuffInfo ADD COLUMN {m} INTEGER DEFAULT 0;"
print(sql)
c.execute(sql)
for b in XiuConfig().sql_back:
try:
c.execute(f"select {b} from back")
except sqlite3.OperationalError:
sql = f"ALTER TABLE back ADD COLUMN {b} INTEGER DEFAULT 0;"
print(sql)
c.execute(sql)
self.conn.commit()
@classmethod
def close_dbs(cls):
XiuxianDateManage().close()
def _create_user(self, user_id: str, root: str, type: str, power: str, create_time, user_name) -> None:
"""在数据库中创建用户并初始化"""
c = self.conn.cursor()
sql = f"INSERT INTO user_xiuxian (user_id,stone,root,root_type,level,power,create_time,user_name,exp) VALUES (?,0,?,?,'江湖好手',?,?,?,100)"
c.execute(sql, (user_id, root, type, power, create_time, user_name))
self.conn.commit()
def get_user_message(self, user_id):
"""根据USER_ID获取用户信息,不获取功法加成"""
cur = self.conn.cursor()
sql = f"select * from user_xiuxian where user_id=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return None
else:
return UserDate(*result)
def get_user_real_info(self, user_id):
"""根据USER_ID获取用户信息,获取功法加成"""
cur = self.conn.cursor()
sql = f"select * from user_xiuxian where user_id=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return None
else:
return UserDate(*final_user_data(result))
def get_sect_info(self, sect_id):
"""
通过宗门编号获取宗门信息
:param sect_id: 宗门编号
:return:
"""
cur = self.conn.cursor()
sql = f"select * from sects where sect_id=?"
cur.execute(sql, (sect_id,))
result = cur.fetchone()
if not result:
return None
else:
return SectInfo(*result)
def get_user_message2(self, user_id):
"""根据user_name获取用户信息"""
cur = self.conn.cursor()
sql = f"select * from user_xiuxian where user_name=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return None
else:
return UserDate(*result)
def create_user(self, user_id, *args):
"""校验用户是否存在"""
cur = self.conn.cursor()
sql = f"select * from user_xiuxian where user_id=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
self._create_user(user_id, args[0], args[1], args[2], args[3], args[4])
self.conn.commit()
return '欢迎进入修仙世界的,你的灵根为:{},类型是:{},你的战力为:{},当前境界:江湖好手'.format(args[0], args[1], args[2], args[3])
else:
return '您已迈入修仙世界,输入【我的修仙信息】获取数据吧!'
def get_sign(self, user_id):
"""获取用户签到信息"""
cur = self.conn.cursor()
sql = f"select is_sign from user_xiuxian where user_id=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return '修仙界没有你的足迹,输入 我要修仙 加入修仙世界吧!'
elif result[0] == 0:
ls = random.randint(XiuConfig().sign_in_lingshi_lower_limit, XiuConfig().sign_in_lingshi_upper_limit)
sql2 = f"UPDATE user_xiuxian SET is_sign=1,stone=stone+? WHERE user_id=?"
cur.execute(sql2, (ls,user_id))
self.conn.commit()
return '签到成功,获取{}块灵石!'.format(ls)
elif result[0] == 1:
return '贪心的人是不会有好运的!'
def ramaker(self, lg, type, user_id):
"""洗灵根"""
cur = self.conn.cursor()
# 查灵石
sql_s = f"SELECT stone FROM user_xiuxian WHERE user_id=?"
cur.execute(sql_s, (user_id,))
result = cur.fetchone()
if result[0] >= XiuConfig().remake:
sql = f"UPDATE user_xiuxian SET root=?,root_type=?,stone=stone-? WHERE user_id=?"
cur.execute(sql, (lg, type, XiuConfig().remake, user_id))
self.conn.commit()
self.update_power2(user_id)
return "逆天之行,重获新生,新的灵根为:{},类型为:{}".format(lg, type)
else:
return "你的灵石还不够呢,快去赚点灵石吧!"
def get_root_rate(self, name):
"""获取灵根倍率"""
data = jsondata.root_data()
return data[name]['type_speeds']
def get_level_power(self, name):
"""获取境界倍率|exp"""
data = jsondata.level_data()
return data[name]['power']
def update_power2(self, user_id) -> None:
"""更新战力"""
UserMessage = self.get_user_message(user_id)
cur = self.conn.cursor()
level = jsondata.level_data()
root = jsondata.root_data()
sql = f"UPDATE user_xiuxian SET power=round(exp*?*?,0) WHERE user_id=?"
cur.execute(sql, (root[UserMessage.root_type]["type_speeds"], level[UserMessage.level]["spend"], user_id))
self.conn.commit()
def update_ls(self, user_id, price, key):
"""更新灵石 1为增加,2为减少"""
cur = self.conn.cursor()
if key == 1:
sql = f"UPDATE user_xiuxian SET stone=stone+? WHERE user_id=?"
cur.execute(sql, (price, user_id))
self.conn.commit()
elif key == 2:
sql = f"UPDATE user_xiuxian SET stone=stone-? WHERE user_id=?"
cur.execute(sql, (price, user_id))
self.conn.commit()
def update_root(self, user_id, key):
"""更新灵根 1为混沌,2为融合,3为超,4为龙,5为天"""
cur = self.conn.cursor()
if int(key) == 1:
sql = f"UPDATE user_xiuxian SET root=?,root_type=? WHERE user_id=?"
cur.execute(sql, ("全属性灵根", "混沌灵根", user_id))
self.conn.commit()
elif int(key) == 2:
sql = f"UPDATE user_xiuxian SET root=?,root_type=? WHERE user_id=?"
cur.execute(sql, ("融合万物灵根", "融合灵根", user_id))
self.conn.commit()
elif int(key) == 3:
sql = f"UPDATE user_xiuxian SET root=?,root_type=? WHERE user_id=?"
cur.execute(sql, ("月灵根", "超灵根", user_id))
self.conn.commit()
elif int(key) == 4:
sql = f"UPDATE user_xiuxian SET root=?,root_type=? WHERE user_id=?"
cur.execute(sql, ("言灵灵根", "龙灵根", user_id))
self.conn.commit()
elif int(key) == 5:
sql = f"UPDATE user_xiuxian SET root=?,root_type=? WHERE user_id=?"
cur.execute(sql, ("金灵根", "天灵根", user_id))
self.conn.commit()
def update_ls_all(self, price):
"""所有用户增加灵石"""
cur = self.conn.cursor()
sql = f"UPDATE user_xiuxian SET stone=stone+?"
cur.execute(sql, (price,))
self.conn.commit()
def get_ls_rank(self):
"""灵石排行榜"""
sql = f"SELECT user_id,stone FROM user_xiuxian WHERE stone>0 ORDER BY stone DESC LIMIT 5"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def singh_remake(self):
"""重置签到"""
sql = f"UPDATE user_xiuxian SET is_sign=0"
cur = self.conn.cursor()
cur.execute(sql, )
self.conn.commit()
def update_user_name(self, user_id, user_name):
"""更新用户道号"""
cur = self.conn.cursor()
get_name = f"select user_name from user_xiuxian where user_name=?"
cur.execute(get_name, (user_name,))
result = cur.fetchone()
if result:
return "已存在该道号!"
else:
sql = f"UPDATE user_xiuxian SET user_name=? where user_id=?"
cur.execute(sql, (user_name, user_id))
self.conn.commit()
return '道友的道号更新成功拉~'
def updata_level_cd(self, user_id):
"""更新破镜CD"""
sql = f"UPDATE user_xiuxian SET level_up_cd=? where user_id=?"
cur = self.conn.cursor()
now_time = datetime.datetime.now()
cur.execute(sql, (now_time, user_id))
self.conn.commit()
def updata_level(self, user_id, level_name):
"""更新境界"""
sql = f"UPDATE user_xiuxian SET level=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (level_name, user_id))
self.conn.commit()
def get_user_cd(self, user_id):
"""
获取用户操作CD
:param user_id: QQ
"""
sql = f"SELECT * FROM user_cd WHERE user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
result = cur.fetchone()
if result:
return UserCd(*result)
else:
self.insert_user_cd(user_id, )
return None
def insert_user_cd(self, user_id) -> None:
"""
添加用户至CD表
:param user_id: qq
:return:
"""
sql = f"INSERT INTO user_cd (user_id) VALUES (?)"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def create_sect(self, user_id, sect_name) -> None:
"""
创建宗门
:param user_id:qq
:param sect_name:宗门名称
:return:
"""
sql = f"INSERT INTO sects(sect_name, sect_owner, sect_scale, sect_used_stone) VALUES (?,?,0,0)"
cur = self.conn.cursor()
cur.execute(sql, (sect_name, user_id))
self.conn.commit()
def get_sect_info_by_qq(self, user_id):
"""
通过用户qq获取宗门信息
:param user_id:
:return:
"""
cur = self.conn.cursor()
sql = f"select * from sects where sect_owner=?"
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return None
else:
return SectInfo(*result)
def get_sect_info_by_id(self, sect_id):
"""
通过宗门id获取宗门信息
:param sect_id:
:return:
"""
cur = self.conn.cursor()
sql = f"select * from sects where sect_id=?"
cur.execute(sql, (sect_id,))
result = cur.fetchone()
if not result:
return None
else:
return SectInfo(*result)
def update_usr_sect(self, user_id, usr_sect_id, usr_sect_position):
"""
更新用户信息表的宗门信息字段
:param user_id:
:param usr_sect_id:
:param usr_sect_position:
:return:
"""
sql = f"UPDATE user_xiuxian SET sect_id=?,sect_position=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (usr_sect_id, usr_sect_position, user_id))
self.conn.commit()
def get_all_sect_id(self):
"""获取全部宗门id"""
sql = f"SELECT sect_id FROM sects"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def in_closing(self, user_id, the_type):
"""
更新用户操作CD
:param user_id: qq
:param the_type: 0:无状态 1:闭关中 2:历练中
:return:
"""
now_time = None
if the_type == 1:
now_time = datetime.datetime.now()
elif the_type == 0:
now_time = 0
elif the_type == 2:
now_time = datetime.datetime.now()
# scheduled_time = datetime.datetime.now() + datetime.timedelta(minutes=int(the_time))
sql = f"UPDATE user_cd SET type=?,create_time=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (the_type, now_time, user_id))
self.conn.commit()
def out_closing(self, user_id, the_type):
"""出关状态更新"""
pass
def update_exp(self, user_id, exp):
"""增加修为"""
sql = f"UPDATE user_xiuxian SET exp=exp+? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (int(exp), user_id))
self.conn.commit()
def update_j_exp(self, user_id, exp):
"""减少修为"""
sql = f"UPDATE user_xiuxian SET exp=exp-? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (int(exp), user_id))
self.conn.commit()
def del_exp_decimal(self, user_id, exp):
"""去浮点"""
sql = f"UPDATE user_xiuxian SET exp=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (int(exp), user_id))
self.conn.commit()
def realm_top(self):
"""境界排行榜"""
sql = f"""SELECT user_name,level,exp FROM user_xiuxian
WHERE user_name is NOT NULL
ORDER BY CASE
WHEN level = '祭道之上' THEN '1'
WHEN level = '仙帝境圆满' THEN '2'
WHEN level = '仙帝境中期' THEN '3'
WHEN level = '仙帝境初期' THEN '4'
WHEN level = '准帝境圆满' THEN '5'
WHEN level = '准帝境中期' THEN '6'
WHEN level = '准帝境初期' THEN '7'
WHEN level = '仙王境圆满' THEN '8'
WHEN level = '仙王境中期' THEN '9'
WHEN level = '仙王境初期' THEN '10'
WHEN level = '真仙境圆满' THEN '11'
WHEN level = '真仙境中期' THEN '12'
WHEN level = '真仙境初期' THEN '13'
WHEN level = '至尊境圆满' THEN '14'
WHEN level = '至尊境中期' THEN '15'
WHEN level = '至尊境初期' THEN '16'
WHEN level = '遁一境圆满' THEN '17'
WHEN level = '遁一境中期' THEN '18'
WHEN level = '遁一境初期' THEN '19'
WHEN level = '斩我境圆满' THEN '20'
WHEN level = '斩我境中期' THEN '21'
WHEN level = '斩我境初期' THEN '22'
WHEN level = '虚道境圆满' THEN '23'
WHEN level = '虚道境中期' THEN '24'
WHEN level = '虚道境初期' THEN '25'
WHEN level = '天神境圆满' THEN '26'
WHEN level = '天神境中期' THEN '27'
WHEN level = '天神境初期' THEN '28'
WHEN level = '圣祭境圆满' THEN '29'
WHEN level = '圣祭境中期' THEN '30'
WHEN level = '圣祭境初期' THEN '31'
WHEN level = '真一境圆满' THEN '32'
WHEN level = '真一境中期' THEN '33'
WHEN level = '真一境初期' THEN '34'
WHEN level = '神火境圆满' THEN '35'
WHEN level = '神火境中期' THEN '36'
WHEN level = '神火境初期' THEN '37'
WHEN level = '尊者境圆满' THEN '38'
WHEN level = '尊者境中期' THEN '39'
WHEN level = '尊者境初期' THEN '40'
WHEN level = '列阵境圆满' THEN '41'
WHEN level = '列阵境中期' THEN '42'
WHEN level = '列阵境初期' THEN '43'
WHEN level = '铭纹境圆满' THEN '44'
WHEN level = '铭纹境中期' THEN '45'
WHEN level = '铭纹境初期' THEN '46'
WHEN level = '化灵境圆满' THEN '47'
WHEN level = '化灵境中期' THEN '48'
WHEN level = '化灵境初期' THEN '49'
WHEN level = '洞天境圆满' THEN '50'
WHEN level = '洞天境中期' THEN '51'
WHEN level = '洞天境初期' THEN '52'
WHEN level = '搬血境圆满' THEN '53'
WHEN level = '搬血境中期' THEN '54'
WHEN level = '搬血境初期' THEN '55'
WHEN level = '江湖好手' THEN '56'
ELSE level END ASC,exp DESC LIMIT 10"""
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def get_exp_rank(self, user_id):
"""修为排行"""
sql = f"select rank from(select user_id,exp,dense_rank() over (ORDER BY exp desc) as 'rank' FROM user_xiuxian) where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
result = cur.fetchone()
return result
def get_stone_rank(self, user_id):
"""灵石排行"""
sql = f"select rank from(select user_id,stone,dense_rank() over (ORDER BY stone desc) as 'rank' FROM user_xiuxian) where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
result = cur.fetchone()
return result
def stone_top(self):
sql = f"SELECT user_name,stone FROM user_xiuxian WHERE user_name is NOT NULL ORDER BY stone DESC LIMIT 10"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def power_top(self):
"""战力排行榜"""
sql = f"SELECT user_name,power FROM user_xiuxian WHERE user_name is NOT NULL ORDER BY power DESC LIMIT 10"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def scale_top(self):
"""
宗门建设度排行榜
:return:
"""
sql = f"SELECT sect_id, sect_name, sect_scale FROM sects WHERE sect_owner is NOT NULL ORDER BY sect_scale DESC"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def get_all_scale(self):
"""
获取所有宗门信息
:return:
"""
sql = f"SELECT * FROM sects WHERE sect_owner is NOT NULL"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
results = []
for r in result:
results.append(SectInfo(*r))
return results
def get_top1_user(self):
"""
获取修为第一的用户
"""
cur = self.conn.cursor()
sql = f"select * from user_xiuxian ORDER BY exp DESC LIMIT 1"
cur.execute(sql)
result = cur.fetchone()
if not result:
return None
else:
return UserDate(*result)
def donate_update(self, sect_id, stone_num):
"""宗门捐献更新建设度及可用灵石"""
sql = f"UPDATE sects SET sect_used_stone=sect_used_stone+?,sect_scale=sect_scale+? where sect_id=?"
cur = self.conn.cursor()
cur.execute(sql, (stone_num, stone_num * 10, sect_id))
self.conn.commit()
def update_sect_materials(self, sect_id, sect_materials, key):
"""更新资材 1为增加,2为减少"""
cur = self.conn.cursor()
if key == 1:
sql = f"UPDATE sects SET sect_materials=sect_materials+? WHERE sect_id=?"
cur.execute(sql, (sect_materials, sect_id))
self.conn.commit()
elif key == 2:
sql = f"UPDATE sects SET sect_materials=sect_materials-? WHERE sect_id=?"
cur.execute(sql, (sect_materials, sect_id))
self.conn.commit()
def get_all_sects_id_scale(self):
"""
获取所有宗门信息
:return
:result[0] = sect_id
:result[1] = 建设度 sect_scale,
:result[2] = 丹房等级 elixir_room_level
"""
sql = f"SELECT sect_id, sect_scale, elixir_room_level FROM sects WHERE sect_owner is NOT NULL ORDER BY sect_scale DESC"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def get_all_users_by_sect_id(self, sect_id):
"""
获取宗门所有成员信息
:return: 成员列表
"""
sql = f"SELECT * FROM user_xiuxian WHERE sect_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (sect_id,))
result = cur.fetchall()
results = []
for user in result:
results.append(UserDate(*user))
return results
def do_work(self, user_id, the_type, sc_time=None):
"""
更新用户操作CD
:param sc_time: 任务
:param user_id: qq
:param the_type: 0:无状态 1:闭关中 2:历练中 3:探索秘境中
:param the_time: 本次操作的时长
:return:
"""
now_time = None
if the_type == 1:
now_time = datetime.datetime.now()
elif the_type == 0:
now_time = 0
elif the_type == 2:
now_time = datetime.datetime.now()
elif the_type == 3:
now_time = datetime.datetime.now()
sql = f"UPDATE user_cd SET type=?,create_time=?,scheduled_time=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (the_type, now_time, sc_time, user_id))
self.conn.commit()
def update_levelrate(self, user_id, rate):
"""更新突破成功率"""
sql = f"UPDATE user_xiuxian SET level_up_rate=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (rate, user_id))
self.conn.commit()
def update_user_attribute(self, user_id, hp, mp, atk):
"""更新用户HP,MP,ATK信息"""
sql = f"UPDATE user_xiuxian SET hp=?,mp=?,atk=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (hp, mp, atk, user_id))
self.conn.commit()
def update_user_hp_mp(self, user_id, hp, mp):
"""更新用户HP,MP信息"""
sql = f"UPDATE user_xiuxian SET hp=?,mp=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (hp, mp, user_id))
self.conn.commit()
def update_user_sect_contribution(self, user_id, sect_contribution):
"""更新用户宗门贡献度"""
sql = f"UPDATE user_xiuxian SET sect_contribution=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (sect_contribution, user_id))
self.conn.commit()
def update_user_hp(self, user_id):
"""重置用户状态信息"""
sql = f"UPDATE user_xiuxian SET hp=exp/2,mp=exp,atk=exp/10 where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def restate(self, user_id=None):
"""restate重置所有用户状态或重置对应人状态"""
if user_id is None:
sql = f"UPDATE user_xiuxian SET hp=exp/2,mp=exp,atk=exp/10"
cur = self.conn.cursor()
cur.execute(sql, )
self.conn.commit()
else:
sql = f"UPDATE user_xiuxian SET hp=exp/2,mp=exp,atk=exp/10 where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def get_back_msg(self, user_id):
"""获取用户背包信息"""
sql = f"SELECT * FROM back where user_id=? and goods_num >= 1"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
result = cur.fetchall()
# msg = f"你的背包\n"
# for i in result:
# msg += f"{i},"
results = []
if not result:
results = None
for r in result:
results.append(back(*r))
return results
def goods_num(self, user_id, goods_id):
"""
判断用户物品数量
:param user_id: 用户qq
:param goods_id: 物品id
:return: 物品数量
"""
sql = f"SELECT num FROM back where user_id=? and goods_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id, goods_id))
result = cur.fetchone()
if result:
return result[0]
else:
return 0
def get_all_user_exp(self, level):
"""查询所有对应大境界玩家的修为"""
sql = f"SELECT exp FROM user_xiuxian WHERE level like '{level}%'"
cur = self.conn.cursor()
cur.execute(sql, )
result = cur.fetchall()
return result
def update_user_atkpractice(self, user_id, atkpractice):
"""更新用户攻击修炼等级"""
sql = f"UPDATE user_xiuxian SET atkpractice={atkpractice} where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def update_user_sect_task(self, user_id, sect_task):
"""更新用户宗门任务次数"""
sql = f"UPDATE user_xiuxian SET sect_task=sect_task+? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (sect_task, user_id))
self.conn.commit()
def sect_task_reset(self):
"""重置宗门任务次数"""
sql = f"UPDATE user_xiuxian SET sect_task=0"
cur = self.conn.cursor()
cur.execute(sql, )
self.conn.commit()
def update_sect_scale_and_used_stone(self, sect_id, sect_used_stone, sect_scale):
"""更新宗门灵石、建设度"""
sql = f"UPDATE sects SET sect_used_stone=?,sect_scale=? where sect_id=?"
cur = self.conn.cursor()
cur.execute(sql, (sect_used_stone, sect_scale, sect_id))
self.conn.commit()
def update_sect_elixir_room_level(self, sect_id, level):
"""更新宗门丹房等级"""
sql = f"UPDATE sects SET elixir_room_level=? where sect_id=?"
cur = self.conn.cursor()
cur.execute(sql, (level, sect_id))
self.conn.commit()
def update_user_sect_elixir_get_num(self, user_id):
"""更新用户每日领取丹药领取次数"""
sql = f"UPDATE user_xiuxian SET sect_elixir_get=1 where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def sect_elixir_get_num_reset(self):
"""重置宗门丹药领取次数"""
sql = f"UPDATE user_xiuxian SET sect_elixir_get=0"
cur = self.conn.cursor()
cur.execute(sql, )
self.conn.commit()
def update_sect_mainbuff(self, sect_id, mainbuffid):
"""更新宗门当前的主修功法"""
sql = f"UPDATE sects SET mainbuff=? where sect_id=?"
cur = self.conn.cursor()
cur.execute(sql, (mainbuffid, sect_id))
self.conn.commit()
def update_sect_secbuff(self, sect_id, secbuffid):
"""更新宗门当前的神通"""
sql = f"UPDATE sects SET secbuff=? where sect_id=?"
cur = self.conn.cursor()
cur.execute(sql, (secbuffid, sect_id))
self.conn.commit()
def initialize_user_buff_info(self, user_id):
"""初始化用户buff信息"""
sql = f"INSERT INTO BuffInfo (user_id,main_buff,sec_buff,faqi_buff,fabao_weapon) VALUES (?,0,0,0,0)"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def get_user_buff_info(self, user_id):
"""获取用户buff信息"""
sql = f"select * from BuffInfo where user_id =?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
result = cur.fetchone()
if not result:
return None
else:
return BuffInfo(*result)
def updata_user_main_buff(self, user_id, id):
"""更新用户主功法信息"""
sql = f"UPDATE BuffInfo SET main_buff = ? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (id, user_id,))
self.conn.commit()
def updata_user_sec_buff(self, user_id, id):
"""更新用户副功法信息"""
sql = f"UPDATE BuffInfo SET sec_buff = ? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (id, user_id,))
self.conn.commit()
def updata_user_faqi_buff(self, user_id, id):
"""更新用户法器信息"""
sql = f"UPDATE BuffInfo SET faqi_buff = ? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (id, user_id,))
self.conn.commit()
def updata_user_fabao_weapon(self, user_id, id):
"""更新用户法宝信息"""
sql = f"UPDATE BuffInfo SET fabao_weapon = ? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (id, user_id,))
self.conn.commit()
def updata_user_armor_buff(self, user_id, id):
"""更新用户防具信息"""
sql = f"UPDATE BuffInfo SET armor_buff = ? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (id, user_id,))
self.conn.commit()
def updata_user_atk_buff(self, user_id, buff):
"""更新用户永久攻击buff信息"""
sql = f"UPDATE BuffInfo SET atk_buff=atk_buff+? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (buff, user_id,))
self.conn.commit()
def updata_user_blessed_spot(self, user_id, blessed_spot):
"""更新用户洞天福地等级"""
sql = f"UPDATE BuffInfo SET blessed_spot=? where user_id = ?"
cur = self.conn.cursor()
cur.execute(sql, (blessed_spot, user_id,))
self.conn.commit()
def update_user_blessed_spot_flag(self, user_id):
"""更新用户洞天福地是否开启"""
sql = f"UPDATE user_xiuxian SET blessed_spot_flag=1 where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (user_id,))
self.conn.commit()
def update_user_blessed_spot_name(self, user_id, blessed_spot_name):
"""更新用户洞天福地的名字"""
sql = f"UPDATE user_xiuxian SET blessed_spot_name=? where user_id=?"
cur = self.conn.cursor()
cur.execute(sql, (blessed_spot_name, user_id,))
self.conn.commit()
def day_num_reset(self):
"""重置丹药每日使用次数"""
sql = f"UPDATE back SET day_num=0 where goods_type='丹药'"
cur = self.conn.cursor()
cur.execute(sql, )
self.conn.commit()
def send_back(self, user_id, goods_id, goods_name, goods_type, goods_num, bind_flag=0):
"""
插入物品至背包
:param user_id: 用户qq
:param goods_id: 物品id
:param goods_name: 物品名称
:param goods_type: 物品类型
:param goods_num: 物品数量
:param bind_flag: 是否绑定物品,0-非绑定,1-绑定
:return: None
"""