增加管理菜单(未完成

This commit is contained in:
2022-09-04 15:00:24 +00:00
parent 07d031c94a
commit b400332423
3 changed files with 141 additions and 3 deletions

View File

@@ -68,6 +68,12 @@ reason TEXT,
name TEXT,
PRIMARY KEY (userId)
)'''
CHATNAMECACHE_TABLE = '''CREATE TABLE chatNameCache (
id INT,
name TEXT,
time INT,
PRIMARY KEY (id)
)'''
@unique
@@ -142,6 +148,9 @@ class database:
if v < [1, 0, 0, 8]:
self._db.execute('ALTER TABLE RSSList ADD settings TEXT;')
self._db.commit()
if v < [1, 0, 0, 9]:
self._db.execute(CHATNAMECACHE_TABLE)
self._db.commit()
self._db.execute('VACUUM;')
self.__updateExistsTable()
self.__write_version()
@@ -161,10 +170,12 @@ class database:
self._db.execute(HASHLIST_TABLE)
if 'userBlackList' not in self._exist_tables:
self._db.execute(USERBLACKLIST_TABLE)
if 'chatNameCache' not in self._exist_tables:
self._db.execute(CHATNAMECACHE_TABLE)
self._db.commit()
def __init__(self, m, loc: str):
self._version = [1, 0, 0, 8]
self._version = [1, 0, 0, 9]
self._value_lock = Lock()
self._db = sqlite3.connect(loc, check_same_thread=False)
self._db.execute('VACUUM;')
@@ -327,6 +338,13 @@ class database:
return i[0]
return None
def getChatName(self, chat_id: int, maxCacheTime: int = 3600) -> Optional[str]:
with self._value_lock:
cur = self._db.execute('SELECT name FROM chatNameCache WHERE id = ? AND time > ?;', (chat_id, round(time()) - maxCacheTime))
for i in cur:
return i[0]
return None
def getChatRSSCount(self) -> int:
with self._value_lock:
cur = self._db.execute('SELECT COUNT(*) FROM chatList;')
@@ -341,6 +359,14 @@ class database:
return i[0]
return None
def getRSSList(self) -> Optional[List[RSSEntry]]:
with self._value_lock:
cur = self._db.execute(f'SELECT * FROM RSSList;')
r = []
for i in cur:
r.append(RSSEntry(i, self._main._setting.maxCount))
return r
def getRSSByIdAndChatId(self, id: int, chatId: int) -> RSSEntry:
while self._value_lock:
cur = self._db.execute('SELECT RSSList.title, RSSList.url, RSSList.interval, RSSList.lastupdatetime, RSSList.id, RSSList.lasterrortime, RSSList.forceupdate, RSSList.errorcount, RSSList.settings, chatList.config FROM chatList INNER JOIN RSSList ON RSSList.id = chatList.id WHERE chatList.chatId = ? AND chatlist.id = ?;', (chatId, id))
@@ -424,6 +450,15 @@ class database:
except:
return False
def saveChatName(self, chatId: int, name: str) -> bool:
with self._value_lock:
try:
self._db.execute('INSERT OR REPLACE INTO chatNameCache VALUES (?, ?, ?);', (chatId, name, round(time())))
self._db.commit()
return True
except:
return False
def setRSSForceUpdate(self, id: int, forceupdate: bool) -> bool:
with self._value_lock:
try: