Skip to content

Commit

Permalink
refactor: task
Browse files Browse the repository at this point in the history
  • Loading branch information
chen310 committed Jan 21, 2022
1 parent c8d69c4 commit 3ec5a94
Show file tree
Hide file tree
Showing 21 changed files with 517 additions and 369 deletions.
64 changes: 33 additions & 31 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@
/* 云贝任务,任务列表中有如下的任务时才触发 */
"yunbei_task": {
/* 分享歌单 */
"发布动态": {
"162005": {
"taskName": "发布动态",
"module": "publishEvent",
/* 是否开启任务 */
"enable": false,
"taskName": "发布动态",
/* 自定义要分享的歌单id,用逗号隔开,分享时随机选取一个,若为空,则从每日推荐歌单中随机选取 */
"id": [],
/* 自定义动态内容,用逗号隔开,分享时随机选取一个 */
Expand All @@ -113,16 +114,18 @@
"delete": true
},
/* 访问云音乐商城 */
"访问云音乐商城": {
"216002": {
"taskName": "访问云音乐商城",
"module": "visitMall",
/* 是否开启任务 */
"enable": true,
"taskName": "访问云音乐商城"
"enable": true
},
/* 云贝推歌 */
"云贝推歌": {
"200002": {
"taskName": "云贝推歌",
"module": "rcmdSong",
/* 是否开启任务 */
"enable": false,
"taskName": "云贝推歌",
/* 要推荐的歌曲id,随机选取一个,如[65528, 64634] */
"songId": [],
/* 推荐的云贝数量 */
Expand All @@ -135,10 +138,11 @@
]
},
/* 发布Mlog:根据填写的歌曲ID,自动下载歌曲的专辑图,并上传 */
"发布Mlog": {
"162006": {
"taskName": "发布Mlog",
"module": "publishMlog",
/* 是否开启任务 */
"enable": false,
"taskName": "发布Mlog",
/* 填写歌曲id,随机选取一个,如[65528, 64634] */
"songId": [],
/* 动态内容,随机选取一个,其中$artist会被替换为歌手名,$song会被替换为歌曲名 */
Expand All @@ -151,20 +155,25 @@
/* 发布成功后是否自动删除该动态 */
"delete": true
},
"分享歌曲/歌单": {
"166000": {
"taskName": "分享歌曲/歌单",
"module": "share",
/* 是否开启任务 */
"enable": false,
"taskName": "分享歌曲/歌单"
"enable": false
}
},
/* 音乐人任务,登录音乐人中心默认开启,其他按需开启 */
"musician_task": {
/* 登录音乐人中心 */
"登录音乐人中心": {
"399000": {
"taskName": "登录音乐人中心",
"module": "musicianSignin",
"enable": true
},
/* 发布3条动态 */
"发布动态": {
"398000": {
"taskName": "发布动态",
"module": "publishEvent",
"enable": false,
/* 自定义要分享的歌单id,用逗号隔开,分享时随机选取一个,若为空,则从每日推荐歌单中随机选取 */
"id": [],
Expand All @@ -177,7 +186,9 @@
/* 发布后自动删除 */
"delete": true
},
"发布主创说": {
"396002": {
"taskName": "发布主创说",
"module": "publishComment",
"enable": false,
/* []内填写你自己歌曲的id,如有多首用,隔开,随机挑选一首 */
"id": [],
Expand All @@ -188,7 +199,9 @@
/* 发布后自动删除 */
"delete": true
},
"回复粉丝评论": {
"393001": {
"taskName": "回复粉丝评论",
"module": "replyComment",
"enable": false,
/* []内填写你自己歌曲的id,如有多首用,隔开,随机挑选一首 */
"id": [],
Expand All @@ -199,7 +212,9 @@
/* 发布后自动删除 */
"delete": true
},
"回复粉丝私信": {
"395002": {
"taskName": "回复粉丝私信",
"module": "sendPrivateMsg",
"enable": false,
/* []内填写粉丝的用户id,如有多个用,隔开,随机挑选一个进行回复 */
"id": [],
Expand All @@ -210,20 +225,7 @@
}
},
/* VIP成长值任务 */
"vip_task": {
"创建共享歌单": {
/* 是否开启任务 */
"enable": false,
"taskName": "创建共享歌单",
/* 自定义歌单名,用逗号隔开,随机选取一个 */
"name": [
"歌单",
"我的歌单"
],
/* 创建成功后是否自动删除该动态 */
"delete": true
}
},
"vip_task": {},
/* 打卡刷歌 */
"daka": {
/* 是否开启任务 */
Expand Down
37 changes: 4 additions & 33 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,15 @@ def start(event={}, context={}):
user.setUser(user_config, user_setting)
if user.isLogined:
user.songnumber = songnumber.get(str(user.uid), -1)
user.userInfo()
user.startTask()

if user_setting['follow']:
user.follow()

if user_setting['sign']:
user.sign()

task_on = False
tasks = user_setting['yunbei_task']
for task in user_setting['yunbei_task']:
task_on = task_on or tasks[task]['enable']
if task_on:
user.yunbei_task()

user.get_yunbei()

if user.userType == 4:
user.musician_task()

if user.vipType == 11:
user.vip_task()

if user_setting['daka']['enable']:
if user_setting['daka']['auto'] == True and user.songnumber != -1:
user.auto_daka()
else:
user.daka()

if user_setting['other']['play_playlists']['enable']:
user.play_playlists()


for push in user_setting['push'].values():
if not push['enable']:
continue
data = {
'title': user.title,
'msg': user.msg,
'mdmsg': user.msg,
'textmsg': md2text(user.msg),
'config': push
}
pusher.append(data)
Expand Down Expand Up @@ -186,5 +156,6 @@ def main_handler(event, context):
return
start(event, context)


if __name__ == '__main__':
start()
3 changes: 2 additions & 1 deletion push/CoolPush.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def getKey(data):
return (config['module'], config['Skey'], config['method'])


def push(title, msg, config):
def push(title, mdmsg, textmsg, config):
msg = textmsg
skey = config['Skey']
method = config['method']
if len(skey) == 0 or len(method) == 0:
Expand Down
3 changes: 2 additions & 1 deletion push/Telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def getKey(data):
return (config['module'], config['userId'], config['botToken'])


def push(title, msg, config):
def push(title, mdmsg, textmsg, config):
msg = mdmsg
if len(config['userId']) == 0 or len(config['botToken']):
return

Expand Down
6 changes: 5 additions & 1 deletion push/WeCom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def get_token(corpid, corpsecret):
return None


def push(title, msg, config):
def push(title, mdmsg, textmsg, config):
msgtype = config['msgtype']
if msgtype == 'markdown':
msg = mdmsg
else:
msg = textmsg
if len(config['corpid']) == 0 or len(config['agentid']) == 0 or len(config['secret']) == 0:
return

Expand Down
3 changes: 2 additions & 1 deletion push/pushPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def getKey(data):
return (config['module'], config['pushToken'], config['topic'], config['template'])


def push(title, msg, config):
def push(title, mdmsg, textmsg, config):
msg = mdmsg
token = config['pushToken']
topic = config['topic']
template = config['template']
Expand Down
3 changes: 2 additions & 1 deletion push/serverChan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def getKey(data):
return (config['module'], config['KEY'])


def push(title, msg, config):
def push(title, mdmsg, textmsg, config):
msg = mdmsg
key = config['KEY']
if len(key) == 0:
return
Expand Down
10 changes: 6 additions & 4 deletions pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ def append(self, data):
return
# 是否合并推送
if not config['merge']:
exec('{}.push(data["title"], data["msg"], config)'.format(
exec('{}.push(data["title"], data["mdmsg"], data["textmsg"], config)'.format(
config['module']))
return

# 配置相同才会合并推送
key = eval('{}.getKey(data)'.format(config['module']))
if key is not None:
if key in self.datas:
self.datas[key]['msg'] += self.separator
self.datas[key]['msg'] += data['msg']
self.datas[key]['mdmsg'] += self.separator
self.datas[key]['mdmsg'] += data['mdmsg']
self.datas[key]['textmsg'] += self.separator
self.datas[key]['textmsg'] += data['textmsg']
else:
self.datas[key] = data

def push(self):
for data in self.datas.values():
exec('{}.push(data["title"], data["msg"], data["config"])'.format(
exec('{}.push(data["title"], data["mdmsg"], data["textmsg"], data["config"])'.format(
data['config']['module']))
34 changes: 29 additions & 5 deletions serverless/loadconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,42 @@ def migratePush(setting):
del setting[key]


def migrateTask(setting):
if 'yunbei_task' in setting:
yunbei_task = setting['yunbei_task']
kv = {'发布动态': '162005', '访问云音乐商城': '216002',
'云贝推歌': '200002', '发布Mlog': '162006', '分享歌曲/歌单': '166000'}
for key in kv:
if key in yunbei_task:
yunbei_task[kv[key]] = yunbei_task[key]
del yunbei_task[key]

if 'musician_task' in setting:
musician_task = setting['musician_task']
kv = {'登录音乐人中心': '399000', '发布动态': '398000',
'发布主创说': '396002', '回复粉丝评论': '393001', '回复粉丝私信': '395002'}
for key in kv:
if key in musician_task:
musician_task[kv[key]] = musician_task[key]
del musician_task[key]


def processSetting(setting):
if 'stopPushOnAPIGateway' in setting:
del setting['stopPushOnAPIGateway']
migratePush(setting)
migrateTask(setting)


def before(src, dst):
for user in src['users']:
if 'md5' in user:
del user['md5']
if 'setting' in user:
migratePush(user['setting'])
processSetting(user['setting'])

setting = src['setting']
migratePush(setting)

if 'stopPushOnAPIGateway' in setting:
del setting['stopPushOnAPIGateway']
processSetting(setting)

key_list = ['version', 'desp']
for key in key_list:
Expand Down
16 changes: 16 additions & 0 deletions task/createSharedPlaylist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import random


def start(user, task={}):
music = user.music
name = random.choice(task['name'])
create_resp = music.playlist_create(name, 0, 'SHARED')
if create_resp['code'] == 200:
if task['delete'] == True:
music.playlist_delete(
[create_resp.get('id', 0)])
user.taskInfo(task['taskName'], '歌单创建成功,已删除')
else:
user.taskInfo(task['taskName'], '歌单创建成功')
else:
user.taskInfo(task['taskName'], user.errMsg(create_resp))
8 changes: 8 additions & 0 deletions task/musicianSignin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def start(user, task={}):
music = user.music

resp = music.user_access()
if resp['code'] == 200:
user.taskInfo(task['taskName'], '登录成功')
else:
user.taskInfo(task['taskName'], user.errMsg(resp))
20 changes: 20 additions & 0 deletions task/publishComment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import random


def start(user, task={}):
music = user.music

if len(task['id']) > 0 and len(user.comments) == 0:
songId = random.choice(task['id'])
if len(task['msg']) > 0:
msg = random.choice(task['msg'])
else:
msg = '感谢大家收听'

resp = music.comments_add(songId, msg)
if resp['code'] == 200:
user.comments.append(
{'commentId': resp['comment']['commentId'], 'songId': songId})
user.taskInfo(task['taskName'], '发布成功')
else:
user.taskInfo(task['taskName'], user.errMsg(resp))
Loading

0 comments on commit 3ec5a94

Please sign in to comment.