This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (43 loc) · 1.18 KB
/
utils.py
File metadata and controls
49 lines (43 loc) · 1.18 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
import shelve
import os
import logging
import shlex
logger = logging.getLogger("polybot")
dir_path = os.path.dirname(os.path.realpath(__file__))
# IO Helper functions
class InvalidFileIO(Exception):
pass
def getData(filename,key): # TODO: encrypt user data
with shelve.open(dir_path+"/data/"+filename) as db:
db.sync()
if key in db.keys():
return db[key]
else:
return None
def setData(filename,key,value):
with shelve.open(dir_path+"/data/"+filename,writeback=True) as db:
db[key]=value
db.sync()
def getUserData(ID,key):
with shelve.open(dir_path+"/data/users/"+ID+".user") as db:
db.sync()
if key in db.keys():
return db[key]
else:
return None
def setUserData(ID,key,value):
with shelve.open(dir_path+"/data/users/"+ID+".user",writeback=True) as db:
db[key]=value
db.sync()
# for splitting messages into tokens for easy parsing
def tokenize(message):
return shlex.split(message.content)
# matching helper funciton
def isMatch(s1,s2):
if type(s2) in (list,tuple):
return s1.lower() in [k.lower() for k in s2]
else:
return s1.lower() == s2.lower()
# helper for checking if it's Nullspeaker.
def isOwner(message):
return message.author.id=="152273482846175234"