speed up response to rsslist inlineKeyBoard
This commit is contained in:
@@ -274,6 +274,15 @@ PRIMARY KEY (userId)
|
||||
r.append(temp)
|
||||
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, chatList.config FROM chatList INNER JOIN RSSList ON RSSList.id = chatList.id WHERE chatList.chatId = ? AND chatlist.id = ?;', (chatId, id))
|
||||
for i in cur:
|
||||
rss = RSSEntry(i, self._main._setting.maxCount)
|
||||
rss.chatList.append(ChatEntry((chatId, i[4], i[8])))
|
||||
return rss
|
||||
return None
|
||||
|
||||
def getRSSListByChatId(self, chatId: int) -> List[RSSEntry]:
|
||||
with self._value_lock:
|
||||
cur = self._db.execute(
|
||||
|
||||
83
rssbot.py
83
rssbot.py
@@ -1204,14 +1204,18 @@ class callbackQueryHandle(Thread):
|
||||
elif self._inlineKeyBoardForRSSListCommand in [InlineKeyBoardForRSSList.Content, InlineKeyBoardForRSSList.CancleUnsubscribe, InlineKeyBoardForRSSList.BackToContentPage]:
|
||||
di = {'chat_id': self._data['message']['chat']['id'],
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
ind = max(ind, 0)
|
||||
rssId = int(self._inputList[4])
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
di['text'] = getTextContentForRSSInList(
|
||||
rssList[ind], self._main._setting)
|
||||
rss, self._main._setting)
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSInList(
|
||||
chatId, rssList[ind], ind, self._main._setting.botOwnerList.isOwner(self._fromUserId))
|
||||
chatId, rss, ind, self._main._setting.botOwnerList.isOwner(self._fromUserId))
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
self.answer()
|
||||
return
|
||||
@@ -1231,12 +1235,16 @@ class callbackQueryHandle(Thread):
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
di['text'] = getTextContentForRSSUnsubscribeInList(
|
||||
rssList[ind])
|
||||
ind = max(ind, 0)
|
||||
rssId = int(self._inputList[4])
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
di['text'] = getTextContentForRSSUnsubscribeInList(rss)
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSUnsubscribeInList(
|
||||
chatId, rssList[ind], ind)
|
||||
chatId, rss, ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
self.answer()
|
||||
return
|
||||
@@ -1245,11 +1253,13 @@ class callbackQueryHandle(Thread):
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
if ind >= len(rssList) or ind < 0:
|
||||
self.answer('取消订阅失败:无效的索引。')
|
||||
rssId = int(self._inputList[4])
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('取消订阅失败:找不到该RSS。')
|
||||
else:
|
||||
unsubscribed = self._main._db.removeItemInChatList(
|
||||
chatId, rssList[ind].id)
|
||||
chatId, rss.id)
|
||||
if unsubscribed:
|
||||
self.answer('取消订阅成功。')
|
||||
ind = ind - 1
|
||||
@@ -1265,14 +1275,18 @@ class callbackQueryHandle(Thread):
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.SettingsPage:
|
||||
di = {'chat_id': self._data['message']['chat']['id'],
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
ind = max(ind, 0)
|
||||
rssId = int(self._inputList[4])
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
di['text'] = getTextContentForRSSInList(
|
||||
rssList[ind], self._main._setting)
|
||||
rss, self._main._setting)
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList(
|
||||
chatId, rssList[ind], ind)
|
||||
chatId, rss, ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
self.answer()
|
||||
return
|
||||
@@ -1281,8 +1295,12 @@ class callbackQueryHandle(Thread):
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
rssEntry = rssList[ind]
|
||||
ind = max(ind, 0)
|
||||
rssId = int(self._inputList[4])
|
||||
rssEntry = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rssEntry is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
chatEntry: ChatEntry = rssEntry.chatList[0]
|
||||
config = chatEntry.config
|
||||
if self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.DisableWebPagePreview:
|
||||
@@ -1300,33 +1318,40 @@ class callbackQueryHandle(Thread):
|
||||
self.answer('修改设置成功')
|
||||
else:
|
||||
self.answer('修改设置失败')
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
di['text'] = getTextContentForRSSInList(
|
||||
rssList[ind], self._main._setting)
|
||||
rss, self._main._setting)
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList(
|
||||
chatId, rssList[ind], ind)
|
||||
chatId, rss, ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
return
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.ForceUpdate:
|
||||
di = {'chat_id': self._data['message']['chat']['id'],
|
||||
'message_id': self._data['message']['message_id']}
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
if self._main._db.setRSSForceUpdate(rssList[ind].id, True):
|
||||
ind = max(ind, 0)
|
||||
rssId = int(self._inputList[4])
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
if self._main._db.setRSSForceUpdate(rss.id, True):
|
||||
self.answer('已发送强制更新请求。')
|
||||
else:
|
||||
self.answer('发送强制更新请求失败。')
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = int(self._inputList[3])
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
|
||||
if rss is None:
|
||||
self.answer('找不到该RSS。')
|
||||
return
|
||||
di['text'] = getTextContentForRSSInList(
|
||||
rssList[ind], self._main._setting)
|
||||
rss, self._main._setting)
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSInList(
|
||||
chatId, rssList[ind], ind, self._main._setting.botOwnerList.isOwner(self._fromUserId))
|
||||
chatId, rss, ind, self._main._setting.botOwnerList.isOwner(self._fromUserId))
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
return
|
||||
else:
|
||||
|
||||
24
rsslist.py
24
rsslist.py
@@ -96,7 +96,7 @@ def getInlineKeyBoardForRSSList(chatId: int, RSSEntries: List[RSSEntry], page: i
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': rss.title, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.Content.value},{s}'})
|
||||
{'text': rss.title, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.Content.value},{s},{rss.id}'})
|
||||
s = s + 1
|
||||
if pn != 1:
|
||||
d.append([])
|
||||
@@ -128,16 +128,16 @@ def getInlineKeyBoardForRSSInList(chatId: int, rssEntry: RSSEntry, index: int, i
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '取消订阅', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.Unsubscribe.value},{index}'})
|
||||
{'text': '取消订阅', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.Unsubscribe.value},{index},{rssEntry.id}'})
|
||||
if not rssEntry.forceupdate and isOwner:
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '强制更新', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ForceUpdate.value},{index}'})
|
||||
{'text': '强制更新', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ForceUpdate.value},{index},{rssEntry.id}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '设置', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SettingsPage.value},{index}'})
|
||||
{'text': '设置', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SettingsPage.value},{index},{rssEntry.id}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
@@ -151,9 +151,9 @@ def getInlineKeyBoardForRSSUnsubscribeInList(chatId: int, rssEntry: RSSEntry, in
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '是', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ConfirmUnsubscribe.value},{index}'})
|
||||
{'text': '是', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ConfirmUnsubscribe.value},{index},{rssEntry.id}'})
|
||||
d[i].append(
|
||||
{'text': '否', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.CancleUnsubscribe.value},{index}'})
|
||||
{'text': '否', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.CancleUnsubscribe.value},{index},{rssEntry.id}'})
|
||||
return {'inline_keyboard': d}
|
||||
|
||||
|
||||
@@ -169,25 +169,25 @@ def getInlineKeyBoardForRSSSettingsInList(chatId: int, rssEntry: RSSEntry, index
|
||||
i = i + 1
|
||||
temp = '启用预览' if config.disable_web_page_preview else '禁用预览'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.DisableWebPagePreview.value},{index}'})
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.DisableWebPagePreview.value},{index},{rssEntry.id}'})
|
||||
temp = '隐藏RSS标题' if config.show_RSS_title else '显示RSS标题'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowRSSTitle.value},{index}'})
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowRSSTitle.value},{index},{rssEntry.id}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
temp = '隐藏内容标题' if config.show_Content_title else '显示内容标题'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowContentTitle.value},{index}'})
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowContentTitle.value},{index},{rssEntry.id}'})
|
||||
temp = '隐藏内容' if config.show_content else '显示内容'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowContent.value},{index}'})
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowContent.value},{index},{rssEntry.id}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
temp = '禁用发送媒体' if config.send_media else '启用发送媒体'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SendMedia.value},{index}'})
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SendMedia.value},{index},{rssEntry.id}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToContentPage.value},{index}'})
|
||||
{'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToContentPage.value},{index},{rssEntry.id}'})
|
||||
return {'inline_keyboard': d}
|
||||
|
||||
Reference in New Issue
Block a user