diff --git a/config.example.json b/config.example.json index 0f5beb857..29be85ba7 100644 --- a/config.example.json +++ b/config.example.json @@ -88,7 +88,7 @@ /* TG机器人token */ "botToken": "", /* 是否将多个账号的信息合并推送 */ - "merge": true + "merge": false }, "Bark": { /* 项目地址: https://github.com/Finb/Bark */ diff --git a/index.py b/index.py index f27a8d0b7..5b1178e18 100644 --- a/index.py +++ b/index.py @@ -20,18 +20,10 @@ def md2text(data): - data = re.sub(r'\n\n', r'\n', data) data = re.sub(r'\[(.*?)\]\((.*?)\)', r'\1: \2 ', data) - data = re.sub(r'\t', r' ➢ ', data) - data = re.sub(r'\*\*(.*?)\*\*\n', r'【\1】\n', data) + data = re.sub(r'- ', r' •', data) + data = re.sub(r'#### (.*?)\n', r'【\1】\n\n', data) data = re.sub(r'### ', r'\n', data) - data = re.sub(r'`', r'', data) - return data - - -def md2fullMd(data): - data = re.sub(r'\*\*(.*?)\*\*\n', r'#### \1\n', data) - data = re.sub(r'\t', r'- ', data) return data @@ -91,8 +83,7 @@ def start(event={}, context={}): continue data = { 'title': user.title, - 'mdmsg': md2fullMd(user.msg), - 'mdmsg_compat': user.msg, + 'mdmsg': user.msg, 'textmsg': md2text(user.msg), 'config': push } diff --git a/push/Bark.py b/push/Bark.py index 8d076823c..5b3063aab 100644 --- a/push/Bark.py +++ b/push/Bark.py @@ -9,7 +9,7 @@ def getKey(data): return (config['module'], config['Bark_key'], config['Bark_url'], config['sound'], config['group'], config['icon']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msg = mdmsg Bark_key = config['Bark_key'] Bark_url = config['Bark_url'] diff --git a/push/CoolPush.py b/push/CoolPush.py index 95781c774..6cf3d7199 100644 --- a/push/CoolPush.py +++ b/push/CoolPush.py @@ -9,7 +9,7 @@ def getKey(data): return (config['module'], config['Skey'], config['method']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msg = textmsg skey = config['Skey'] method = config['method'] diff --git a/push/Telegram.py b/push/Telegram.py index 08493435b..c6b4ae880 100644 --- a/push/Telegram.py +++ b/push/Telegram.py @@ -9,9 +9,9 @@ def getKey(data): return (config['module'], config['userId'], config['botToken']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): #deprecate str.replace() funciton since Telegram support ** syntax to bold text. - msg = mdmsg_compat # .replace('**', '*') + msg = textmsg if len(config['userId']) == 0 or len(config['botToken']) == 0: return server = config['server'] @@ -21,7 +21,7 @@ def push(title, mdmsg, mdmsg_compat, textmsg, config): else: server = 'https://api.telegram.org' url = server + '/bot' + config['botToken'] + '/sendMessage' - ret = requests.post(url, data={'chat_id': config['userId'], 'text': msg, 'parse_mode': "Markdown"}, headers={ + ret = requests.post(url, data={'chat_id': config['userId'], 'text': msg}, headers={ 'Content-Type': 'application/x-www-form-urlencoded'}) print('Telegram response: \n', ret.status_code) if ret.status_code != 200: diff --git a/push/WeCom.py b/push/WeCom.py index 7928f90e7..0908b8f8c 100644 --- a/push/WeCom.py +++ b/push/WeCom.py @@ -25,7 +25,7 @@ def get_token(corpid, corpsecret): return None -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msgtype = config['msgtype'] if msgtype == 'markdown': msg = mdmsg diff --git a/push/pushPlus.py b/push/pushPlus.py index 400ebaf76..d2f1299f2 100644 --- a/push/pushPlus.py +++ b/push/pushPlus.py @@ -10,7 +10,7 @@ def getKey(data): return (config['module'], config['pushToken'], config['topic'], config['template']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msg = mdmsg token = config['pushToken'] topic = config['topic'] diff --git a/push/pushdeer.py b/push/pushdeer.py index d626210d7..21b2fdb11 100644 --- a/push/pushdeer.py +++ b/push/pushdeer.py @@ -10,7 +10,7 @@ def getKey(data): return (config['module'], config['pushkey'], config['server']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msg = mdmsg pushkey = config['pushkey'] if len(pushkey) == 0: diff --git a/push/serverChan.py b/push/serverChan.py index 0047d3efc..7c75d0df0 100644 --- a/push/serverChan.py +++ b/push/serverChan.py @@ -9,7 +9,7 @@ def getKey(data): return (config['module'], config['KEY']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): msg = mdmsg key = config['KEY'] if len(key) == 0: diff --git a/push/wxpusher.py b/push/wxpusher.py index 3491bae27..90e799732 100644 --- a/push/wxpusher.py +++ b/push/wxpusher.py @@ -8,7 +8,7 @@ def getKey(data): return (config['module'], config['APP_TOKEN'], config['UID']) -def push(title, mdmsg, mdmsg_compat, textmsg, config): +def push(title, mdmsg, textmsg, config): data = { "appToken": config['APP_TOKEN'], "content": mdmsg, diff --git a/pusher.py b/pusher.py index 18a6b1d1d..f2560fe6b 100644 --- a/pusher.py +++ b/pusher.py @@ -8,7 +8,7 @@ class Pusher(): def __init__(self): self.datas = {} - self.separator = '-------------------------\n' + self.separator = '-----------------------------------\n\n' def append(self, data): config = data['config'] @@ -17,7 +17,7 @@ def append(self, data): return # 是否合并推送 if not config['merge']: - exec('{}.push(data["title"], data["mdmsg"], data["mdmsg_compat"], data["textmsg"], config)'.format( + exec('{}.push(data["title"], data["mdmsg"], data["textmsg"], config)'.format( config['module'])) return @@ -25,7 +25,7 @@ def append(self, data): key = eval('{}.getKey(data)'.format(config['module'])) if key is not None: if key in self.datas: - for syntax in ['mdmsg', 'mdmsg_compat', 'textmsg']: + for syntax in ['mdmsg', 'textmsg']: self.datas[key][syntax] += self.separator self.datas[key][syntax] += data[syntax] else: @@ -33,5 +33,5 @@ def append(self, data): def push(self): for data in self.datas.values(): - exec('{}.push(data["title"], data["mdmsg"], data["mdmsg_compat"], data["textmsg"], data["config"])'.format( + exec('{}.push(data["title"], data["mdmsg"], data["textmsg"].strip(), data["config"])'.format( data['config']['module'])) diff --git a/user.py b/user.py index 36e1efe1a..1de4f77c5 100644 --- a/user.py +++ b/user.py @@ -175,19 +175,16 @@ def login_check(self, username, pwd='', cookie='', countrycode='', ip=''): return music def taskTitle(self, title): - msg = '**{}**\n'.format(title) - self.msg += msg + '\n' - print(msg) - def taskInfo(self, key, value='', useCodeblock = True): + self.msg += '#### ' + title + '\n' + print('#### ' + title) + + def taskInfo(self, key, value=''): if value == '': - msg = f"\t{str(key)}" - elif useCodeblock: - # Use `codeblock` to prevent markdown 's keywords containing in value which leads to 400 Bad Request - msg = f"\t{str(key)}: `{str(value)}`" + self.msg += '- ' + str(key) + '\n' + print('- ' + str(key)) else: - msg = f"\t{str(key)}: {str(value)}" - self.msg += msg + '\n' - print(msg) + self.msg += '- ' + str(key) + ': ' + str(value) + '\n' + print('- ' + str(key) + ': ' + str(value)) def finishTask(self): @@ -330,7 +327,7 @@ def auto_daka(self): self.taskInfo('听歌总数', str(resp['listenSongs']) + '首') if resp['listenSongs'] - self.songnumber < 300: self.taskInfo( - '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')', useCodeblock=False) + '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')') return else: total = 300 - (resp['listenSongs'] - self.songnumber) @@ -351,7 +348,7 @@ def auto_daka(self): self.taskInfo('听歌总数', str(resp['listenSongs']) + '首') if resp['listenSongs'] - self.songnumber < 300: self.taskInfo( - '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')', useCodeblock=False) + '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')') self.finishTask() def daka(self): @@ -415,7 +412,7 @@ def daka(self): self.taskInfo('听歌总数', str(resp['listenSongs']) + '首') if resp['listenSongs'] - self.listenSongs < 300: self.taskInfo( - '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')', useCodeblock=False) + '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')') return time.sleep(user_setting['daka']['sleep_time'] + 5) @@ -428,7 +425,7 @@ def daka(self): self.taskInfo('听歌总数', str(resp['listenSongs']) + '首') if resp['listenSongs'] - self.listenSongs < 300: self.taskInfo( - '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')', useCodeblock=False) + '温馨提示', '数据更新可能有延时,[点击查看最新数据](https://music.163.com/#/user/home?id='+str(self.uid)+')') self.finishTask() def play_playlists(self): @@ -530,7 +527,7 @@ def follow(self): self.taskInfo('感谢关注', author_nickname) # self.taskInfo('如果不想关注,请在配置文件里修改,并在官方客户端里取消关注') self.taskInfo( - '如果不想关注,请在配置文件里修改,并在[主页](https://music.163.com/#/user/home?id='+str(author_uid)+')里取消关注', useCodeblock=False) + '如果不想关注,请在配置文件里修改,并在[主页](https://music.163.com/#/user/home?id='+str(author_uid)+')里取消关注') self.finishTask() def sign(self):