diff --git a/.gitignore b/.gitignore index c98c909..49c0dbf 100644 --- a/.gitignore +++ b/.gitignore @@ -173,4 +173,7 @@ cython_debug/ # PyPI configuration file .pypirc -.* \ No newline at end of file +.* +state.json +botpy.log* +joined_group.cfg \ No newline at end of file diff --git a/bot.py b/bot.py index b1b7d61..e0604df 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,5 @@ from typing import Any, List - +import group from botpy.connection import ConnectionSession from botpy.message import (Message) @@ -127,11 +127,11 @@ class djtuWebsocket (Client) : # 加入群聊 new_group = True if not groups is None : - for i in groups : + for i in groups.groups : if i.find(gid) != -1 : new_group = False if new_group : - groups.append(gid) + groups.groups.append(gid) # 解析指令 commands:dict[str,types.MethodType|types.FunctionType] = { r'吃什么' : lambda :"是啊吃什么" @@ -160,7 +160,7 @@ class djtuWebsocket (Client) : # 广播 try : msg = self.q.get() - for i in groups: + for i in groups.groups: asyncio.create_task(self.api.post_group_message(i,content=msg)) except Exception as e: @@ -173,7 +173,7 @@ bbyAccount = os.getenv("BOBBY_ACCOUNT") bbyPasswd = os.getenv("BOBBY_PASSWORD") appid = os.getenv("APP_ID") secret_bot = os.getenv("SECRET") -groups:list[str] = [] +groups = group.GroupCtl() if appid is None or secret_bot is None : raise SystemExit("未找到bot配置!") diff --git a/group.py b/group.py new file mode 100644 index 0000000..13e767a --- /dev/null +++ b/group.py @@ -0,0 +1,13 @@ +import os + +# 记录加入的群组 +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()) +