add support to modify config
This commit is contained in:
19
database.py
19
database.py
@@ -202,6 +202,7 @@ PRIMARY KEY (hash)
|
||||
try:
|
||||
self._db.execute(
|
||||
f"DELETE FROM chatList WHERE chatId={chatId} AND id='{id}'")
|
||||
self._db.commit()
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
@@ -235,6 +236,24 @@ PRIMARY KEY (hash)
|
||||
except:
|
||||
return False
|
||||
|
||||
def updateChatConfig(self, chatEntry: ChatEntry) -> bool:
|
||||
with self._value_lock:
|
||||
try:
|
||||
cur = self._db.execute(
|
||||
f"SELECT * FROM chatList WHERE chatId={chatEntry.chatId} AND id='{chatEntry.id}'")
|
||||
has_data = False
|
||||
for i in cur: # pylint: disable=unused-variable
|
||||
has_data = True
|
||||
break
|
||||
if not has_data:
|
||||
return False
|
||||
self._db.execute(
|
||||
f"UPDATE chatList SET config='{dealtext(chatEntry.config.toJson())}' WHERE chatId={chatEntry.chatId} AND id='{chatEntry.id}'")
|
||||
self._db.commit()
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def updateRSS(self, title: str, url: str, lastupdatetime: int, hashEntries: HashEntries, ttl: int = None):
|
||||
with self._value_lock:
|
||||
try:
|
||||
|
||||
51
rssbot.py
51
rssbot.py
@@ -14,7 +14,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from database import database, userStatus, RSSConfig
|
||||
from RSSEntry import HashEntry, HashEntries, calHash
|
||||
from RSSEntry import HashEntry, HashEntries, calHash, ChatEntry
|
||||
from os.path import exists
|
||||
from readset import settings, commandline
|
||||
from requests import Session
|
||||
@@ -30,7 +30,7 @@ from random import randrange
|
||||
from textc import textc, removeEmptyLine, decodeURI
|
||||
from re import search, I
|
||||
from rsschecker import RSSCheckerThread
|
||||
from rsslist import getInlineKeyBoardForRSSList, InlineKeyBoardForRSSList, getInlineKeyBoardForRSSInList, getTextContentForRSSInList, getInlineKeyBoardForRSSUnsubscribeInList, getTextContentForRSSUnsubscribeInList
|
||||
from rsslist import getInlineKeyBoardForRSSList, InlineKeyBoardForRSSList, getInlineKeyBoardForRSSInList, getTextContentForRSSInList, getInlineKeyBoardForRSSUnsubscribeInList, getTextContentForRSSUnsubscribeInList, getInlineKeyBoardForRSSSettingsInList
|
||||
from usercheck import checkUserPermissionsInChat, UserPermissionsInChatCheckResult
|
||||
import sys
|
||||
|
||||
@@ -866,7 +866,7 @@ class callbackQueryHandle(Thread):
|
||||
'message_id': self._data['message']['message_id']}
|
||||
self._main._request("deleteMessage", "post", json=di)
|
||||
return
|
||||
elif self._inlineKeyBoardForRSSListCommand in [InlineKeyBoardForRSSList.Content, InlineKeyBoardForRSSList.CancleUnsubscribe]:
|
||||
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)
|
||||
@@ -926,6 +926,51 @@ class callbackQueryHandle(Thread):
|
||||
chatId, rssList, itemIndex=ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
return
|
||||
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)
|
||||
di['text'] = getTextContentForRSSInList(rssList[ind])
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList(
|
||||
chatId, rssList[ind], ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
self.answer()
|
||||
return
|
||||
elif self._inlineKeyBoardForRSSListCommand in [InlineKeyBoardForRSSList.DisableWebPagePreview, InlineKeyBoardForRSSList.ShowRSSTitle, InlineKeyBoardForRSSList.ShowContentTitle, InlineKeyBoardForRSSList.ShowContent, InlineKeyBoardForRSSList.SendMedia]:
|
||||
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)
|
||||
rssEntry = rssList[ind]
|
||||
chatEntry: ChatEntry = rssEntry.chatList[0]
|
||||
config = chatEntry.config
|
||||
if self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.DisableWebPagePreview:
|
||||
config.disable_web_page_preview = not config.disable_web_page_preview
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.ShowRSSTitle:
|
||||
config.show_RSS_title = not config.show_RSS_title
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.ShowContentTitle:
|
||||
config.show_Content_title = not config.show_Content_title
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.ShowContent:
|
||||
config.show_content = not config.show_content
|
||||
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.SendMedia:
|
||||
config.send_media = not config.send_media
|
||||
updated = self._main._db.updateChatConfig(chatEntry)
|
||||
if updated:
|
||||
self.answer('修改设置成功')
|
||||
else:
|
||||
self.answer('修改设置失败')
|
||||
rssList = self._main._db.getRSSListByChatId(chatId)
|
||||
ind = max(min(ind, len(rssList)), 0)
|
||||
di['text'] = getTextContentForRSSInList(rssList[ind])
|
||||
di['parse_mode'] = 'HTML'
|
||||
di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList(
|
||||
chatId, rssList[ind], ind)
|
||||
self._main._request("editMessageText", "post", json=di)
|
||||
return
|
||||
else:
|
||||
self.answer('未知的按钮。')
|
||||
return
|
||||
|
||||
47
rsslist.py
47
rsslist.py
@@ -33,6 +33,13 @@ class InlineKeyBoardForRSSList(Enum):
|
||||
Unsubscribe = 7
|
||||
ConfirmUnsubscribe = 8
|
||||
CancleUnsubscribe = 9
|
||||
SettingsPage = 10
|
||||
BackToContentPage = 11
|
||||
DisableWebPagePreview = 12
|
||||
ShowRSSTitle = 13
|
||||
ShowContentTitle = 14
|
||||
ShowContent = 15
|
||||
SendMedia = 16
|
||||
|
||||
|
||||
def getTextContentForRSSInList(rssEntry: RSSEntry) -> str:
|
||||
@@ -113,6 +120,10 @@ def getInlineKeyBoardForRSSInList(chatId: int, rssEntry: RSSEntry, index: int) -
|
||||
{'text': '取消订阅', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.Unsubscribe.value},{index}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '设置', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SettingsPage.value},{index}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToList.value},{index}'})
|
||||
return {'inline_keyboard': d}
|
||||
@@ -128,3 +139,39 @@ def getInlineKeyBoardForRSSUnsubscribeInList(chatId: int, rssEntry: RSSEntry, in
|
||||
d[i].append(
|
||||
{'text': '否', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.CancleUnsubscribe.value},{index}'})
|
||||
return {'inline_keyboard': d}
|
||||
|
||||
|
||||
def getInlineKeyBoardForRSSSettingsInList(chatId: int, rssEntry: RSSEntry, index: int, page: int = 1) -> dict:
|
||||
d = []
|
||||
i = -1
|
||||
if page != 1:
|
||||
page = 1
|
||||
chatInfo: ChatEntry = rssEntry.chatList[0]
|
||||
config = chatInfo.config
|
||||
if page == 1:
|
||||
d.append([])
|
||||
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}'})
|
||||
temp = '隐藏RSS标题' if config.show_RSS_title else '显示RSS标题'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowRSSTitle.value},{index}'})
|
||||
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}'})
|
||||
temp = '隐藏内容' if config.show_content else '显示内容'
|
||||
d[i].append(
|
||||
{'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.ShowContent.value},{index}'})
|
||||
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}'})
|
||||
d.append([])
|
||||
i = i + 1
|
||||
d[i].append(
|
||||
{'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToContentPage.value},{index}'})
|
||||
return {'inline_keyboard': d}
|
||||
|
||||
Reference in New Issue
Block a user