diff --git a/database.py b/database.py index 01f7074..b5bc38b 100644 --- a/database.py +++ b/database.py @@ -376,6 +376,13 @@ class database: r.append(RSSEntry(i, self._main._setting.maxCount)) return r + def getRSSById(self, id: int) -> Optional[RSSEntry]: + with self._value_lock: + cur = self._db.execute(f'SELECT * FROM RSSList WHERE id = ?;', (id,)) + for i in cur: + return RSSEntry(i, self._main._setting.maxCount) + return None + 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)) diff --git a/manage.py b/manage.py index 1cd4e0f..71e77ff 100644 --- a/manage.py +++ b/manage.py @@ -17,6 +17,7 @@ from enum import Enum, unique from html import escape from math import ceil, floor from typing import List +from config import RSSConfig from readset import settings from rssbotlib import have_rssbotlib from RSSEntry import ChatEntry, RSSEntry @@ -36,6 +37,8 @@ class InlineKeyBoardForManage(Enum): RSSManage = 8 ChatManage = 9 BackToList = 10 + Unsubscribe = 11 + ConfirmUnsubscribe = 12 def getInlineKeyBoardForManage(): @@ -156,7 +159,7 @@ def getTextContentForRSSInManageList(m, rssEntry: RSSEntry, s: settings, chatId: chatName = m.getChatName(chatId) temp = chatName if chatId < 0 else f'{escape(chatName)}' text.addtotext(f'订阅用户:{temp}') - if len(rssEntry.chatList) > 0: + if len(rssEntry.chatList) > 0 and chatId is not None: chatEntry: ChatEntry = rssEntry.chatList[0] config = chatEntry.config text.addtotext("设置:") @@ -173,6 +176,10 @@ def getTextContentForRSSInManageList(m, rssEntry: RSSEntry, s: settings, chatId: text += f"发送时压缩过大图片:{config.compress_big_image}" text += f"RSS全局设置:" text += f"发送时使用原文件名:{config.send_origin_file_name}" + else: + global_config = RSSConfig(rssEntry._settings) + text += f"RSS全局设置:" + text += f"发送时使用原文件名:{global_config.send_origin_file_name}" return text.tostr() @@ -182,5 +189,20 @@ def getInlineKeyBoardForRSSInManageList(rss: RSSEntry, index: int, chatId: int = d.append([]) i += 1 have_chat_id = chatId is not None and chatIndex is not None + if have_chat_id: + d[i].append({'text': '取消订阅', 'callback_data': f'3,{InlineKeyBoardForManage.ManageByChatId.value},{InlineKeyBoardForManage.ChatManage.value},{chatIndex},{chatId},{InlineKeyBoardForManage.RSSManage.value},{index},{rss.id},{InlineKeyBoardForManage.Unsubscribe.value}'}) + d.append([]) + i += 1 d[i].append({'text': '返回', 'callback_data': (f'3,{InlineKeyBoardForManage.ManageByChatId.value},{InlineKeyBoardForManage.ChatManage.value},{chatIndex},{chatId}' if have_chat_id else f'3,{InlineKeyBoardForManage.ManageByRSS.value}') + f',{InlineKeyBoardForManage.BackToList.value},{index}' }) return {'inline_keyboard': d} + + +def getInlineKeyBoardForRSSUnsubscribeInManageList(rss: RSSEntry, index: int, chatId: int, chatIndex: int): + d = [] + i = -1 + d.append([]) + i += 1 + base = f'3,{InlineKeyBoardForManage.ManageByChatId.value},{InlineKeyBoardForManage.ChatManage.value},{chatIndex},{chatId},{InlineKeyBoardForManage.RSSManage.value},{index},{rss.id}' + d[i].append({'text': '是', 'callback_data': f'{base},{InlineKeyBoardForManage.ConfirmUnsubscribe.value}'}) + d[i].append({'text': '否', 'callback_data': base}) + return {'inline_keyboard': d} diff --git a/rssbot.py b/rssbot.py index 35138a4..9aa3b52 100644 --- a/rssbot.py +++ b/rssbot.py @@ -42,7 +42,7 @@ from miraiDatabase import MiraiDatabase from mirai import Mirai from blackList import BlackList, InlineKeyBoardForBlackList, getInlineKeyBoardForBlackList, getTextContentForBlackInfo, getInlineKeyBoardForBlackInfo, getTextContentForUnbanBlackInfo, getInlineKeyBoardForUnbanBlackInfo, BlackInfo from json import loads -from manage import getInlineKeyBoardForManage, InlineKeyBoardForManage, getInlineKeyBoardForManageRSSList, getInlineKeyBoardForManageChatList, getTextContentForRSSInManageList, getInlineKeyBoardForRSSInManageList +from manage import getInlineKeyBoardForManage, InlineKeyBoardForManage, getInlineKeyBoardForManageRSSList, getInlineKeyBoardForManageChatList, getTextContentForRSSInManageList, getInlineKeyBoardForRSSInManageList, getInlineKeyBoardForRSSUnsubscribeInManageList MAX_ITEM_IN_MEDIA_GROUP = 10 @@ -2114,13 +2114,19 @@ class callbackQueryHandle(Thread): if rssManageChatId is not None: rssEntry = self._main._db.getRSSByIdAndChatId(rssManageRSSId, rssManageChatId) else: - pass + rssEntry = self._main._db.getRSSById(rssManageRSSId) if rssManageCommand is None: di['text'] = getTextContentForRSSInManageList(self._main, rssEntry, self._main._setting, rssManageChatId) di['parse_mode'] = 'HTML' di['reply_markup'] = getInlineKeyBoardForRSSInManageList(rssEntry, rssManageIndex, rssManageChatId, rssManageChatIndex) self._main._request("editMessageText", "post", json=di) return + elif rssManageCommand == InlineKeyBoardForManage.Unsubscribe: + di['text'] = getTextContentForRSSUnsubscribeInList(rssEntry) + di['parse_mode'] = 'HTML' + di['reply_markup'] = getInlineKeyBoardForRSSUnsubscribeInManageList(rssEntry, rssManageIndex, rssManageChatId, rssManageChatIndex) + self._main._request("editMessageText", "post", json=di) + return elif self._inlineKeyBoardForManageCommand == InlineKeyBoardForManage.ManageMenu: di['text'] = '请选择管理模式:' di['reply_markup'] = getInlineKeyBoardForManage()