forked from rabbit2rabbit/bili2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_status.py
150 lines (122 loc) · 4 KB
/
user_status.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from datetime import datetime
from tasks.tv_raffle_handler import TvRaffleHandlerTask
from tasks.guard_raffle_handler import GuardRaffleHandlerTask
from tasks.live_daily_job import (
HeartBeatTask,
RecvHeartGiftTask,
OpenSilverBoxTask,
RecvDailyBagTask,
SignTask,
WatchTvTask,
SignFansGroupsTask,
SendGiftTask,
ExchangeSilverCoinTask,
)
from tasks.main_daily_job import (
JudgeCaseTask,
BiliMainTask
)
# 1 延迟操作,返回一个参考延迟范围
# 2 放弃操作
# 时间状态
class FreeStatus:
@staticmethod
def check_status(func):
# print('是个自由人')
return 0, None
class JailStatus:
dict_jail_status = {
RecvHeartGiftTask.recv_heartgift: 1,
OpenSilverBoxTask.open_silver_box: 1,
TvRaffleHandlerTask.join: 2,
GuardRaffleHandlerTask.join: 2,
}
@staticmethod
def check_status(func):
# print('进了监狱')
strategy = JailStatus.dict_jail_status.get(func, 0)
if strategy == 1:
return strategy, 1800
return strategy, None
# 工作状态类
class DayStatus:
@staticmethod
def check_status(func):
# print("工作,精神百倍")
return 0, None
class NightStatus:
dict_night_status = {
HeartBeatTask.heart_beat: 1,
RecvHeartGiftTask.recv_heartgift: 1,
OpenSilverBoxTask.open_silver_box: 1,
RecvDailyBagTask.recv_dailybag: 1,
SignTask.sign: 1,
WatchTvTask.watch_tv: 1,
SignFansGroupsTask.sign_groups: 1,
SendGiftTask.send_gift: 1,
ExchangeSilverCoinTask.silver2coin: 1,
JudgeCaseTask.judge: 1,
BiliMainTask.finish_bilimain_tasks: 1,
TvRaffleHandlerTask.check: 2,
GuardRaffleHandlerTask.check: 2,
}
@staticmethod
def check_status(func):
# print("睡觉了")
strategy = NightStatus.dict_night_status.get(func, 0)
if strategy == 1:
now = datetime.now()
# 7点时候
sleeptime = (7 - now.hour - 1) * 3600 + (59 - now.minute) * 60 + 60 - now.second
return 1, sleeptime
return strategy, None
class LoginStatus:
@staticmethod
def check_status():
# print('因为已经正常登陆')
return True
class LogoutStatus:
@staticmethod
def check_status():
# print('因为未正常登陆')
return False
class UserStatus:
def __init__(self, user):
self.time_status = DayStatus
self.work_status = FreeStatus
self.log_status = LoginStatus
self.user = user
def sleep(self):
# print('{休眠}')
self.time_status = NightStatus
def wakeup(self):
# print('{起床}')
self.time_status = DayStatus
def go_to_jail(self):
# print('{入狱}')
self.work_status = JailStatus
def out_of_jail(self):
# print('{自由}')
self.work_status = FreeStatus
def logout(self):
# print('{未登陆}')
self.log_status = LogoutStatus
def login(self):
# print('{已经登陆}')
self.log_status = LoginStatus
def print_status(self):
work_status = '恭喜中奖' if self.work_status == JailStatus else '自由之身'
time_status = '白天工作' if self.time_status == DayStatus else '夜晚休眠'
self.user.infos([f'小黑屋状态: {work_status}'])
self.user.infos([f'工作状态: {time_status}'])
def check_status(self, func):
code, sleeptime = self.time_status.check_status(func)
# print('初次code', code)
if not code:
code, sleeptime = self.work_status.check_status(func)
# print(code, sleeptime)
return code, sleeptime
def check_log_status(self):
# print('正在检查', request)
code = self.log_status.check_status()
return code