From 87551ee3583a47f2658629514eec9d063d0ab3b7 Mon Sep 17 00:00:00 2001 From: Wbucket <2595141012@stu.hqu.edu.cn> Date: Wed, 30 Sep 2026 23:00:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20=E5=BF=98=E8=AE=B0=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E4=BA=86QAQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 1 + group.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 3d45f76..fcdfc8c 100644 --- a/bot.py +++ b/bot.py @@ -142,6 +142,7 @@ class djtuWebsocket (Client) : new_group = False if new_group : groups.groups.append(gid) + groups.save() # 解析指令 commands:dict[str,types.MethodType|types.FunctionType] = { r'吃什么' : lambda :"是啊吃什么" diff --git a/group.py b/group.py index 13e767a..1ff3d30 100644 --- a/group.py +++ b/group.py @@ -5,9 +5,18 @@ class GroupCtl : path = os.path.join(os.getcwd(),"joined_group.cfg") groups:list[str] = [] - - def __init__(self) -> None: - fd = os.open(self.path,os.O_CREAT|os.W_OK) - with open(fd) as file : - self.groups.append(file.readline()) + def __init__(self) -> None: + with open(self.openfile()) as awa: + self.groups = awa.readlines() + + def save(self): + # 重新加载 + fd = self.openfile() + os.truncate(self.path,0) + os.write(fd,bytes('\n'.join(self.groups),'utf-8')) + os.close(fd) + + def openfile(self): + return os.open(self.path,os.O_RDWR|os.O_CREAT) + \ No newline at end of file