forked from BeiYazi0/draw-card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_card.py
81 lines (69 loc) · 2.04 KB
/
draw_card.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
import sqlite3
import os
import random
import re
_dir = os.path.dirname(__file__)
conn = os.path.join(_dir,"cards.db")
def get_card(idx: str):
db = sqlite3.connect(conn)
xka = db.cursor()
if idx == "-1":
xka.execute("SELECT * FROM cardinfo")
result = xka.fetchall()
xka.close()
res = random.choice(result)
idx = res[0]
url = res[1]
content = f"你抽到了 [CQ:image,file={url}]\n--------------\n 卡号:{idx}"
else:
xka.execute('''SELECT * FROM cardinfo WHERE idx = ("%s")''' % idx)
result = xka.fetchone()
xka.close()
if result == None:
db.close()
return None,idx
url = result[1]
qq = result[2]
content = f"卡号:{idx}\n上传者:{qq} [CQ:image,file={url}]"
db.close()
return content,idx
def card_increase(imgs: str, qq: str):
cnt = 0
image_url = re.search(r"\[CQ:image,file=(.*?)url=(.*?)\]", imgs)
db = sqlite3.connect(conn)
while image_url != None:
cnt += 1
url = image_url.group(2)
sql = '''INSERT INTO cardinfo (url,qq) VALUES ("%s","%s")''' % (url,qq)
db.execute(sql)
db.commit()
imgs = imgs.replace(image_url.group(), "")
image_url = re.search(r"\[CQ:image,file=(.*?)url=(.*?)\]", imgs)
db.close()
return cnt
def card_decrease(idx: str):
db = sqlite3.connect(conn)
xka = db.cursor()
xka.execute('''SELECT * FROM cardinfo WHERE idx = ("%s")''' % idx)
result = xka.fetchone()
if result == None:
return None
qq = result[2]
xka.execute('''DELETE FROM cardinfo WHERE idx = ("%s")''' % idx)
db.commit()
xka.close()
db.close()
return qq
def qq_decrease(qq: str):
db = sqlite3.connect(conn)
sql = '''DELETE FROM cardinfo WHERE qq = ("%s")''' % qq
db.execute(sql)
db.commit()
db.close()
def total():
db = sqlite3.connect(conn)
c = db.execute("SELECT COUNT(idx) FROM cardinfo")
stock = c.fetchall()
c.close()
db.close()
return stock[0][0]