Skip to content

Commit

Permalink
控制与users文件分离
Browse files Browse the repository at this point in the history
加了注释
  • Loading branch information
yjqiang committed Feb 9, 2019
1 parent e85b836 commit e9266dc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
35 changes: 35 additions & 0 deletions conf/ctrl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[print_control]
# 控制default_monitor_roomid所指认的room弹幕打印(pythonista ios可以彩打哦)
danmu = false

[task_control]
# 清理即将过期礼物,请true之后一定要把紧随其后的clean-expiring-gift2room设置为真实房间号
clean-expiring-gift = false
# 单位秒
set-expiring-time = 0
# 对过期礼物是否优先投递到其他勋章(按照勋章等级由大到小顺序投递),之后会剩余的清理掉至clean-expiring-gift2room
clean_expiring_gift2all_medal = false
clean-expiring-gift2room = 0

# 一天最多一个硬币兑换机会
silver2coin = false

# 自动投满佩戴勋章当日亲密度
send2wearing-medal = false
# 短房间号(与投满亲密度send2wearing-medal的一起使用)
send2medal = []

# 输入数字 0-5 表示主站每日自动投币
givecoin = 0
# av获取(bilitop或者uper)分别代表b站随机或者根据up主mid选取
fetchrule = "bilitop"
# up主list([123]或者[123, 234, 123]等)
mid = [ 207539637,]

[other_control]
# 默认监听房间号(打印弹幕)
default_monitor_roomid = 23058
# 额外自定义弹幕监控房间(比如yj协同大航海等自定义,0会不启动)
raffle_minitor_roomid = 0
# 固定的直播分区设置
area_ids = [ 1, 2, 3, 4, 5, 6,]
19 changes: 0 additions & 19 deletions conf/user.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,3 @@ csrf = ""
uid = ""
refresh_token = ""

[print_control]
danmu = false

[task_control]
clean-expiring-gift = false
set-expiring-time = 0
clean_expiring_gift2all_medal = false
clean-expiring-gift2room = 0
silver2coin = false
send2wearing-medal = false
send2medal = []
givecoin = 0
fetchrule = "bilitop"
mid = [ 207539637,]

[other_control]
default_monitor_roomid = 23058
raffle_minitor_roomid = 0
area_ids = [ 1, 2, 3, 4, 5, 6,]
24 changes: 16 additions & 8 deletions conf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ def rgb_to_percent(list_rgb):


class ConfLoader():
def set_path(self, file_color, file_user, file_bili):
self.file_color = file_color
self.file_user = file_user
self.file_bili = file_bili
def set_path(self, root_path):
self.file_color = f'{root_path}/conf/color.toml'
self.file_user = f'{root_path}/conf/user.toml'
self.file_bili = f'{root_path}/conf/bili.toml'
self.file_ctrl = f'{root_path}/conf/ctrl.toml'

'''
self.dict_color = self.read_color()
Expand Down Expand Up @@ -59,15 +60,17 @@ def read_user(self):
dict_user = toml.load(f)
return dict_user

def read_ctrl(self):
with open(self.file_ctrl, encoding="utf-8") as f:
dict_ctrl = toml.load(f)
return dict_ctrl


var = ConfLoader()


def set_path(root_path):
file_color = f'{root_path}/conf/color.toml'
file_user = f'{root_path}/conf/user.toml'
file_bili = f'{root_path}/conf/bili.toml'
var.set_path(file_color, file_user, file_bili)
var.set_path(root_path)


def write_user(dict_new, user_id):
Expand All @@ -84,3 +87,8 @@ def read_color():

def read_user():
return var.read_user()


def read_ctrl():
return var.read_ctrl()

11 changes: 6 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
dict_user = conf_loader.read_user()
dict_bili = conf_loader.read_bili()
dict_color = conf_loader.read_color()
printer.init_config(dict_color, dict_user['print_control']['danmu'])
area_ids = dict_user['other_control']['area_ids']
dict_ctrl = conf_loader.read_ctrl()
printer.init_config(dict_color, dict_ctrl['print_control']['danmu'])
area_ids = dict_ctrl['other_control']['area_ids']

users = []
task_control = dict_user['task_control']
task_control = dict_ctrl['task_control']
for i, user_info in enumerate(dict_user['users']):
users.append(User(i, user_info, task_control, dict_bili))

Expand All @@ -59,10 +60,10 @@

danmu_tasks = [connect.RaffleConnect(i).run() for i in area_ids]

yj_danmu_roomid = dict_user['other_control']['raffle_minitor_roomid']
yj_danmu_roomid = dict_ctrl['other_control']['raffle_minitor_roomid']
danmu_tasks.append(connect.YjConnection(yj_danmu_roomid).run())

default_monitor_roomid = dict_user['other_control']['default_monitor_roomid']
default_monitor_roomid = dict_ctrl['other_control']['default_monitor_roomid']
connect.init_danmu_roomid(default_monitor_roomid)
danmu_tasks.append(connect.run_danmu())

Expand Down

0 comments on commit e9266dc

Please sign in to comment.