-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
74 lines (51 loc) · 1.95 KB
/
database.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
import sqlite3
def initdatabase():
connection = sqlite3.connect('members.db')
cursor = connection.cursor()
command1 = """CREATE TABLE IF NOT EXISTS
activity(memberID INTEGER PRIMARY KEY, msg_count INTEGER, Voice_activity INTEGER)"""
cursor.execute(command1)
def addmessage(id):
connection = sqlite3.connect('members.db')
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM 'activity' WHERE memberID = {id}")
check = cursor.fetchone()
if(check == None):
cursor.execute(f"INSERT OR IGNORE INTO activity VALUES ({id},1,0)")
else:
cursor.execute(f"UPDATE activity SET msg_count = msg_count + 1 WHERE memberID = {id}")
connection.commit()
def addvoice(id,count):
connection = sqlite3.connect('members.db')
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM 'activity' WHERE memberID = {id}")
check = cursor.fetchone()
if(check == None):
cursor.execute(f"INSERT OR IGNORE INTO activity VALUES ({id},0,{count})")
else:
cursor.execute(f"UPDATE activity SET Voice_activity = Voice_activity + {count} WHERE memberID = {id}")
connection.commit()
def getvoicecount(id):
connection = sqlite3.connect('members.db')
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM 'activity' WHERE memberID = {id}")
check = cursor.fetchone()
#print(check)
if(check != None):
cursor.execute(f"SELECT Voice_activity FROM 'activity' WHERE memberID = {id}")
count = cursor.fetchone()[0]
else:
return 0
return count
def getmsgcount(id):
connection = sqlite3.connect('members.db')
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM 'activity' WHERE memberID = {id}")
check = cursor.fetchone()
#print(check)
if(check != None):
cursor.execute(f"SELECT msg_count FROM 'activity' WHERE memberID = {id}")
count = cursor.fetchone()[0]
else:
return 0
return count