diff --git a/config.py b/config.py index 8746691..2786dc8 100644 --- a/config.py +++ b/config.py @@ -79,10 +79,11 @@ class RSSConfig: self.send_ugoira_method = SendUgoiraMethod(0) self.compress_big_image = True self.thread_ids = MessageThreadIdList() + self.add_author = False self.update(d) def toJson(self): - return dumps({'disable_web_page_preview': self.disable_web_page_preview, 'show_RSS_title': self.show_RSS_title, 'show_Content_title': self.show_Content_title, 'show_content': self.show_content, 'send_media': self.send_media, 'display_entry_link': self.display_entry_link, 'send_img_as_file': self.send_img_as_file, 'send_ugoira_with_origin_pix_fmt': self.send_ugoira_with_origin_pix_fmt, 'send_ugoira_method': self.send_ugoira_method.value, "compress_big_image": self.compress_big_image, 'thread_ids': {'list': self.thread_ids._list, 'without_id': self.thread_ids._without_id}}, ensure_ascii=False) + return dumps({'disable_web_page_preview': self.disable_web_page_preview, 'show_RSS_title': self.show_RSS_title, 'show_Content_title': self.show_Content_title, 'show_content': self.show_content, 'send_media': self.send_media, 'display_entry_link': self.display_entry_link, 'send_img_as_file': self.send_img_as_file, 'send_ugoira_with_origin_pix_fmt': self.send_ugoira_with_origin_pix_fmt, 'send_ugoira_method': self.send_ugoira_method.value, "compress_big_image": self.compress_big_image, 'thread_ids': {'list': self.thread_ids._list, 'without_id': self.thread_ids._without_id}, 'add_author': self.add_author}, ensure_ascii=False) def update(self, d: dict): if d is not None: diff --git a/rssbot.py b/rssbot.py index aa15c25..fc695a8 100644 --- a/rssbot.py +++ b/rssbot.py @@ -97,6 +97,7 @@ def getMediaInfo(m: dict, config: RSSConfig = RSSConfig()) -> str: s += f"\n发送原始像素格式的Pixiv动图:{config.send_ugoira_with_origin_pix_fmt}" s += f'\n发送Pixiv动图为{config.send_ugoira_method}' s += f"\n发送时压缩过大图片:{config.compress_big_image}" + s += f"\n添加作者名:{config.add_author}" s += f"\nRSS全局设置:" s += f"\n发送时使用原文件名:{config.send_origin_file_name}" return s @@ -127,6 +128,7 @@ class InlineKeyBoardCallBack(Enum): EnableSendWithoutTopicId = 20 RemoveTopicFromList = 21 DisableTopic = 22 + AddAuthor = 23 def getInlineKeyBoardWhenRSS(hashd: str, m: dict, isOwn: bool) -> dict: @@ -203,6 +205,7 @@ def getInlineKeyBoardWhenRSS2(hashd: str, config: RSSConfig) -> str: d.append([]) i += 1 d[i].append({'text': f'{"管理" if config.thread_ids.isEnabled else "启用"}发送到话题功能', 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.EnableTopic.value}'}) + d[i].append({'text': f'{"禁用" if config.add_author else "启用"}添加作者名', 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.AddAuthor.value}'}) d.append([]) i += 1 d[i].append( @@ -279,16 +282,18 @@ class main: if testMessage: text.addtotext('#测试消息') if config.show_RSS_title: - text.addtotext(f"{meta['title']}") + text.addtotext(f"{escape(meta['title'])}") + if config.add_author and 'author' in content and content['author']: + text += f"{escape(content['author'])}" if config.show_Content_title and 'title' in content and content['title'] is not None and content['title'] != '': if 'link' in content and content['link'] is not None and content['link'] != '': if not config.display_entry_link: - text += f"""{content['title']}""" + text += f"""{escape(content['title'])}""" else: - text += f"{content['title']}" + text += f"{escape(content['title'])}" text += f"""{escape(content['link'])}""" else: - text.addtotext(f"{content['title']}") + text.addtotext(f"{escape(content['title'])}") elif 'link' in content and content['link'] is not None and content['link'] != '': text.addtotext( f"""{escape(content['link'])}""") @@ -1832,7 +1837,7 @@ class callbackQueryHandle(Thread): self._main._request("editMessageText", "post", json=di) self.answer() return - elif self._inlineKeyBoardCommand in [InlineKeyBoardCallBack.DisableWebPagePreview, InlineKeyBoardCallBack.ShowRSSTitle, InlineKeyBoardCallBack.ShowContentTitle, InlineKeyBoardCallBack.ShowContent, InlineKeyBoardCallBack.SendMedia, InlineKeyBoardCallBack.DisplayEntryLink, InlineKeyBoardCallBack.SendImgAsFile, InlineKeyBoardCallBack.SendUgoiraWithOriginPixFmt, InlineKeyBoardCallBack.SendUgoiraMethod, InlineKeyBoardCallBack.CompressBigImage]: + elif self._inlineKeyBoardCommand in [InlineKeyBoardCallBack.DisableWebPagePreview, InlineKeyBoardCallBack.ShowRSSTitle, InlineKeyBoardCallBack.ShowContentTitle, InlineKeyBoardCallBack.ShowContent, InlineKeyBoardCallBack.SendMedia, InlineKeyBoardCallBack.DisplayEntryLink, InlineKeyBoardCallBack.SendImgAsFile, InlineKeyBoardCallBack.SendUgoiraWithOriginPixFmt, InlineKeyBoardCallBack.SendUgoiraMethod, InlineKeyBoardCallBack.CompressBigImage, InlineKeyBoardCallBack.AddAuthor]: if self._inlineKeyBoardCommand == InlineKeyBoardCallBack.DisableWebPagePreview: self._rssMeta.config.disable_web_page_preview = not self._rssMeta.config.disable_web_page_preview elif self._inlineKeyBoardCommand == InlineKeyBoardCallBack.ShowRSSTitle: @@ -1853,6 +1858,8 @@ class callbackQueryHandle(Thread): self._rssMeta.config.send_ugoira_method = SendUgoiraMethod(int(self._inputList[3])) elif self._inlineKeyBoardCommand == InlineKeyBoardCallBack.CompressBigImage: self._rssMeta.config.compress_big_image = not self._rssMeta.config.compress_big_image + elif self._inlineKeyBoardCommand == InlineKeyBoardCallBack.AddAuthor: + self._rssMeta.config.add_author = not self._rssMeta.config.add_author di = {'chat_id': self._rssMeta.chatId, 'message_id': self._rssMeta.messageId} di['text'] = getMediaInfo( @@ -2118,7 +2125,7 @@ class callbackQueryHandle(Thread): self._main._request("editMessageText", "post", json=di) self.answer() return - elif self._inlineKeyBoardForRSSListCommand in [InlineKeyBoardForRSSList.DisableWebPagePreview, InlineKeyBoardForRSSList.ShowRSSTitle, InlineKeyBoardForRSSList.ShowContentTitle, InlineKeyBoardForRSSList.ShowContent, InlineKeyBoardForRSSList.SendMedia, InlineKeyBoardForRSSList.DisplayEntryLink, InlineKeyBoardForRSSList.SendImgAsFile, InlineKeyBoardForRSSList.SendUgoiraWithOriginPixFmt, InlineKeyBoardForRSSList.SendUgoiraMethod, InlineKeyBoardForRSSList.CompressBigImage]: + elif self._inlineKeyBoardForRSSListCommand in [InlineKeyBoardForRSSList.DisableWebPagePreview, InlineKeyBoardForRSSList.ShowRSSTitle, InlineKeyBoardForRSSList.ShowContentTitle, InlineKeyBoardForRSSList.ShowContent, InlineKeyBoardForRSSList.SendMedia, InlineKeyBoardForRSSList.DisplayEntryLink, InlineKeyBoardForRSSList.SendImgAsFile, InlineKeyBoardForRSSList.SendUgoiraWithOriginPixFmt, InlineKeyBoardForRSSList.SendUgoiraMethod, InlineKeyBoardForRSSList.CompressBigImage, InlineKeyBoardForRSSList.AddAuthor]: di = {'chat_id': self._data['message']['chat']['id'], 'message_id': self._data['message']['message_id']} rssList = self._main._db.getRSSListByChatId(chatId) @@ -2151,6 +2158,8 @@ class callbackQueryHandle(Thread): config.send_ugoira_method = SendUgoiraMethod(int(self._inputList[5])) elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.CompressBigImage: config.compress_big_image = not config.compress_big_image + elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.AddAuthor: + config.add_author = not config.add_author updated = self._main._db.updateChatConfig(chatEntry) if updated: self.answer('修改设置成功') diff --git a/rsslist.py b/rsslist.py index 8aa55ea..be78edf 100644 --- a/rsslist.py +++ b/rsslist.py @@ -55,6 +55,7 @@ class InlineKeyBoardForRSSList(Enum): EnableSendWithoutTopicId = 27 RemoveTopicFromList = 28 DisableTopic = 29 + AddAuthor = 30 def getTextContentForRSSInList(rssEntry: RSSEntry, s: settings) -> str: @@ -97,6 +98,7 @@ def getTextContentForRSSInList(rssEntry: RSSEntry, s: settings) -> str: text += f'发送原始像素格式的Pixiv动图:{config.send_ugoira_with_origin_pix_fmt}' text += f'发送Pixiv动图为{config.send_ugoira_method}' text += f"发送时压缩过大图片:{config.compress_big_image}" + text += f"添加作者名:{config.add_author}" text += f"RSS全局设置:" text += f"发送时使用原文件名:{config.send_origin_file_name}" return text.tostr() @@ -238,6 +240,7 @@ def getInlineKeyBoardForRSSSettingsInList(chatId: int, rssEntry: RSSEntry, index d.append([]) i += 1 d[i].append({'text': f'{"管理" if config.thread_ids.isEnabled else "启用"}发送到话题功能', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.EnableTopic.value},{index},{rssEntry.id}'}) + d[i].append({'text': f'{"禁用" if config.add_author else "启用"}添加作者名', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.AddAuthor.value},{index},{rssEntry.id}'}) d.append([]) i = i + 1 d[i].append(