Browse Source

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

master
JerryXiao 8 months ago
parent
commit
0e17748e3a
Signed by: Jerry
GPG Key ID: 22618F758B5BE2E5
  1. 3
      requirements.txt
  2. 9
      tgmsbot.py

3
requirements.txt

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

9
tgmsbot.py

@ -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):

Loading…
Cancel
Save