-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
100 lines (82 loc) · 3.63 KB
/
db.py
File metadata and controls
100 lines (82 loc) · 3.63 KB
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
import sqlite3
from random import randint
def addUser(username): # добавить пользователя в базу данных. возвращает False, если уже занесен
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
cursor.execute("SELECT Points FROM ChattersPoints WHERE Name = :user", {"user": username})
if cursor.fetchone() is None:
cursor.execute("insert into ChattersPoints(Name, Points) values (:user, 0)", {"user": username})
connection.commit()
connection.close()
return True
else:
connection.close()
return False
def addPoint(username, points): # добавить очков усеру, возвращает False и добавляет усера в базу, если его там еще нет
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
cursor.execute("SELECT Points FROM ChattersPoints WHERE Name = :user", {"user": username})
a = cursor.fetchone()
if a == None:
addUser(username)
connection.close()
return False
else:
b = a[0] + int(points)
cursor.execute("UPDATE ChattersPoints SET Points = ? WHERE Name = ?", (b, username))
connection.commit()
connection.close()
return True
def takeawayPoint(username, points): # отнять очков усеру, возвращает False, если у усера нет столько очков, сколько указано
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
cursor.execute("SELECT Points FROM ChattersPoints WHERE Name = :user", {"user": username})
a = cursor.fetchone()
if a[0] < int(points):
connection.close()
return False
else:
b = a[0] - int(points)
cursor.execute("UPDATE ChattersPoints SET Points = ? WHERE Name = ?", (b, username))
connection.commit()
connection.close()
return True
def countPoint(username): # возвращает количество очков у усера
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
cursor.execute("SELECT Points FROM ChattersPoints WHERE Name = :user", {"user": username})
return cursor.fetchone()
def createMSize(username): # размер морковки. добавляет в базу и присваиваеет рандомное значение
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
cursor.execute("SELECT Size FROM MSize WHERE Name = :user", {"user": username})
size = cursor.fetchone()
if size is None:
rand = randint(1, 30)
cursor.execute("insert into MSize(Name, Size) values (?, ?)", (username, rand))
connection.commit()
connection.close()
return rand
else:
connection.close()
return size[0]
def setMSize(username, count): # меняет размер морковки
# username = username.lower
connection = sqlite3.connect('ChattersPoints.db')
cursor = connection.cursor()
if int(count) == 0:
rand = randint(1, 30)
cursor.execute("UPDATE MSize SET Size = ? WHERE Name = ?", (rand, username))
connection.commit()
connection.close()
return rand
else:
cursor.execute("UPDATE MSize SET Size = ? WHERE Name = ?", (int(count), username))
connection.commit()
connection.close()
return int(count)