This commit is contained in:
2021-01-08 22:14:44 +08:00
parent 8073c008ff
commit e5287760c2
3 changed files with 21 additions and 3 deletions

View File

@@ -34,3 +34,4 @@ class settings:
self._maxTTL = int(d['maxTTL']) if 'maxTTL' in d and d['maxTTL'].isnumeric(
) and int(d['maxTTL']) >= self._minTTL else max(1440, self._minTTL)
self._maxRetryCount = int(d['maxRetryCount']) if 'maxRetryCount' in d and d['maxRetryCount'].isnumeric() and int(d['maxRetryCount']) >= 0 else 3
self._telegramBotApiServer = d['telegramBotApiServer'] if 'telegramBotApiServer' in d else 'https://api.telegram.org'

View File

@@ -135,10 +135,10 @@ class main:
def __init__(self):
pass
def _request(self, methodName: str, HTTPMethod: str = 'get', data: dict = None, json: dict = None, files: dict = None, returnType: str = 'json'):
def _request(self, methodName: str, HTTPMethod: str = 'get', data: dict = None, json: dict = None, files: dict = None, returnType: str = 'json', telegramBotApiServer: str = None):
try:
r = self._r.request(
HTTPMethod, f'https://api.telegram.org/bot{self._setting._token}/{methodName}', data=data, json=json, files=files)
HTTPMethod, f'{self._telegramBotApiServer if telegramBotApiServer is None else telegramBotApiServer}/bot{self._setting._token}/{methodName}', data=data, json=json, files=files)
if r.status_code != 200:
return None
if returnType == 'json':
@@ -240,6 +240,10 @@ class main:
if self._setting._token is None:
print('没有机器人token')
return -1
self._telegramBotApiServer = self._setting._telegramBotApiServer
if self._telegramBotApiServer != 'https://api.telegram.org':
self._request("logOut", "post",
telegramBotApiServer="https://api.telegram.org")
self._db = database(self)
if not exists('settings.txt'):
print('找不到settings.txt')

View File

@@ -30,11 +30,15 @@ class InlineKeyBoardForRSSList(Enum):
Close = 4
Content = 5
BackToList = 6
Unsubscribe = 7
ConfirmUnsubscribe = 8
CancleUnsubscribe = 9
def getTextContentForRSSInList(rssEntry: RSSEntry) -> str:
text = textc()
text.addtotext(f"""<a href="{rssEntry.url}">{rssEntry.title}</a>""")
text.addtotext(
f"""<a href="{rssEntry.url}">{escape(rssEntry.title)}</a>""")
temp = '更新间隔:未知' if rssEntry.interval is None else f'更新间隔:{rssEntry.interval}'
text.addtotext(temp)
temp = '上次更新时间:未知' if rssEntry.lastupdatetime is None or rssEntry.lastupdatetime < 0 else f'上次更新时间:{timeToStr(rssEntry.lastupdatetime)}'
@@ -51,6 +55,10 @@ def getTextContentForRSSInList(rssEntry: RSSEntry) -> str:
return text.tostr()
def getTextContentForRSSUnsubscribeInList(rssEntry: RSSEntry) -> str:
return f"""你是否要取消订阅<a href="{rssEntry.url}">{escape(rssEntry.title)}</a>?"""
def getInlineKeyBoardForRSSList(chatId: int, RSSEntries: List[RSSEntry], page: int = 1, lastPage: bool = False, itemIndex: int = None) -> dict:
d = []
i = -1
@@ -100,6 +108,11 @@ def getInlineKeyBoardForRSSInList(chatId: int, rssEntry: RSSEntry, index: int) -
d = []
i = -1
d.append([])
i = i + 1
d[i].append(
{'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.BackToList.value},{index}'})
return {'inline_keyboard': d}