add send_origin_file_name

This commit is contained in:
2021-10-30 21:15:16 +08:00
parent 9b349e79ff
commit db9783f4fc
6 changed files with 242 additions and 35 deletions

View File

@@ -21,7 +21,7 @@ from hashl import sha256WithBase64
class ChatEntry:
def __init__(self, data=None):
def __init__(self, data=None, settings=None):
self._chatId = data[0] if data is not None and data[0] is not None else None
self._id = data[1] if data is not None and data[1] is not None else None
try:
@@ -29,6 +29,11 @@ class ChatEntry:
loads(data[2])) if data is not None and data[2] is not None else RSSConfig()
except:
self.config = RSSConfig()
if settings is not None:
try:
self.config.update(settings)
except Exception:
pass
@property
def chatId(self) -> int:
@@ -176,6 +181,14 @@ class RSSEntry:
self._errorcount = 0
if data is not None and data[7] is not None:
self._errorcount = data[7]
self._settings: dict = {}
if data is not None and data[8] is not None:
try:
self._settings = loads(data[8])
if not isinstance(self._settings, dict):
self._settings = {}
except Exception:
self._settings = {}
self.chatList = []
self.hashList = HashEntries(maxCount)

View File

@@ -25,10 +25,17 @@ class RSSConfig:
self.send_media = True
self.display_entry_link = False
self.send_img_as_file = False
self.send_origin_file_name = 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}, ensure_ascii=False)
def update(self, d: dict):
if d is not None:
for k in d.keys():
if hasattr(self, k):
setattr(self, k, d[k])
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}, ensure_ascii=False)
def toGlobalJson(self):
return dumps({'send_origin_file_name': self.send_origin_file_name}, ensure_ascii=False)

View File

