Allows pickled loading to fix points function

This commit is contained in:
Mark Hoekveen
2020-05-04 15:21:26 +02:00
parent 70392bed44
commit b79c9c70c2
2 changed files with 15 additions and 15 deletions
+4 -4
View File
@@ -17,7 +17,7 @@ class Chatbot(commands.Cog):
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
self.pmCount = 0
try:
np.load('markov_dict.npy')
np.load('markov_dict.npy', allow_pickle=True)
except FileNotFoundError:
#If there's no initial file, make a new one:
initFile = {'pairs':{self.START_OF_MESSAGE:{'Hoi':1},'Hoi':{self.END_OF_MESSAGE:1}}, 'trairs':{}, 'responsePairs':{}}
@@ -187,7 +187,7 @@ class Chatbot(commands.Cog):
channel=self.bot.get_channel(channelId)
#Open current chain:
wordDict = np.load('markov_dict.npy').item()
wordDict = np.load('markov_dict.npy', allow_pickle=True).item()
#Iterate through the last x messages from the channel:
messageIterator = channel.history(limit=nrOfMessages, before=None, after=None, reverse=False, around=None)
@@ -276,7 +276,7 @@ class Chatbot(commands.Cog):
MAX_N_WORDS = 100 #Don't use more words than this
#Get dictionary/Markov chain
wordDict = np.load('markov_dict.npy').item()
wordDict = np.load('markov_dict.npy', allow_pickle=True).item()
wordPairDict = wordDict['pairs']
wordTrairDict = wordDict['trairs']
responsePairDict = wordDict['responsePairs']
@@ -389,7 +389,7 @@ class Chatbot(commands.Cog):
MAX_N_TRIES = 50
#Get dictionary/Markov chain
wordDict = np.load('markov_dict.npy').item()
wordDict = np.load('markov_dict.npy', allow_pickle=True).item()
wordPairDict = wordDict['pairs']
#try:
+10 -10
View File
@@ -122,7 +122,7 @@ class Points(commands.Cog):
"""
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)
for user in pointsCountSorted:
if user[0] != self.BANK_ID:
@@ -146,31 +146,31 @@ class Points(commands.Cog):
# Transfer points form one user to another
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[toUserId]["points"] += points
np.save("pointscount.npy", pointsCount)
# Do we know this 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()
# Get a user's point balance
def getUserBalance(self, user):
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
return pointsCount[user.id]["points"]
# Get the balance of the bank
def getBankBalance(self):
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
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
# If this was in the past: reset
# Also, return the updated object. Why not.
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")
if 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.
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
def increaseUsersPointTakenOnDate(self, userId, points):
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
pointsCount[userId]["pointTakenOnDate"] += points
np.save("pointscount.npy", pointsCount)
# Increase the number of bank points this user has given today
# Warning: assumes you executed refreshDateVarsAndReturnUserVars()
def increaseUsersBankPointGivenAwayToday(self, userId, points):
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
pointsCount[userId]["bankPointsGivenOnDate"] += points
np.save("pointscount.npy", pointsCount)
@@ -252,10 +252,10 @@ class Points(commands.Cog):
def init(self):
# Check if points file exists:
try:
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
except FileNotFoundError:
np.save("pointscount.npy", {})
pointsCount = np.load('pointscount.npy').item()
pointsCount = np.load('pointscount.npy', allow_pickle=True).item()
# Initialise the bank:
if self.BANK_ID not in pointsCount.keys():