what the f**k why would you add lock to the user and chat object, are you crazy?

This commit is contained in:
JerryXiao 2021-12-13 20:49:32 +08:00
parent 99f7055178
commit 0e17748e3a
Signed by: Jerry
GPG Key ID: 22618F758B5BE2E5
2 changed files with 10 additions and 2 deletions

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
numpy==1.21.4
peewee==3.14.8
python-telegram-bot==13.9

View File

@ -90,8 +90,8 @@ def display_username(user, atuser=True, shorten=False, markdown=True):
class Game:
def __init__(self, board, group, creator, lives=1):
self.board = board
self.group = group
self.creator = creator
self.group = self.nobot(group)
self.creator = self.nobot(creator)
self.msgid = None
self.__actions = dict()
self.last_player = None
@ -106,6 +106,10 @@ class Game:
self.lives = lives
self.ttl_lives = lives
self.lock = Lock()
@staticmethod
def nobot(input):
setattr(input, "bot", None)
return input
def __getstate__(self):
""" https://docs.python.org/3/library/pickle.html#handling-stateful-objects """
state = self.__dict__.copy()
@ -116,6 +120,7 @@ class Game:
self.lock = Lock()
def save_action(self, user, spot):
'''spot is supposed to be a tuple'''
user = self.nobot(user)
self.last_player = user
self.__actions.setdefault(user, list()).append(spot)
def actions_sum(self):