@@ -16,7 +16,7 @@
import sqlite3
from config import RSSConfig
from RSSEntry import RSSEntry, ChatEntry, HashEntry, HashEntries
from typing import List, Tuple
from typing import List, Optional, Tuple
from enum import Enum, unique
from threading import Lock
from time import time
@@ -40,6 +40,7 @@ id INTEGER,
lasterrortime INT,
forceupdate BOOLEAN,
errorcount INT,
settings TEXT,
PRIMARY KEY (id)
);'''
CHATLIST_TABLE = '''CREATE TABLE chatList (
@@ -138,6 +139,9 @@ class database:
if v < [1, 0, 0, 7]:
self._db.execute('ALTER TABLE userBlackList ADD name TEXT;')
self._db.commit()
if v < [1, 0, 0, 8]:
self._db.execute('ALTER TABLE RSSList ADD settings TEXT;')
self._db.commit()
self._db.execute('VACUUM;')
self.__updateExistsTable()
self.__write_version()
@@ -160,7 +164,7 @@ class database:
self._db.commit()
def __init__(self, m, loc: str):
self._version = [1, 0, 0, 7]
self._version = [1, 0, 0, 8]
self._value_lock = Lock()
self._db = sqlite3.connect(loc, check_same_thread=False)
self._db.execute('VACUUM;')
@@ -226,12 +230,12 @@ class database:
hashd = i[4]
if has_data:
self._db.execute(
f"UPDATE RSSList SET title=?, interval=? WHERE id=?;",
(title, ttl, hashd))
f"UPDATE RSSList SET title=?, interval=?, settings=? WHERE id=?;",
(title, ttl, config.toGlobalJson(), hashd))
else:
self._db.execute(
f"INSERT INTO RSSList (title, url, interval, lastupdatetime, lasterrortime, forceupdate, errorcount) VALUES (?, ?, ?, ?, null, false, 0);",
(title, url, ttl, int(time())))
f"INSERT INTO RSSList (title, url, interval, lastupdatetime, lasterrortime, forceupdate, errorcount, settings) VALUES (?, ?, ?, ?, null, false, 0, ?);",
(title, url, ttl, int(time()), config.toGlobalJson()))
cur = self._db.execute(
'SELECT * FROM RSSList WHERE url=?;', (url,))
for i in cur:
@@ -296,7 +300,7 @@ class database:
cur2 = self._db.execute(
f'SELECT * FROM chatList WHERE id=?;', (temp.id,))
for i2 in cur2:
temp2 = ChatEntry(i2)
temp2 = ChatEntry(i2, temp._settings)
temp.chatList.append(temp2)
cur3 = self._db.execute(
f"SELECT * FROM hashList WHERE id=? ORDER BY time;", (temp.id,))
@@ -318,24 +322,33 @@ class database:
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))
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))
for i in cur:
rss = RSSEntry(i, self._main._setting.maxCount)
rss.chatList.append(ChatEntry((chatId, i[4], i[8])))
rss.chatList.append(ChatEntry((chatId, i[4], i[9]), rss._settings))
return rss
return None
def getRSSListByChatId(self, chatId: int) -> List[RSSEntry]:
with self._value_lock:
cur = self._db.execute(
f"SELECT RSSList.title, RSSList.url, RSSList.interval, RSSList.lastupdatetime, RSSList.id, RSSList.lasterrortime, RSSList.forceupdate, RSSList.errorcount, chatList.config FROM RSSList, chatList WHERE chatList.chatId = ? AND RSSList.id = chatList.id ORDER BY title;", (chatId,))
f"SELECT RSSList.title, RSSList.url, RSSList.interval, RSSList.lastupdatetime, RSSList.id, RSSList.lasterrortime, RSSList.forceupdate, RSSList.errorcount, RSSList.settings, chatList.config FROM RSSList, chatList WHERE chatList.chatId = ? AND RSSList.id = chatList.id ORDER BY title;", (chatId,))
RSSEntries = []
for i in cur:
rssEntry = RSSEntry(i, self._main._setting.maxCount)
rssEntry.chatList.append(ChatEntry((chatId, i[4], i[8])))
rssEntry.chatList.append(ChatEntry((chatId, i[4], i[9]), rssEntry._settings))
RSSEntries.append(rssEntry)
return RSSEntries
def getRSSSettingsByUrl(self, url: str) -> Optional[str]:
with self._value_lock:
try:
cur = self._db.execute('SELECT settings FROM RSSList WHERE url=?;', (url,))
for i in cur:
return i[0]
except Exception:
return None
def getUserStatus(self, userId: int) -> Tuple[userStatus, str]:
with self._value_lock:
try:
@@ -480,6 +493,24 @@ class database:
except:
return False
def updateRSSSettings(self, id: int, settings: RSSConfig):
with self._value_lock:
try:
cur = self._db.execute(
f'SELECT * FROM RSSList WHERE id=?;', (id,))
has_data = False
for i in cur:
rss = RSSEntry(i, self._main._setting.maxCount)
has_data = True
break
if not has_data:
return False
self._db.execute('UPDATE RSSList SET settings=? WHERE id=?;', (settings.toGlobalJson(), id))
self._db.commit()
return True
except Exception:
return False
def updateRSSWithError(self, id: int, lasterrortime: int):
with self._value_lock:
try:

View File

