forked from sdyxxjj123/Daidao
-
Notifications
You must be signed in to change notification settings - Fork 1
/
daidao.py
1678 lines (1571 loc) · 70.5 KB
/
daidao.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 asyncio
import base64
import os
import aiohttp
import random
import sqlite3
import math
from datetime import datetime, timedelta
import pytz
from io import BytesIO
from PIL import Image
import hoshino
from hoshino import Service, priv
from hoshino.typing import CQEvent
import copy
import re
import json
import nonebot
from nonebot import on_command, on_request,MessageSegment
from hoshino import sucmd,config,get_bot
from hoshino.typing import NoticeSession
from multiprocessing import Pool
import requests
import imgkit
from HTMLTable import HTMLTable
sv = Service('daidao', bundle='daidao', help_='''
'''.strip())
DAIDAO_DB_PATH = os.path.expanduser('~/.hoshino/daidao.db')
DAIDAO_jpg_PATH = os.path.expanduser('~/.hoshino/')
SUPERUSERS = config.SUPERUSERS
GroupID_ON = True #当GO版本为0.94fix4以上时,允许从群内发起私聊(即使用管理员身份强制私聊,不需要对方主动私聊过),如果低于该版本请不要开启
NOprivate = True #全局开关,启用后,不再尝试私聊,也不会在群内发送“私聊失败”等消息,仅做记录使用,降低机器人冻结风险。
yesprivate = {}#上面填了True 的情况下,还想开私聊的白名单群(留给想只给自己群用的),按逗号隔开
jindu_bt_color="#2b4490"#进度表标题颜色,不懂?百度颜色表
jindu_bg_color="#48a6fb"#进度表表格 背景颜色
jindu_wz_color="#fff"#进度表表格 文字颜色
jindu_bk_color="#181d4b"#进度表表格 边框颜色
'''黑白风格
jindu_bt_color="#2b4490"#进度表标题颜色
jindu_bg_color="#3e4145"#进度表表格 背景颜色
jindu_wz_color="#fffffb"#进度表表格 文字颜色
jindu_bk_color="#d3d7d4"#进度表表格 边框颜色
'''
def get_db_path():
if not (os.path.isfile(os.path.abspath(os.path.join(os.path.dirname(__file__), "../"
"yobot/yobot/src/client/yobot_data/yobotdata.db"))) or os.access(os.path.abspath(os.path.join(os.path.dirname(__file__), "../"
"yobot/yobot/src/client/yobot_data/yobotdata.db")), os.R_OK)):
return None
db_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"
"yobot/yobot/src/client/yobot_data/yobotdata.db"))
return db_path
def get_web_address():
if not os.path.isfile(os.path.abspath(os.path.join(os.path.dirname(__file__), "../"
"yobot/yobot/src/client/yobot_data/yobot_config.json"))):
return None
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"
"yobot/yobot/src/client/yobot_data/yobot_config.json"))
with open(f'{config_path}', 'r', encoding='utf8')as fp:
yobot_config = json.load(fp)
website_suffix = str(yobot_config["public_basepath"])
port = str(hoshino.config.PORT)
web_address = "http://127.0.0.1" + ":" + port + website_suffix
return web_address
yobot_url = get_web_address()
if not yobot_url:
yobot_url = '' #如果非hoshino插件版请填写yobot_config上的链接
# 获取主页地址:在群内向bot发送指令“手册”,复制bot发送的链接地址,删除末尾的manual/后即为主页地址
# 例:https://域名/目录/或http://IP地址:端口号/目录/,注意不要漏掉最后的斜杠!
DB_PATH = get_db_path()
if not DB_PATH:
DB_PATH = ''
# 例:C:/Hoshino/hoshino/modules/yobot/yobot/src/client/yobot_data/yobotdata.db
# 注意斜杠方向!!!
#
Version = '0.8.2'
# 检查客户端版本
async def get_user_card(bot, group_id, user_id):
mlist = await bot.get_group_member_list(group_id=group_id)
for m in mlist:
if m['user_id'] == user_id:
return m['card'] if m['card']!='' else m['nickname']
return str(user_id)
def get_apikey(gid:str) -> str:
# 获取apikey
conn = sqlite3.connect(DB_PATH)
cur = conn.cursor()
cur.execute(f'select apikey from clan_group where group_id={gid}')
apikey = cur.fetchall()[0][0]
cur.close()
conn.close()
return apikey
class RecordDAO:
def __init__(self, db_path):
self.db_path = db_path
os.makedirs(os.path.dirname(db_path), exist_ok=True)
self._create_table()
def connect(self):
return sqlite3.connect(self.db_path)
def _create_table(self):
with self.connect() as conn:
conn.execute(
"CREATE TABLE IF NOT EXISTS limiter"
"(key TEXT NOT NULL, num INT NOT NULL, date INT, PRIMARY KEY(key))"
)
def exist_check(self, key):
try:
key = str(key)
with self.connect() as conn:
conn.execute("INSERT INTO limiter (key,num,date) VALUES (?, 0,-1)", (key,), )
return
except:
return
def get_num(self, key):
self.exist_check(key)
key = str(key)
with self.connect() as conn:
r = conn.execute(
"SELECT num FROM limiter WHERE key=? ", (key,)
).fetchall()
r2 = r[0]
return r2[0]
def clear_key(self, key):
key = str(key)
self.exist_check(key)
with self.connect() as conn:
conn.execute("UPDATE limiter SET num=0 WHERE key=?", (key,), )
return
def increment_key(self, key, num):
self.exist_check(key)
key = str(key)
with self.connect() as conn:
conn.execute("UPDATE limiter SET num=num+? WHERE key=?", (num, key,))
return
def get_date(self, key):
self.exist_check(key)
key = str(key)
with self.connect() as conn:
r = conn.execute(
"SELECT date FROM limiter WHERE key=? ", (key,)
).fetchall()
r2 = r[0]
return r2[0]
def set_date(self, date, key):
self.exist_check(key)
key = str(key)
with self.connect() as conn:
conn.execute("UPDATE limiter SET date=? WHERE key=?", (date, key,), )
return
db = RecordDAO(DAIDAO_DB_PATH)
class DAICounter:
def __init__(self):
os.makedirs(os.path.dirname(DAIDAO_DB_PATH), exist_ok=True)
self._create_Beidai()
self._create_BCD()
self._create_ZZ()
self._create_GS()
self._create_SHB()
def _connect(self):
return sqlite3.connect(DAIDAO_DB_PATH)
#被代刀部分
def _create_Beidai(self):
try:
self._connect().execute('''CREATE TABLE IF NOT EXISTS BEIDAI
(GID INT NOT NULL,
UID INT NOT NULL,
ID INT NOT NULL,
ZHOU INT NOT NULL,
HAO INT NOT NULL,
PRIMARY KEY(GID, UID));''')
except:
raise Exception('创建被代刀表发生错误')
def _get_Daidao_owner(self, gid, uid):
try:
r = self._connect().execute("SELECT ID FROM BEIDAI WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找代刀归属发生错误')
def _get_Daidao_ZHOU(self, gid, uid):
try:
r = self._connect().execute("SELECT ZHOU FROM BEIDAI WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找代刀归属发生错误')
def _get_Daidao_HAO(self, gid, uid):
try:
r = self._connect().execute("SELECT HAO FROM BEIDAI WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找代刀归属发生错误')
def _set_DAIDAO_owner(self, gid, id, uid,zhou, hao):
with self._connect() as conn:
conn.execute(
"INSERT OR REPLACE INTO BEIDAI (GID, ID, UID, ZHOU, HAO) VALUES (?, ?, ?, ?, ?)",
(gid, id, uid, zhou, hao),
)
def _delete_DAIDAO_owner(self, gid, uid):
with self._connect() as conn:
conn.execute(
"DELETE FROM BEIDAI WHERE GID=? AND UID=?",
(gid, uid),
)
#补偿刀部分
def _create_BCD(self):
try:
self._connect().execute('''CREATE TABLE IF NOT EXISTS BCD
(GID INT NOT NULL,
UID INT NOT NULL,
DATA NTEXT NOT NULL,
PRIMARY KEY(GID, UID));''')
except:
raise Exception('创建补偿刀表发生错误')
def _get_Weidao_owner(self, gid, uid):
try:
r = self._connect().execute("SELECT NUM FROM BCD WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找代刀归属发生错误')
def _set_BC_owner(self, gid, uid, data):
with self._connect() as conn:
conn.execute(
"INSERT OR REPLACE INTO BCD (GID, UID, DATA) VALUES (?, ?, ?)",
(gid, uid, data),
)
def _get_BC(self, gid, uid):
try:
r = self._connect().execute("SELECT DATA FROM BCD WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找助战归属发生错误')
#移除补偿刀
def _delete_BC(self, gid, uid):
with self._connect() as conn:
conn.execute(
"DELETE FROM BCD WHERE GID=? AND UID=?",
(gid, uid),
)
def _get_uid_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM BEIDAI WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
def _get_BC_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM BCD WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
#助战部分
def _create_ZZ(self):
try:
self._connect().execute('''CREATE TABLE IF NOT EXISTS ZZ
(GID INT NOT NULL,
UID INT NOT NULL,
ZZ NTEXT NOT NULL,
NUM INT NOT NULL,
PRIMARY KEY(GID, UID));''')
except:
raise Exception('创建锁助战表发生错误')
def _get_ZZ_Suo(self, gid, uid):
try:
r = self._connect().execute("SELECT ZZ FROM ZZ WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找助战归属发生错误')
def _get_ZZ_Suo_list(self, gid, uid):
try:
r = self._connect().execute("SELECT ZZ FROM ZZ WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找助战归属发生错误')
def _set_ZZ_owner(self, gid, uid, ZZ, num=1):
with self._connect() as conn:
conn.execute(
"INSERT OR REPLACE INTO ZZ (GID, UID, ZZ, NUM) VALUES (?, ?, ?,?)",
(gid, uid, ZZ, num),
)
def _delete_ZZ_Suo(self, gid, uid):
with self._connect() as conn:
conn.execute(
"DELETE FROM ZZ WHERE GID=? AND UID=?",
(gid, uid),
)
#挂树部分
def _create_GS(self):
try:
self._connect().execute('''CREATE TABLE IF NOT EXISTS GS
(GID INT NOT NULL,
UID INT NOT NULL,
HOUR NTEXT NOT NULL,
MIN INT NOT NULL,
ID INT NOT NULL,
LY NTEXT NOT NULL,
PRIMARY KEY(GID, UID));''')
except:
raise Exception('创建挂树表发生错误')
def _get_GS_Hour(self, gid, uid):
try:
r = self._connect().execute("SELECT HOUR FROM GS WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树时间发生错误')
def _get_GS_MIN(self, gid, uid):
try:
r = self._connect().execute("SELECT MIN FROM GS WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树时间发生错误')
def _get_GS_id(self, gid, uid):
try:
r = self._connect().execute("SELECT ID FROM GS WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树归属发生错误')
def _get_GS_ly(self, gid, uid):
try:
r = self._connect().execute("SELECT LY FROM GS WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树归属发生错误')
def _set_GS_owner(self, gid, uid, Hour, Min, id ,ly):
with self._connect() as conn:
conn.execute(
"INSERT OR REPLACE INTO GS (GID, UID, HOUR, MIN ,ID,LY) VALUES (?, ?, ?, ?, ?, ?)",
(gid, uid, Hour, Min, id,ly),
)
def _delete_GS(self, gid, uid):
with self._connect() as conn:
conn.execute(
"DELETE FROM GS WHERE GID=? AND UID=?",
(gid, uid),
)
#暂停伤害部分
def _create_SHB(self):
try:
self._connect().execute('''CREATE TABLE IF NOT EXISTS SHB
(GID INT NOT NULL,
UID INT NOT NULL,
ID INT NOT NULL,
SH NTEXT NOT NULL,
PRIMARY KEY(GID, UID));''')
except:
raise Exception('创建挂树表发生错误')
def _get_SHB_SH(self, gid, uid):
try:
r = self._connect().execute("SELECT SH FROM SHB WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树时间发生错误')
def _get_SHB_ID(self, gid, uid):
try:
r = self._connect().execute("SELECT ID FROM SHB WHERE GID=? AND UID=?", (gid, uid)).fetchone()
return 0 if r is None else r[0]
except:
raise Exception('查找挂树时间发生错误')
def _set_SH_owner(self, gid, uid, id, sh):
with self._connect() as conn:
conn.execute(
"INSERT OR REPLACE INTO SHB (GID, UID, ID, SH) VALUES (?, ?, ?, ?)",
(gid, uid, id, sh),
)
def _delete_SH(self, gid, uid):
with self._connect() as conn:
conn.execute(
"DELETE FROM SHB WHERE GID=? AND UID=?",
(gid, uid),
)
#获取列表部分
def _get_SH_uid_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM SHB WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
def _get_GS_uid_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM GS WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
def _get_DD_uid_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM BEIDAI WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
def _get_ZZ_uid_list(self, gid):
try:
r = self._connect().execute("SELECT DISTINCT(UID) FROM ZZ WHERE GID=? ", (gid,)).fetchall()
return [u[0] for u in r] if r else {}
except:
raise Exception('查找uid表发生错误')
@sv.on_rex(r'^(代刀中?|开始代刀) ?$')
async def kakin(bot, ev: CQEvent):
dai = DAICounter()
gid = ev.group_id
count = 0
fail = 0
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
owner = dai._get_Daidao_owner(gid,uid)
if owner ==0:
daoz= await get_daoz(gid)
Zhou = daoz[0]
Hao = daoz[1]
HP = daoz[2]
if HP == 0:
Hao += 1
if Hao == 6:
Hao = 1
Zhou +=1
dai._set_DAIDAO_owner(gid,ev.user_id,uid,Zhou,Hao)
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid),group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})正在为您代刀,请勿登录!本次代刀发起是在{Zhou}周目{Hao}号BOSS!')
else:
await bot.send_private_msg(user_id=int(uid), message=f'您好~代刀手{user_card}({ev.user_id})正在为您代刀,请勿登录!本次代刀发起是在{Zhou}周目{Hao}号BOSS!')
count += 1
except:
await bot.send(ev, '发送私聊代刀消息时发生错误,该用户可能没有私聊过机器人(但代刀正常记录,若机器人是管理员,则消息已正常发出)')
fail += 1
else:
sv.logger.info('已记录代刀')
else:
zhou = dai._get_Daidao_ZHOU(gid,uid)
hao = dai._get_Daidao_HAO(gid,uid)
user_card = await get_user_card(bot, ev.group_id, owner)
user_card2 = await get_user_card(bot, ev.group_id, uid)
await bot.send(ev, f'{user_card2}在{zhou}周目{hao}号BOSS由{user_card}发起了代刀,无法重复代刀')
if count and not NOprivate or gid in yesprivate:
if fail:
await bot.send(ev, f"{user_card}开始代刀!已私聊通知{count}位用户!{fail}位用户通知失败!")
else:
await bot.send(ev, f"{user_card}开始代刀!已私聊通知{count}位用户!")
if NOprivate:
await bot.send(ev, f"{user_card}开始代刀!")
@sv.on_rex(r'^报刀 ?\d+ ?$')
async def baodao(bot, ev: CQEvent):
dai = DAICounter()
gid = ev.group_id
num = 0
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
dai._delete_DAIDAO_owner(gid,uid)
dai._delete_ZZ_Suo(gid,uid)
dai._delete_GS(gid,uid)
dai._delete_SH(gid,uid)
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
num += 1
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid),group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})已经为您代刀完毕!')
else:
await bot.send_private_msg(user_id=int(uid),message=f'您好~代刀手{user_card}({ev.user_id})已经为您代刀完毕!')
await bot.send(ev, f"{user_card}代刀结束!已私聊通知该用户!")
except:
await bot.send(ev, '发送私聊代刀消息时发生错误,该用户可能没有私聊过机器人(但代刀正常记录,若机器人是管理员,则消息已正常发出)')
else:
await bot.send(ev, f"{user_card}代刀结束!")
if num == 0:
uid = ev.user_id
dai._delete_DAIDAO_owner(gid,uid)
dai._delete_GS(gid,uid)
dai._delete_SH(gid,uid)
dai._delete_ZZ_Suo(gid,uid)
@sv.on_rex(r'^查询代刀 ?$')
async def search_kakin(bot, ev: CQEvent):
dai = DAICounter()
gid = ev.group_id
num = 0
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
owner = dai._get_Daidao_owner(gid,uid)
if owner == 0:
user_card = await get_user_card(bot, ev.group_id, uid)
await bot.send(ev, f"{user_card}的账号未在代刀状态!您可确认后登录!")
else:
zhou = dai._get_Daidao_ZHOU(gid,uid)
hao = dai._get_Daidao_HAO(gid,uid)
user_card = await get_user_card(bot, ev.group_id, owner)
user_card2 = await get_user_card(bot, ev.group_id, uid)
await bot.send(ev, f'{user_card2}在{zhou}周目{hao}号BOSS由{user_card}发起了代刀,请小心顶号!')
num += 1
if num == 0:
uid = ev.user_id
user_card = await get_user_card(bot, ev.group_id, uid)
owner = dai._get_Daidao_owner(gid,uid)
if owner == 0:
user_card = await get_user_card(bot, ev.group_id, uid)
await bot.finish(ev, f"您的账号未在代刀状态!您可确认后登录!")
else:
zhou = dai._get_Daidao_ZHOU(gid,uid)
hao = dai._get_Daidao_HAO(gid,uid)
user_card = await get_user_card(bot, ev.group_id, owner)
user_card2 = await get_user_card(bot, ev.group_id, uid)
await bot.send(ev, f'您的账号在{zhou}周目{hao}号BOSS由{user_card}发起了代刀,请小心顶号!')
@sv.on_rex(r'^尾刀$')
async def weidao(bot, ev: CQEvent):
dai = DAICounter()
gid = ev.group_id
daoz= await get_daoz(gid)
Zhou = daoz[0]
Hao = daoz[1]
num = 0
#kill = 0
umlist = dai._get_SH_uid_list(gid)
if umlist !=0:
msgSH = "暂停的下来吧:\n"
for s in range(len(umlist)):
uid = int(umlist[s])
dai._delete_SH(gid,uid)
msgSH += f"[CQ:at,qq={uid}]"
if msgSH != "暂停的下来吧:\n":
await bot.send(ev, msgSH)
umlist = dai._get_GS_uid_list(gid)
if umlist !=0:
msgGS = "挂树的下来吧:\n"
for s in range(len(umlist)):
uid = int(umlist[s])
dai._delete_GS(gid,uid)
msgGS += f"[CQ:at,qq={uid}]"
if msgGS != "挂树的下来吧:\n":
await bot.send(ev, msgGS)
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
dai._delete_DAIDAO_owner(gid,uid)
dai._delete_ZZ_Suo(gid,uid)
uid = int(m.data['qq'])
data = str(f'在{Zhou}周目{Hao}号BOSS收尾,代刀手为{user_card}')
dai._set_BC_owner(gid,uid,data)
num += 1
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid), group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})已经为您代刀完毕!(您是尾刀,请关注群消息)')
else:
await bot.send_private_msg(user_id=int(uid), message=f'您好~代刀手{user_card}({ev.user_id})已经为您代刀完毕!(您是尾刀,请关注群消息)')
await bot.send(ev, f"{user_card}代刀结束!已私聊通知该用户!补偿刀信息已录入,请及时更新!")
except:
await bot.send(ev, '发送私聊代刀消息时发生错误,该用户可能没有私聊过机器人(但代刀正常记录,若机器人是管理员,则消息已正常发出)')
else:
await bot.send(ev, f"{user_card}代刀结束!补偿刀信息已录入,请及时更新!")
if num == 0:
uid = ev.user_id
dai._delete_DAIDAO_owner(gid,uid)
data = str(f'在{Zhou}周目{Hao}号BOSS收尾')
dai._set_BC_owner(gid,uid,data)
@sv.on_rex(r'^(?:SL|sl) *([\??])?')
async def SLL(bot, ev: CQEvent):
match = ev['match']
gid = ev.group_id
if bool(match.group(1)):
return
count = 0
dai = DAICounter()
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
if dai._get_GS_id(gid,uid) !=0:
dai._delete_GS(gid,uid)
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid),group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})使用了您的SL!请关注群消息!')
else:
await bot.send_private_msg(user_id=int(uid), message=f'您好~代刀手{user_card}({ev.user_id})使用了您的SL!请关注群消息!')
except:
await bot.send(ev, '发送私聊代刀消息时发生错误,该用户可能没有私聊过机器人(但代刀正常记录,若机器人是管理员,则消息已正常发出)')
count += 1
if count:
await bot.send(ev, f"{user_card}在代刀中使用了SL!已通知{count}位用户!")
if NOprivate:
await bot.send(ev, f"{user_card}在代刀中使用了SL!")
@sv.on_rex(r'^挂树 ?$|^挂树[::](.*)') #这个地方match.group(1)提取留言
async def guashu(bot, ev: CQEvent):
count = 0
now = datetime.now(pytz.timezone('Asia/Shanghai'))
Hour = now.hour
Min = now.minute
dai = DAICounter()
gid = ev.group_id
id = ev.user_id
match = ev['match']
ly = match.group(1)
if ly == None:
ly = '无'
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
dai._set_GS_owner(gid,uid,Hour,Min,id,ly)
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid),group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})在您的账号上代刀时挂树!请暂时不要登陆并关注群消息!')
else:
await bot.send_private_msg(user_id=int(uid), message=f'您好~代刀手{user_card}({ev.user_id})在您的账号上代刀时挂树!请暂时不要登陆并关注群消息!')
except:
await bot.send(ev, '发送私聊代刀消息时发生错误,该用户可能没有私聊过机器人(但代刀正常记录,若机器人是管理员,则消息已正常发出)')
count += 1
if count:
if not NOprivate or gid in yesprivate:
await bot.send(ev, f"{user_card}在代刀中挂树!已通知{count}位用户!")
else:
await bot.send(ev, f"{user_card}在代刀中挂树!")
else:
uid = ev.user_id
dai._set_GS_owner(gid,uid,Hour,Min,id,ly)
await bot.send(ev, '已记录挂树')
@sv.on_rex(r'^取消挂树 ?$')
async def guashu_del(bot, ev: CQEvent):
count = 0
#id = ev.user_id
dai = DAICounter()
gid = ev.group_id
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
user_card2 = await get_user_card(bot, ev.group_id, uid)
if dai._get_GS_id(gid,uid) !=0:
dai._delete_GS(gid,uid)
await bot.send(ev, f'{user_card}已取消{user_card2}的挂树状态!')
else:
await bot.send(ev, f'{user_card}没有挂树!')
count += 1
if count:
return
else:
uid = ev.user_id
if dai._get_GS_id(gid,uid) !=0:
dai._delete_GS(gid,uid)
await bot.send(ev, f'已取消挂树状态!')
else:
await bot.send(ev, f'您没有挂树!')
@sv.on_rex(r'^(:?取消|结束)代刀 ?$')
async def quxiao(bot, ev: CQEvent):
dai = DAICounter()
gid = ev.group_id
user_card = await get_user_card(bot, ev.group_id, ev.user_id)
for m in ev.message:
if m.type == 'at' and m.data['qq'] != 'all':
uid = int(m.data['qq'])
owner = dai._get_Daidao_owner(gid,uid)
if owner !=0:
dai._delete_DAIDAO_owner(gid,uid)
user_card2 = await get_user_card(bot, ev.group_id, uid)
if not NOprivate or gid in yesprivate:
try:
if GroupID_ON == True:
await bot.send_private_msg(user_id=int(uid),group_id=int(gid),message=f'您好~代刀手{user_card}({ev.user_id})取消了代刀!')
else:
await bot.send_private_msg(user_id=int(uid), message=f'您好~代刀手{user_card}({ev.user_id})取消了代刀!')
await bot.send(ev, f"{user_card}取消了为{user_card2}的代刀!已私聊通知该用户!")
except:
await bot.finish(ev, f'发送私聊取消代刀消息时发生错误,{user_card2}可能没有私聊过机器人(但取消代刀正常记录)')
else:
await bot.send(ev, f"{user_card}取消了为{user_card2}的代刀!")
else:
await bot.finish(ev, f'{user_card2}未在代刀状态!')
@sv.on_rex(f'^暂停(:|:)(.*)$')
async def zt(bot, ev: CQEvent):
gid = ev.group_id
id = ev.user_id
dai = DAICounter()
match = ev['match']
try:
uid = int(ev.message[1].data['qq'])
except:
uid = ev.user_id
user_card = await get_user_card(bot, ev.group_id, uid)
num = str(match.group(2))
if dai._get_SHB_SH(gid,uid) != 0:
dai._set_SH_owner(gid,uid,id,num)
await bot.finish(ev, f'您的暂停伤害已更新为{num}!')
else:
dai._set_SH_owner(gid,uid,id,num)
await bot.finish(ev, f'已记录{user_card}的伤害为{num}!')
@sv.on_rex(f'^记录补偿刀(:|:)(.*)$')
async def jl(bot, ev: CQEvent):
gid = ev.group_id
#id = ev.user_id
dai = DAICounter()
match = ev['match']
try:
uid = int(ev.message[1].data['qq'])
except:
uid = ev.user_id
user_card = await get_user_card(bot, ev.group_id, uid)
num = str(match.group(2))
dai._set_BC_owner(gid,uid,num)
await bot.finish(ev, f'已记录{user_card}补偿刀{num}!')
async def get_user_card_dict(bot, group_id):
mlist = await bot.get_group_member_list(group_id=group_id)
d = {}
for m in mlist:
d[m['user_id']] = m['card'] if m['card']!='' else m['nickname']
return d
async def get_gid_dict(bot, group_id):
mlist = await bot.get_group_list()
d = {}
for m in mlist:
d[m['group_id']] = m['group_id']
return d
@sv.on_fullmatch('详细状态')
async def XXZT(bot, ev: CQEvent):
user_card_dict = await get_user_card_dict(bot, ev.group_id)
score_dict = {}
dai = DAICounter()
gid = ev.group_id
now = datetime.now(pytz.timezone('Asia/Shanghai'))
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_Daidao_owner(gid,uid)
if owner !=0:
Zhou = dai._get_Daidao_ZHOU(gid,uid)
Hao = dai._get_Daidao_HAO(gid,uid)
user = await get_user_card(bot, ev.group_id, owner)
score_dict[user_card_dict[uid]] = [Zhou,Hao,user]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg1 = '当前正在被代刀的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
msg1 += f'{i+1}. {group_ranking[i][0]} 在{group_ranking[i][1][0]}周目{group_ranking[i][1][1]}号BOSS被{group_ranking[i][1][2]}发起代刀\n'
if msg1 == '当前正在被代刀的有:\n':
msg1 = '当前没有人正在被代刀\n'
score_dict = {}
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_SHB_SH(gid,uid)
if owner !=0:
SH = dai._get_SHB_SH(gid,uid)
id = dai._get_SHB_ID(gid,uid)
user = await get_user_card(bot, ev.group_id, id)
score_dict[user_card_dict[uid]] = [SH,user]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg3 = '当前暂停的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
if group_ranking[i][0] != group_ranking[i][1][1]:
msg3 += f'{i+1}. {group_ranking[i][0]} 伤害:{group_ranking[i][1][0]} 刀手:{group_ranking[i][1][1]}\n'
else:
msg3 += f'{i+1}. {group_ranking[i][0]} 伤害:{group_ranking[i][1][0]}\n'
if msg3 == '当前暂停的有:\n':
msg3 = '当前没有人成刀暂停\n'
score_dict = {}
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_GS_id(gid,uid)
if owner !=0:
Hour = dai._get_GS_Hour(gid,uid)
Min = dai._get_GS_MIN(gid,uid)
id = dai._get_GS_id(gid,uid)
ly = dai._get_GS_ly(gid,uid)
user = await get_user_card(bot, ev.group_id, id)
score_dict[user_card_dict[uid]] = [Hour,Min,user,ly]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg4 = '当前挂树的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
if group_ranking[i][1][2] != group_ranking[i][0]:
msg4 += f'{i+1}. {group_ranking[i][0]} 挂树开始时间:{group_ranking[i][1][0]} 时{group_ranking[i][1][1]} 分 刀手:{group_ranking[i][1][2]},留言:{group_ranking[i][1][3]},已挂树{60*(now.hour-int(group_ranking[i][1][0]))+now.minute-int(group_ranking[i][1][1])}分钟\n'
else:
msg4 += f'{i+1}. {group_ranking[i][0]} 挂树开始时间:{group_ranking[i][1][0]} 时{group_ranking[i][1][1]} 分,留言:{group_ranking[i][1][3]},已挂树{60*(now.hour-int(group_ranking[i][1][0]))+now.minute-int(group_ranking[i][1][1])}分钟\n'
if msg4 == '当前挂树的有:\n':
msg4 = '当前没有人挂树\n'
msg = msg1+msg3+msg4
await bot.send(ev, msg.strip())
@sv.on_fullmatch('查树')
async def CHASHU(bot, ev: CQEvent):
now = datetime.now(pytz.timezone('Asia/Shanghai'))
user_card_dict = await get_user_card_dict(bot, ev.group_id)
score_dict = {}
dai = DAICounter()
gid = ev.group_id
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_GS_id(gid,uid)
if owner !=0:
Hour = dai._get_GS_Hour(gid,uid)
Min = dai._get_GS_MIN(gid,uid)
id = dai._get_GS_id(gid,uid)
ly = dai._get_GS_ly(gid,uid)
user = await get_user_card(bot, ev.group_id, id)
score_dict[user_card_dict[uid]] = [Hour,Min,user,ly]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg = '当前挂树的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
if group_ranking[i][1][2] != group_ranking[i][0]:
msg += f'{i+1}. {group_ranking[i][0]} 挂树开始时间:{group_ranking[i][1][0]} 时{group_ranking[i][1][1]} 分 刀手:{group_ranking[i][1][2]},留言:{group_ranking[i][1][3]},已挂树{60*(now.hour-int(group_ranking[i][1][0]))+now.minute-int(group_ranking[i][1][1])}分钟\n'
else:
msg += f'{i+1}. {group_ranking[i][0]} 挂树开始时间:{group_ranking[i][1][0]} 时{group_ranking[i][1][1]} 分,留言:{group_ranking[i][1][3]},已挂树{60*(now.hour-int(group_ranking[i][1][0]))+now.minute-int(group_ranking[i][1][1])}分钟\n'
if msg == '当前挂树的有:\n':
msg = '当前没有人挂树\n'
await bot.send(ev, msg.strip())
@sv.on_fullmatch('代刀列表')
async def DDB(bot, ev: CQEvent):
user_card_dict = await get_user_card_dict(bot, ev.group_id)
score_dict = {}
dai = DAICounter()
gid = ev.group_id
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_Daidao_owner(gid,uid)
if owner !=0:
Zhou = dai._get_Daidao_ZHOU(gid,uid)
Hao = dai._get_Daidao_HAO(gid,uid)
user = await get_user_card(bot, ev.group_id, owner)
score_dict[user_card_dict[uid]] = [Zhou,Hao,user]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg = '当前正在被代刀的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
msg += f'{i+1}. {group_ranking[i][0]} 在{group_ranking[i][1][0]}周目{group_ranking[i][1][1]}号BOSS被{group_ranking[i][1][2]}发起代刀\n'
if msg == '当前正在被代刀的有:\n':
msg = '当前没有人正在被代刀'
await bot.send(ev, msg.strip())
@sv.on_fullmatch('暂停列表')
async def ZZB(bot, ev: CQEvent):
user_card_dict = await get_user_card_dict(bot, ev.group_id)
score_dict = {}
dai = DAICounter()
gid = ev.group_id
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_SHB_SH(gid,uid)
if owner !=0:
SH = dai._get_SHB_SH(gid,uid)
id = dai._get_SHB_ID(gid,uid)
user = await get_user_card(bot, ev.group_id, id)
score_dict[user_card_dict[uid]] = [SH,user]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg = '当前暂停的有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
if group_ranking[i][0] != group_ranking[i][1][1]:
msg += f'{i+1}. {group_ranking[i][0]} 伤害:{group_ranking[i][1][0]} 刀手:{group_ranking[i][1][1]}\n'
else:
msg += f'{i+1}. {group_ranking[i][0]} 伤害:{group_ranking[i][1][0]}\n'
if msg == '当前暂停的有:\n':
msg = '当前没有人成刀暂停\n'
await bot.send(ev, msg.strip())
@sv.on_fullmatch('补偿刀列表')
async def BCB(bot, ev: CQEvent):
user_card_dict = await get_user_card_dict(bot, ev.group_id)
score_dict = {}
dai = DAICounter()
gid = ev.group_id
for uid in user_card_dict.keys():
if uid != ev.self_id:
owner = dai._get_BC(gid,uid)
if owner !=0:
score_dict[user_card_dict[uid]] = [1,owner]
else:
continue
group_ranking = sorted(score_dict.items(),key = lambda x:x[1],reverse = True)
msg = '当前记录的补偿刀有:\n'
for i in range(len(group_ranking)):
if group_ranking[i][1] != 0:
msg += f'{i+1}. {group_ranking[i][0]} 记录了:{group_ranking[i][1][1]}\n'
if msg == '当前记录的补偿刀有:\n':
msg = '当前没有记录的补偿刀'
await bot.send(ev, msg.strip())
@sv.on_fullmatch('清空代刀数据')
async def Reset(bot, ev: CQEvent):
if not priv.check_priv(ev, priv.ADMIN):
await bot.finish(ev, '无权进行该操作!', at_sender=True)
gid = ev.group_id
dai = DAICounter()
umlist = dai._get_uid_list(gid)
for s in range(len(umlist)):
uid = int(umlist[s])
dai._delete_DAIDAO_owner(gid,uid)
await bot.finish(ev, '已清空正在代刀的数据!')
@sv.on_fullmatch('清空补偿数据')
async def reset(bot, ev: CQEvent):
if not priv.check_priv(ev, priv.ADMIN):
await bot.finish(ev, '无权进行该操作!', at_sender=True)
gid = ev.group_id
dai = DAICounter()
umlist = dai._get_BC_list(gid)
for s in range(len(umlist)):
uid = int(umlist[s])
dai._delete_BC(gid,uid)
await bot.finish(ev, '已清空目前记录的补偿刀数据!')
@sv.scheduled_job('cron', hour ='*',)
async def clock():
now = datetime.now(pytz.timezone('Asia/Shanghai'))
if now.hour !=5 and now.hour !=4:
return
dai = DAICounter()
bot = nonebot.get_bot()
mlist = await bot.get_group_list()
d = {}
for m in mlist:
d[m['group_id']] = m['group_id']