feat : 群组记录存储 && .gitingore

This commit is contained in:
Wbucket
2026-09-30 22:08:14 +08:00
parent 9cb81deab4
commit 9e46704d63
3 changed files with 22 additions and 6 deletions
+3
View File
@@ -174,3 +174,6 @@ cython_debug/
# PyPI configuration file # PyPI configuration file
.pypirc .pypirc
.* .*
state.json
botpy.log*
joined_group.cfg
+5 -5
View File
@@ -1,5 +1,5 @@
from typing import Any, List from typing import Any, List
import group
from botpy.connection import ConnectionSession from botpy.connection import ConnectionSession
from botpy.message import (Message) from botpy.message import (Message)
@@ -127,11 +127,11 @@ class djtuWebsocket (Client) :
# 加入群聊 # 加入群聊
new_group = True new_group = True
if not groups is None : if not groups is None :
for i in groups : for i in groups.groups :
if i.find(gid) != -1 : if i.find(gid) != -1 :
new_group = False new_group = False
if new_group : if new_group :
groups.append(gid) groups.groups.append(gid)
# 解析指令 # 解析指令
commands:dict[str,types.MethodType|types.FunctionType] = { commands:dict[str,types.MethodType|types.FunctionType] = {
r'吃什么' : lambda :"是啊吃什么" r'吃什么' : lambda :"是啊吃什么"
@@ -160,7 +160,7 @@ class djtuWebsocket (Client) :
# 广播 # 广播
try : try :
msg = self.q.get() msg = self.q.get()
for i in groups: for i in groups.groups:
asyncio.create_task(self.api.post_group_message(i,content=msg)) asyncio.create_task(self.api.post_group_message(i,content=msg))
except Exception as e: except Exception as e:
@@ -173,7 +173,7 @@ bbyAccount = os.getenv("BOBBY_ACCOUNT")
bbyPasswd = os.getenv("BOBBY_PASSWORD") bbyPasswd = os.getenv("BOBBY_PASSWORD")
appid = os.getenv("APP_ID") appid = os.getenv("APP_ID")
secret_bot = os.getenv("SECRET") secret_bot = os.getenv("SECRET")
groups:list[str] = [] groups = group.GroupCtl()
if appid is None or secret_bot is None : if appid is None or secret_bot is None :
raise SystemExit("未找到bot配置!") raise SystemExit("未找到bot配置!")
+13
View File
@@ -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())