@@ -14,13 +14,14 @@
# 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 urllib.parse import urlsplit, parse_qs
from os.path import abspath, splitext, getsize, exists, isdir, isfile
from os.path import abspath, splitext, getsize, exists, isdir, isfile, join, basename
from time import time_ns
from random import randint
from requests import get
from os import remove as removeFile, mkdir, listdir, removedirs
from typing import List
from threading import Lock
from config import RSSConfig
def remove(s: str):
@@ -39,7 +40,7 @@ def remove(s: str):
class FileEntry:
def __init__(self, url: str, m):
def __init__(self, url: str, m, config: RSSConfig):
if not exists('Temp'):
mkdir('Temp')
if not isdir('Temp'):
@@ -47,7 +48,10 @@ class FileEntry:
mkdir('Temp')
from rssbot import main
self._m: main = m
self._config = config
self._url = url
self._usetempdir = False
self._tempdir: str = None
ph = urlsplit(url).path
self._ext = splitext(ph)[1]
if self._ext == '' and ph.endswith('/RSSProxy'): # Support my own proxy link
@@ -56,8 +60,24 @@ class FileEntry:
self._ext = splitext(urlsplit(qs['t'][0]).path)[1]
if self._ext == '':
self._ext = '.temp'
if self._config.send_origin_file_name:
self._usetempdir = True
self._tempdir = f"{time_ns()}{randint(0, 9999)}"
if ph.endswith('/RSSProxy'):
self._fn = basename(splitext(urlsplit(qs['t'][0]).path)[0])
if self._fn == '':
self._fn = basename(splitext(ph)[0])
if self._fn == '':
self._usetempdir = False
self._fn = self._tempdir
else:
self._fn = join(self._tempdir, self._fn)
else:
self._fn = f"{time_ns()}{randint(0, 9999)}"
self._fullfn = f"{self._fn}{self._ext}"
if self._usetempdir:
self._tempdir = abspath(join('Temp', self._tempdir))
mkdir(self._tempdir)
self._abspath = abspath(f'Temp/{self._fn}{self._ext}')
try:
self._r = get(url, stream=True)
@@ -69,8 +89,13 @@ class FileEntry:
self.ok = self._r.ok
except:
self.ok = False
self._fileSize = getsize(self._abspath)
self._fileExist = True if exists(self._abspath) else False
if not self._fileExist:
self._fileSize = 0
if self._usetempdir:
remove(self._tempdir)
else:
self._fileSize = getsize(self._abspath)
self._localURI = f"file://{self._abspath}" if self._abspath[0] == '/' else f"file:///{self._abspath}"
self._f = None
@@ -81,6 +106,8 @@ class FileEntry:
self._f.close()
try:
remove(self._abspath)
if self._usetempdir:
remove(self._tempdir)
self._fileExist = False
except:
pass
@@ -105,10 +132,10 @@ class FileEntries:
self.__list = []
self._value_lock = Lock()
def add(self, url: str) -> FileEntry:
def add(self, url: str, config: RSSConfig) -> FileEntry:
if self.has(url):
return self.get(url)
fileEntry = FileEntry(url, self._m)
fileEntry = FileEntry(url, self._m, config)
if fileEntry.ok and fileEntry._fileExist:
self.__list.append(fileEntry)
return fileEntry

133
rssbot.py
View File

