From 26435018e38781896794a253785a801307b610b0 Mon Sep 17 00:00:00 2001 From: yjqiang Date: Sat, 27 Apr 2019 08:48:24 +0800 Subject: [PATCH] close #122 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 以及一些注释 --- conf/ctrl.sample.toml | 19 ++++++++++++++----- run.py | 12 +++++++++--- user.py | 3 ++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/conf/ctrl.sample.toml b/conf/ctrl.sample.toml index f4e9665..6918215 100644 --- a/conf/ctrl.sample.toml +++ b/conf/ctrl.sample.toml @@ -1,8 +1,10 @@ -[print_control] +[print_control] # 打印 # 控制default_monitor_roomid所指认的room弹幕打印(pythonista ios可以彩打哦) danmu = false -[task_control] + + +[global_task_control] # 总体的task控制 # 清理即将过期礼物,请true之后一定要把紧随其后的clean-expiring-gift2room设置为真实房间号 clean-expiring-gift = false # 单位秒,这是控制定义过期礼物何时为“过期”的阈值 @@ -16,7 +18,7 @@ silver2coin = false # 自动投满佩戴勋章当日亲密度 send2wearing-medal = false -# 短房间号(与投满亲密度send2wearing-medal的一起使用) +# 短房间号(与投满亲密度send2wearing-medal的一起使用)。注意⚠️如果只需要投佩戴的勋章,不用修改send2medal send2medal = [] # 输入数字 0-5 表示主站每日自动投币 @@ -26,12 +28,19 @@ fetchrule = "bilitop" # up主list([123]或者[123, 234, 123]等) mid = [ 207539637,] -[dyn_raffle] # 抽奖@的人,格式为 uid = "用户名"(例如 {332704117 = "白上吹雪Official", 339567211 = "赤井心Official"}) # 要求被@的人不能经常改名字,这样也就说明这些用户也可控,即不得随意骚扰他人 dyn_lottery_friends = {} -[other_control] + + +[custom_task_control] # 与global_task_control对应。针对某个具体用户的自定义(如果用户没有自定义的部分,就使用前面global那里的配置) + [custom_task_control.username] # sub-table({'custom_task_control': {'user0': {}, 'user1': {}}}),name与user.toml内的相同 + givecoin = 5 + + + +[other_control] # 其他细节控制 # 默认监听房间号(用于打印弹幕功能等) default_monitor_roomid = 23058 diff --git a/run.py b/run.py index 1abc1e2..c7120c6 100644 --- a/run.py +++ b/run.py @@ -38,11 +38,17 @@ dict_ctrl = conf_loader.read_ctrl() printer.init_config(dict_color, dict_ctrl['print_control']['danmu']) +# user设置 users = [] -task_control = dict_ctrl['task_control'] -dyn_lottery_friends = [(str(uid), name) for uid, name in dict_ctrl['dyn_raffle']['dyn_lottery_friends'].items()] +global_task_control = dict_ctrl['global_task_control'] +custom_task_control = dict_ctrl['custom_task_control'] for i, user_info in enumerate(dict_user['users']): - users.append(User(i, user_info, task_control, dict_bili, dyn_lottery_friends)) + username = user_info['username'] + if username in custom_task_control: + task_control = {**global_task_control, **custom_task_control[username]} + else: + task_control = global_task_control + users.append(User(i, user_info, task_control, dict_bili)) notifier.set_values(loop) notifier.set_users(users) diff --git a/user.py b/user.py index 15645fb..e9e855d 100644 --- a/user.py +++ b/user.py @@ -11,7 +11,7 @@ class User: - def __init__(self, id, dict_user, task_ctrl, dict_bili, dyn_lottery_friends): + def __init__(self, id, dict_user, task_ctrl, dict_bili): self.id = id self.name = dict_user['username'] self.password = dict_user['password'] @@ -27,6 +27,7 @@ def __init__(self, id, dict_user, task_ctrl, dict_bili, dyn_lottery_friends): self.update_login_data(dict_user) self.list_delay = [] self.repost_del_lock = asyncio.Lock() # 在follow与unfollow过程中必须保证安全(repost和del整个过程加锁) + dyn_lottery_friends = [(str(uid), name) for uid, name in task_ctrl['dyn_lottery_friends'].items()] self.dyn_lottery_friends = dyn_lottery_friends # list (uid, name) self.storm_lock = asyncio.Semaphore(1) # 用于控制同时进行的风暴数目(注意是单个用户的)