Merge branch 'latest-version' of bitbucket.org:FluffyMeowl/stroopwafel into latest-version
This commit is contained in:
@@ -122,7 +122,7 @@ class Points(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
message = "**De puntentelling:** \n```"
|
message = "**De puntentelling:** \n```"
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
pointsCountSorted = sorted(pointsCount.items(), key=lambda i: i[1]['points'], reverse=True)
|
pointsCountSorted = sorted(pointsCount.items(), key=lambda i: i[1]['points'], reverse=True)
|
||||||
for user in pointsCountSorted:
|
for user in pointsCountSorted:
|
||||||
if user[0] != self.BANK_ID:
|
if user[0] != self.BANK_ID:
|
||||||
@@ -146,31 +146,31 @@ class Points(commands.Cog):
|
|||||||
|
|
||||||
# Transfer points form one user to another
|
# Transfer points form one user to another
|
||||||
def transferPoints(self, fromUserId, toUserId, points):
|
def transferPoints(self, fromUserId, toUserId, points):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
pointsCount[fromUserId]["points"] -= points
|
pointsCount[fromUserId]["points"] -= points
|
||||||
pointsCount[toUserId]["points"] += points
|
pointsCount[toUserId]["points"] += points
|
||||||
np.save("pointscount.npy", pointsCount)
|
np.save("pointscount.npy", pointsCount)
|
||||||
|
|
||||||
# Do we know this user?
|
# Do we know this user?
|
||||||
def isUserOnList(self, user):
|
def isUserOnList(self, user):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
return user.id in pointsCount.keys()
|
return user.id in pointsCount.keys()
|
||||||
|
|
||||||
# Get a user's point balance
|
# Get a user's point balance
|
||||||
def getUserBalance(self, user):
|
def getUserBalance(self, user):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
return pointsCount[user.id]["points"]
|
return pointsCount[user.id]["points"]
|
||||||
|
|
||||||
# Get the balance of the bank
|
# Get the balance of the bank
|
||||||
def getBankBalance(self):
|
def getBankBalance(self):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
return pointsCount[self.BANK_ID]["points"]
|
return pointsCount[self.BANK_ID]["points"]
|
||||||
|
|
||||||
# To keep track if a user used some points today, we look at when the last time was he/she used them
|
# To keep track if a user used some points today, we look at when the last time was he/she used them
|
||||||
# If this was in the past: reset
|
# If this was in the past: reset
|
||||||
# Also, return the updated object. Why not.
|
# Also, return the updated object. Why not.
|
||||||
def refreshDateVarsAndReturnUserVars(self, userId):
|
def refreshDateVarsAndReturnUserVars(self, userId):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
currentDateStr = datetime.now().strftime("%Y%m%d")
|
currentDateStr = datetime.now().strftime("%Y%m%d")
|
||||||
if pointsCount[userId]["theDate"] != currentDateStr:
|
if pointsCount[userId]["theDate"] != currentDateStr:
|
||||||
pointsCount[userId]["theDate"] = currentDateStr
|
pointsCount[userId]["theDate"] = currentDateStr
|
||||||
@@ -192,14 +192,14 @@ class Points(commands.Cog):
|
|||||||
# Increase the number of points this user has taken away today.
|
# Increase the number of points this user has taken away today.
|
||||||
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
|
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
|
||||||
def increaseUsersPointTakenOnDate(self, userId, points):
|
def increaseUsersPointTakenOnDate(self, userId, points):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
pointsCount[userId]["pointTakenOnDate"] += points
|
pointsCount[userId]["pointTakenOnDate"] += points
|
||||||
np.save("pointscount.npy", pointsCount)
|
np.save("pointscount.npy", pointsCount)
|
||||||
|
|
||||||
# Increase the number of bank points this user has given today
|
# Increase the number of bank points this user has given today
|
||||||
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
|
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
|
||||||
def increaseUsersBankPointGivenAwayToday(self, userId, points):
|
def increaseUsersBankPointGivenAwayToday(self, userId, points):
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
pointsCount[userId]["bankPointsGivenOnDate"] += points
|
pointsCount[userId]["bankPointsGivenOnDate"] += points
|
||||||
np.save("pointscount.npy", pointsCount)
|
np.save("pointscount.npy", pointsCount)
|
||||||
|
|
||||||
@@ -252,10 +252,10 @@ class Points(commands.Cog):
|
|||||||
def init(self):
|
def init(self):
|
||||||
# Check if points file exists:
|
# Check if points file exists:
|
||||||
try:
|
try:
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
np.save("pointscount.npy", {})
|
np.save("pointscount.npy", {})
|
||||||
pointsCount = np.load('pointscount.npy').item()
|
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
|
||||||
|
|
||||||
# Initialise the bank:
|
# Initialise the bank:
|
||||||
if self.BANK_ID not in pointsCount.keys():
|
if self.BANK_ID not in pointsCount.keys():
|
||||||
|
|||||||
Reference in New Issue
Block a user