forked from BananoCoin/Banano-Discord-TipBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faucet_db.py
76 lines (65 loc) · 1.97 KB
/
faucet_db.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
import datetime
import util
from peewee import *
from playhouse.sqliteq import SqliteQueueDatabase
db = SqliteQueueDatabase('bananodiscord.db')
logger = util.get_logger("db")
### User Stuff
def add_new_request(user):
try:
fuser = FaucetUser.get(user_id == user.user_id)
fuser.last_request_1=fuser.last_request_2
fuser.last_request_2=fuser.last_request_3
fuser.last_request_3=fuser.last_request_4
fuser.last_request_4=datetime.datetime.now()
fuser.request_count = fuser.request_count + 1
fuser.save();
except FaucetUser.DoesNotExist:
create_fuser(user.user_id, user.user_name);
add_new_request(user);
return None
def get_first_request(user):
try:
fuser = FaucetUser.get(user_id == user.user_id)
return fuser.last_request_1
except FaucetUser.DoesNotExist:
create_fuser(user.user_id, user.user_name);
get_first_request(user);
return None
def get_last_request(user):
try:
fuser = FaucetUser.get(user_id == user.user_id)
return fuser.last_request_4
except FaucetUser.DoesNotExist:
create_fuser(user.user_id, user.user_name);
get_last_request(user);
return None
def create_fuser(user_id, user_name):
fuser = FaucetUser(user_id=user_id,
user_name=user_name,
last_request_1=datetime.datetime.fromtimestamp(1284286794),
last_request_2=datetime.datetime.fromtimestamp(1284286794),
last_request_3=datetime.datetime.fromtimestamp(1284286794),
last_request_4=datetime.datetime.fromtimestamp(1284286794),
request_count=0,
created=datetime.datetime.now(),
)
fuser.save()
return user
# User table
class FaucetUser(Model):
user_id = CharField(unique=True)
user_name = CharField()
last_request_1 = DateTimeField()
last_request_2 = DateTimeField()
last_request_3 = DateTimeField()
last_request_4 = DateTimeField()
request_count = IntegerField()
created = DateTimeField()
class Meta:
database = db
def create_db():
db.connect()
db.create_tables([FaucetUser], safe=True)
logger.debug("DB Connected")
create_db()