-
Notifications
You must be signed in to change notification settings - Fork 7
/
charge.py
103 lines (95 loc) · 4.54 KB
/
charge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import json
import base64
import random
setting = True
def pic_to_b64(pic_path:str) -> str:
with open(pic_path,'rb') as f:
base64_str = base64.b64encode(f.read()).decode()
return 'base64://' + base64_str
def get_img(good):
if good:
img_path = os.path.join(os.path.dirname(__file__),'image',"good")
else:
img_path = os.path.join(os.path.dirname(__file__),'image',"bad")
image_name = random.choice(os.listdir(img_path))
base64_str = pic_to_b64(f"{img_path}/{image_name}")
img =f'[CQ:image,file={base64_str}]'
return img
def read_json():
current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
file = open(current_dir, 'r', encoding = 'UTF-8')
config = json.load(file)
return config
def random_choice(list):
return random.choice(list)
# 康康当前配置
def get_current_json():
config = read_json()
msg = '超级管理员配置的早安晚安设置如下:'
# morning_config
get_up_intime = config['morning']['get_up_intime']['enable']
if get_up_intime:
msg = msg + '\n是否要求规定时间内起床:是\n - 最早允许起床时间:' + str(config['morning']['get_up_intime']['early_time']) + '点\n - 最晚允许起床时间:' + str(config['morning']['get_up_intime']['late_time']) + '点'
else:
msg = msg + '\n是否要求规定时间内起床:否'
multi_get_up = config['morning']['multi_get_up']['enable']
if multi_get_up:
msg = msg + '\n是否允许连续多次起床:是'
else:
msg = msg + '\n是否允许连续多次起床:否\n - 允许的最短起床间隔:' + str(config['morning']['multi_get_up']['interval']) + '小时'
super_get_up = config['morning']['super_get_up']['enable']
if super_get_up:
msg = msg + '\n是否允许超级亢奋(即睡眠时长很短):是'
else:
msg = msg + '\n是否允许超级亢奋(即睡眠时长很短):否\n - 允许的最短睡觉时长:' + str(config['morning']['super_get_up']['interval']) + '小时'
# night_config
sleep_intime = config['night']['sleep_intime']['enable']
if sleep_intime:
msg = msg + '\n是否要求规定时间内睡觉:是\n - 最早允许睡觉时间:' + str(config['night']['sleep_intime']['early_time']) + '点\n - 最晚允许睡觉时间:第二天早上' + str(config['night']['sleep_intime']['late_time']) + '点'
else:
msg = msg + '\n是否要求规定时间内睡觉:否'
multi_sleep = config['night']['multi_sleep']['enable']
if multi_sleep:
msg = msg + '\n是否允许连续多次睡觉:是'
else:
msg = msg + '\n是否允许连续多次睡觉:否\n - 允许的最短睡觉间隔:' + str(config['night']['multi_sleep']['interval']) + '小时'
super_sleep = config['night']['super_sleep']['enable']
if super_sleep:
msg = msg + '\n是否允许超级睡眠(即清醒时长很短):是 '
else:
msg = msg + '\n是否允许超级睡眠(即清醒时长很短):否\n - 允许的最短清醒时长:' + str(config['night']['super_sleep']['interval']) + '小时'
return msg
# 开启或关闭
def change_settings(day_or_night, server, enable):
try:
_current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
config = read_json()
config[day_or_night][server]['enable'] = enable
with open(_current_dir, "w", encoding="UTF-8") as f:
f.write(json.dumps(config, ensure_ascii=False, indent=4))
msg = '配置更新成功!'
except Exception as e:
msg = f'配置更新失败!错误原因{e}'
return msg
# 更改时间或间隔
def change_set_time(*args):
try:
_current_dir = os.path.join(os.path.dirname(__file__), 'config.json')
config = read_json()
day_or_night = args[0]
server = args[1]
if server == 'get_up_intime' or server == 'sleep_intime':
early_time = args[2]
late_time = args[3]
config[day_or_night][server]['early_time'] = early_time
config[day_or_night][server]['late_time'] = late_time
else:
interval = args[2]
config[day_or_night][server]['interval'] = interval
with open(_current_dir, "w", encoding="UTF-8") as f:
f.write(json.dumps(config, ensure_ascii=False, indent=4))
msg = '配置更新成功!'
except Exception as e:
msg = f'配置更新失败!错误原因{e}'
return msg