From 43c4ff2d754a724befe11fe5f5d4890e1facbcba Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Sun, 24 Mar 2024 05:16:36 +1100 Subject: [PATCH] Invite tokens were trying to save to the wrong place, but failing anyway, and some other bugs. --- backends/file.py | 6 +++--- models.py | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backends/file.py b/backends/file.py index b19bbfc..ff45c42 100644 --- a/backends/file.py +++ b/backends/file.py @@ -15,7 +15,7 @@ def _load(name,pos,file,obj): for line in linegen(file): split=line.split(',') if split[pos]==name: return obj(*split) - raise Exception('No such',obj.__name__,'with identifier',name) + raise Exception(f'No such {obj.__name__} with identifier {name}') def _load_multi(name,pos,file,obj): out=[] for line in linegen(file): @@ -62,7 +62,7 @@ def delete_invite(token): def linegen(path): i=0 file=open(path) - line=file.readline() + line=file.readline().rstrip('\n') # Maybe sometimes there won't be one. while line: i+=1 response=yield line @@ -91,7 +91,7 @@ def writefile(path,action,post=None): while line: i+=1 action(write,i,line) - line=file.readline() + line=file.readline().rstrip('\n') if post is not None: post(write) file.close() write.close() diff --git a/models.py b/models.py index f64ca8b..92f2c36 100644 --- a/models.py +++ b/models.py @@ -24,12 +24,15 @@ class Token(): self.owner=owner def revoke(self): backend.delete_token(self) + @property + def serialise(self): + return ','.join([self.value,self.owner]) @dataclass class InviteToken(Token): _uses: int=0 _max_uses: int=-1 - _expires: datetime=None + expires: datetime=None def __init__(self,*args,**kwargs): return super().__init__(*args,**kwargs) @property @@ -44,6 +47,9 @@ class InviteToken(Token): def max_uses(self,val): if -1