@@ -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, getInlineKeyBoardForRSSSettingsInList
from rsslist import getInlineKeyBoardForRSSList, InlineKeyBoardForRSSList, getInlineKeyBoardForRSSInList, getTextContentForRSSInList, getInlineKeyBoardForRSSUnsubscribeInList, getTextContentForRSSUnsubscribeInList, getInlineKeyBoardForRSSSettingsInList, getInlineKeyBoardForRSSGlobalSettingsInList
from usercheck import checkUserPermissionsInChat, UserPermissionsInChatCheckResult
import sys
from fileEntry import FileEntries, remove
@@ -40,6 +40,7 @@ from time import sleep, time
from miraiDatabase import MiraiDatabase
from mirai import Mirai
from blackList import BlackList, InlineKeyBoardForBlackList, getInlineKeyBoardForBlackList, getTextContentForBlackInfo, getInlineKeyBoardForBlackInfo, getTextContentForUnbanBlackInfo, getInlineKeyBoardForUnbanBlackInfo, BlackInfo
from json import loads
MAX_ITEM_IN_MEDIA_GROUP = 10
@@ -72,6 +73,8 @@ def getMediaInfo(m: dict, config: RSSConfig = RSSConfig()) -> str:
s = f"{s}\n发送媒体:{config.send_media}"
s = f"{s}\n单独一行显示链接:{config.display_entry_link}"
s += f"\n发送图片为文件:{config.send_img_as_file}"
s += f"\nRSS全局设置:"
s += f"\n发送时使用原文件名:{config.send_origin_file_name}"
return s
@@ -90,9 +93,11 @@ class InlineKeyBoardCallBack(Enum):
SendMedia = 10
DisplayEntryLink = 11
SendImgAsFile = 12
GlobalSettingsPage = 13
SendOriginFileName = 14
def getInlineKeyBoardWhenRSS(hashd: str, m: dict) -> dict:
def getInlineKeyBoardWhenRSS(hashd: str, m: dict, isOwn: bool) -> dict:
d = []
i = 0
d.append([])
@@ -117,6 +122,10 @@ def getInlineKeyBoardWhenRSS(hashd: str, m: dict) -> dict:
i = i + 1
d[i].append(
{'text': '设置', 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.SettingsPage.value}'})
if isOwn:
d.append([])
i += 1
d[i].append({'text': 'RSS全局设置', 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.GlobalSettingsPage.value}'})
return {'inline_keyboard': d}
@@ -156,6 +165,17 @@ def getInlineKeyBoardWhenRSS2(hashd: str, config: RSSConfig) -> str:
return {'inline_keyboard': d}
def getInlineKeyBoardWhenRSS3(hashd: str, config: RSSConfig):
d = [[]]
i = 0
temp = '禁用发送时使用原文件名' if config.send_origin_file_name else '启用发送时使用原文件名'
d[i].append({'text': temp, 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.SendOriginFileName.value}'})
d.append([])
i += 1
d[i].append({'text': '返回', 'callback_data': f'0,{hashd},{InlineKeyBoardCallBack.BackToNormalPage.value}'})
return {'inline_keyboard': d}
class main:
def __init__(self):
pass
@@ -244,7 +264,7 @@ class main:
re = self._request('sendPhoto', 'post', json=di)
else:
fileEntry = self._tempFileEntries.add(
content['imgList'][0])
content['imgList'][0], config)
if not fileEntry.ok:
continue
should_use_file = False if fileEntry._fileSize < MAX_PHOTO_SIZE and not config.send_img_as_file else True
@@ -301,7 +321,7 @@ class main:
di['video'] = content['videoList'][0]['src']
else:
fileEntry = self._tempFileEntries.add(
content['videoList'][0]['src'])
content['videoList'][0]['src'], config)
if not fileEntry.ok:
continue
if self._setting.sendFileURLScheme:
@@ -315,7 +335,7 @@ class main:
di['thumb'] = content['videoList'][0]['poster']
else:
fileEntry = self._tempFileEntries.add(
content['videoList'][0]['poster'])
content['videoList'][0]['poster'], config)
if not fileEntry.ok:
continue
if self._setting.sendFileURLScheme:
@@ -410,7 +430,7 @@ class main:
if not self._setting.downloadMediaFile:
di2['media'] = i
else:
fileEntry = self._tempFileEntries.add(i)
fileEntry = self._tempFileEntries.add(i, config)
if not fileEntry.ok:
return None
should_use_file = False if fileEntry._fileSize < MAX_PHOTO_SIZE and not config.send_img_as_file else True
@@ -450,7 +470,7 @@ class main:
if not self._setting.downloadMediaFile:
di2['media'] = i['src']
else:
fileEntry = self._tempFileEntries.add(i['src'])
fileEntry = self._tempFileEntries.add(i['src'], config)
if not fileEntry.ok:
return None
if self._setting.sendFileURLScheme:
@@ -464,7 +484,7 @@ class main:
if not self._setting.downloadMediaFile:
di2['thumb'] = i['poster']
else:
fileEntry = self._tempFileEntries.add(i['poster'])
fileEntry = self._tempFileEntries.add(i['poster'], config)
if not fileEntry.ok:
return None
if self._setting.sendFileURLScheme:
@@ -749,7 +769,8 @@ class messageHandle(Thread):
print('未知的chat id')
return -1
self._fromUserId = self.__getFromUserId()
if self._main._blackList.isInBlackList(self._chatId) and not self._main._setting.botOwnerList.isOwner(self._fromUserId):
self._isOwn = self._main._setting.botOwnerList.isOwner(self._fromUserId)
if self._main._blackList.isInBlackList(self._chatId) and not self._isOwn:
c = self.__getChatType()
if c == 'private':
c = ''
@@ -891,7 +912,7 @@ class messageHandle(Thread):
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS(
self._hashd, metainfo.meta)
self._hashd, metainfo.meta, self._isOwn)
self._main._request('editMessageText', 'post', json=di)
self._main._db.setUserStatus(
self._fromUserId, userStatus.normalStatus)
@@ -1060,9 +1081,13 @@ class messageHandle(Thread):
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS(
self._hash, media)
self._hash, media, self._isOwn)
try:
conf = RSSConfig(loads(self._main._db.getRSSSettingsByUrl(self._uri)))
except Exception:
conf = None
self._main._rssMetaList.addRSSMeta(rssMetaInfo(
re['message_id'], chatId, media, p.itemList, self._hash))
re['message_id'], chatId, media, p.itemList, self._hash, conf))
self._main._request('editMessageText', 'post', json=di)
if self._botCommand == '/rsslist' and self._needCheckUser and re is not None and 'ok' in re and re['ok']:
messageInfo = re['result']
@@ -1118,6 +1143,7 @@ class callbackQueryHandle(Thread):
except:
self.answer('错误的按钮数据。')
return
self._isOwn = self._main._setting.botOwnerList.isOwner(self._fromUserId)
if self._loc == 0:
if 'message' not in self._data:
self.answer('找不到信息。')
@@ -1218,7 +1244,7 @@ class callbackQueryHandle(Thread):
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS(
self._hashd, self._rssMeta.meta)
self._hashd, self._rssMeta.meta, self._isOwn)
self._main._request("editMessageText", "post", json=di)
self.answer()
return
@@ -1242,7 +1268,7 @@ class callbackQueryHandle(Thread):
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS(
self._hashd, self._rssMeta.meta)
self._hashd, self._rssMeta.meta, self._isOwn)
self._main._request("editMessageText", "post", json=di)
self.answer()
return
@@ -1272,6 +1298,34 @@ class callbackQueryHandle(Thread):
self._main._request("editMessageText", "post", json=di)
self.answer()
return
if not self._isOwn:
self.answer('❌你没有权限操作,请与Bot主人进行PY交易以获得权限。')
return
if self._inlineKeyBoardCommand == InlineKeyBoardCallBack.GlobalSettingsPage:
di = {'chat_id': self._rssMeta.chatId,
'message_id': self._rssMeta.messageId}
di['text'] = getMediaInfo(
self._rssMeta.meta, self._rssMeta.config)
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS3(
self._hashd, self._rssMeta.config)
self._main._request("editMessageText", "post", json=di)
self.answer()
return
elif self._inlineKeyBoardCommand == InlineKeyBoardCallBack.SendOriginFileName:
self._rssMeta.config.send_origin_file_name = not self._rssMeta.config.send_origin_file_name
di = {'chat_id': self._rssMeta.chatId,
'message_id': self._rssMeta.messageId}
di['text'] = getMediaInfo(
self._rssMeta.meta, self._rssMeta.config)
di['parse_mode'] = 'HTML'
di['disable_web_page_preview'] = True
di['reply_markup'] = getInlineKeyBoardWhenRSS3(
self._hashd, self._rssMeta.config)
self._main._request("editMessageText", "post", json=di)
self.answer()
return
elif self._loc == 1:
chatId = int(self._inputList[1])
self._inlineKeyBoardForRSSListCommand = InlineKeyBoardForRSSList(
@@ -1487,11 +1541,60 @@ class callbackQueryHandle(Thread):
chatId, rss, ind, self._main._setting.botOwnerList.isOwner(self._fromUserId))
self._main._request("editMessageText", "post", json=di)
return
if not self._isOwn:
self.answer('❌你没有权限操作,请与Bot主人进行PY交易以获得权限。')
return
if self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.GlobalSettingsPage:
di = {'chat_id': self._data['message']['chat']['id'],
'message_id': self._data['message']['message_id']}
ind = int(self._inputList[3])
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(
rss, self._main._setting)
di['parse_mode'] = 'HTML'
di['reply_markup'] = getInlineKeyBoardForRSSGlobalSettingsInList(chatId, rss, ind)
self._main._request("editMessageText", "post", json=di)
self.answer()
return
elif self._inlineKeyBoardForRSSListCommand == InlineKeyBoardForRSSList.SendOriginFileName:
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(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
config.send_origin_file_name = not config.send_origin_file_name
updated = self._main._db.updateRSSSettings(rssEntry.id, config)
if updated:
self.answer('修改设置成功')
else:
self.answer('修改设置失败')
rss = self._main._db.getRSSByIdAndChatId(rssId, chatId)
if rss is None:
self.answer('找不到该RSS。')
return
di['text'] = getTextContentForRSSInList(
rss, self._main._setting)
di['parse_mode'] = 'HTML'
di['reply_markup'] = getInlineKeyBoardForRSSGlobalSettingsInList(chatId, rss, ind)
self._main._request("editMessageText", "post", json=di)
return
elif self._loc == 2:
if 'message' not in self._data:
self.answer('找不到信息。')
return
if self._fromUserId is None or not self._main._setting.botOwnerList.isOwner(self._fromUserId):
if self._fromUserId is None or not self._isOwn:
self.answer('❌你没有权限操作,请与Bot主人进行PY交易以获得权限。')
return
try:

View File

@@ -43,6 +43,8 @@ class InlineKeyBoardForRSSList(Enum):
ForceUpdate = 17
DisplayEntryLink = 18
SendImgAsFile = 19
GlobalSettingsPage = 20
SendOriginFileName = 21
def getTextContentForRSSInList(rssEntry: RSSEntry, s: settings) -> str:
@@ -74,6 +76,8 @@ def getTextContentForRSSInList(rssEntry: RSSEntry, s: settings) -> str:
text.addtotext(f"发送媒体:{config.send_media}")
text += f"单独一行显示链接:{config.display_entry_link}"
text += f"发送图片为文件:{config.send_img_as_file}"
text += f"RSS全局设置:"
text += f"发送时使用原文件名:{config.send_origin_file_name}"
return text.tostr()
@@ -142,6 +146,10 @@ def getInlineKeyBoardForRSSInList(chatId: int, rssEntry: RSSEntry, index: int, i
i = i + 1
d[i].append(
{'text': '设置', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SettingsPage.value},{index},{rssEntry.id}'})
if isOwner:
d.append([])
i += 1
d[i].append({'text': 'RSS全局设置', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.GlobalSettingsPage.value},{index},{rssEntry.id}'})
d.append([])
i = i + 1
d[i].append(
@@ -201,3 +209,21 @@ def getInlineKeyBoardForRSSSettingsInList(chatId: int, rssEntry: RSSEntry, index
d[i].append(
{'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToContentPage.value},{index},{rssEntry.id}'})
return {'inline_keyboard': d}
def getInlineKeyBoardForRSSGlobalSettingsInList(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:
temp = '禁用发送时使用原文件名' if config.send_origin_file_name else '启用发送时使用原文件名'
d.append([])
i += 1
d[i].append({'text': temp, 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.SendOriginFileName.value},{index},{rssEntry.id}'})
d.append([])
i += 1
d[i].append({'text': '返回', 'callback_data': f'1,{chatId},{InlineKeyBoardForRSSList.BackToContentPage.value},{index},{rssEntry.id}'})
return {'inline_keyboard': d}