-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_tools.py
100 lines (76 loc) · 2.5 KB
/
db_tools.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
'''
database functions to get/set from pickledb
'''
import pickledb
def init_db(): # remove keys from previous runs
db = pickledb.load('data.db', False)
if db.exists('last_trade'):
db.rem('last_trade')
if db.exists('last_signing'):
db.rem('last_signing')
db.dump() # save the db
def getLastTradeShown():
db = pickledb.load('data.db', False)
if db.exists('last_trade'):
return db.get('last_trade')
return None # if key doesn't exist, then it's the first time running the bot
def setLastTradeShown(data):
db = pickledb.load('data.db', False)
db.set('last_trade', data)
db.dump() # save the db
def getLastSigningShown():
db = pickledb.load('data.db', False)
if db.exists('last_signing'):
return db.get('last_signing')
return None # if key doesn't exist, then it's the first time running the bot
def setLastSigningShown(data):
db = pickledb.load('data.db', False)
db.set('last_signing', data)
db.dump() # save the db
# goalie stuff
def getLastDateSaved():
db = pickledb.load('data.db', False)
if db.exists('date'):
return db.get('date')
return None # if key doesn't exist, then it's the first time running the bot
def setLastDateSaved(data):
db = pickledb.load('data.db', False)
db.set('date', data)
db.dump() # save the db
def getLastGoalieData():
db = pickledb.load('data.db', False)
if db.exists('goalies'):
return db.get('goalies')
return None # if key doesn't exist, then it's the first time running the bot
def setLastGoalieData(data):
db = pickledb.load('data.db', False)
db.set('goalies', data)
db.dump() # save the db
def setRequests(data):
db = pickledb.load('data.db', False)
db.set('requests', data)
db.dump() # save the db
# channel stuff
def getChannels():
db = pickledb.load('data.db', False)
if db.exists('channels'):
return db.get('channels')
return []
def addChannel(channel_id):
db = pickledb.load('data.db', False)
channels = db.get('channels') or []
if channel_id not in channels:
channels.append(channel_id)
db.set('channels', channels)
db.dump() # save the db
return True
return False
def removeChannel(channel_id):
db = pickledb.load('data.db', False)
channels = db.get('channels') or []
if channel_id in channels:
channels.remove(channel_id)
db.set('channels', channels)
db.dump() # save the db
return True
return False