async def check(real_roomid, raffle_id=None): if not await Utils.is_normal_room(real_roomid): return if raffle_id is not None: data = {"data": [{"id": raffle_id, "time": 65}]} else: for i in range(10): data = await BasicRequest.guard_req_check(real_roomid) if data["data"]: break await asyncio.sleep(1) else: Log.warning("%s 没有guard或guard已领取" % real_roomid) return list_available_raffleid = [] for j in data["data"]: raffle_id = j["id"] if not Statistics.is_raffleid_duplicate(raffle_id): Log.raffle("本次获取到的 大航海 抽奖id为 %s" % raffle_id) list_available_raffleid.append(raffle_id) Statistics.add2raffle_ids(raffle_id) tasklist = [] num_available = len(list_available_raffleid) for raffle_id in list_available_raffleid: task = asyncio.ensure_future(GuardRaffleHandler.join(num_available, real_roomid, raffle_id)) tasklist.append(task) if tasklist: raffle_results = await asyncio.gather(*tasklist) if False in raffle_results: Log.error("繁忙提示,稍后重新尝试") RaffleHandler.push2queue((real_roomid,), GuardRaffleHandler.check)
async def check(real_roomid): if not await Utils.is_normal_room(real_roomid): return data = await BasicRequest.gift_req_check(real_roomid) list_available_raffleid = [] checklen = data["data"]["pk"] try: if len(checklen) == 0: Log.error("检测到无效的大乱斗抽奖") return for j in checklen: raffle_id = j["id"] Log.raffle("本次获取到的 大乱斗 抽奖id为 %s" % raffle_id) list_available_raffleid.append(raffle_id) except: Log.error("检测到无效的大乱斗抽奖") return tasklist = [] for raffle_id in list_available_raffleid: task = asyncio.ensure_future( PkRaffleHandler.join(real_roomid, raffle_id)) tasklist.append(task) if tasklist: raffle_results = await asyncio.gather(*tasklist) if False in raffle_results: Log.error("繁忙提示,稍后重新尝试") RaffleHandler.push2queue((real_roomid, ), PkRaffleHandler.check)
def handle_message(self, data): cmd = data["category"] raffle_name = data["name"] raffle_id = data["id"] room_id = data["roomid"] expireAt = data["expireAt"] # 大航海 if cmd == "guard": if config["Raffle_Handler"]["GUARD"] != "False": Log.raffle("监控服务器检测到 %s 的 %s" % (room_id, raffle_name)) RaffleHandler.push2queue((room_id,), GuardRaffleHandler.check) # 如果不是总督就设置为2(本房间) broadcast_type = 0 if raffle_name == "总督" else 2 Statistics.add2pushed_raffles(raffle_name, broadcast_type) # PK(WIP) elif cmd == "pk": if config["Raffle_Handler"]["PK"] != "False": Log.raffle("监控服务器检测到 %s 的 %s" % (room_id, raffle_name)) RaffleHandler.push2queue((room_id,), PkRaffleHandler.check) Statistics.add2pushed_raffles(raffle_name, 1) # 节奏风暴 elif cmd == "storm": if config["Raffle_Handler"]["STORM"] != "False": Log.raffle("监控服务器检测到 %s 的 %s" % (room_id, raffle_name)) RaffleHandler.push2queue((room_id,), StormRaffleHandler.check) Statistics.add2pushed_raffles(raffle_name, 1) # 天选 elif cmd == "anchor": if config["Raffle_Handler"]["ANCHOR"] != "False": Log.raffle("监控服务器检测到 %s 的 天选时刻, 奖品为: %s" % (room_id, raffle_name)) RaffleHandler.push2queue((room_id, raffle_name, raffle_id, expireAt), AnchorRaffleHandler.join) Statistics.add2pushed_raffles("天选时刻", 1)
def handle_danmu(self, body): data = json.loads(body.decode("utf-8")) cmd = data["cmd"] if cmd == "PREPARING": Log.info("%s 号弹幕监控下播 %s" % (self._area_id, self._room_id)) return False elif cmd == "NOTICE_MSG": # 1 《第五人格》哔哩哔哩直播预选赛六强诞生! # 2 全区广播:<%user_name%>送给<%user_name%>1个嗨翻全城,快来抽奖吧 # 3 <%user_name%> 在 <%user_name%> 的房间开通了总督并触发了抽奖,点击前往TA的房间去抽奖吧 # 4 欢迎 <%总督 user_name%> 登船 # 5 恭喜 <%user_name%> 获得大奖 <%23333x银瓜子%>, 感谢 <%user_name%> 的赠送 # 6 <%user_name%> 在直播间 <%529%> 使用了 <%20%> 倍节奏风暴,大家快去跟风领取奖励吧!(只报20的) msg_type = data["msg_type"] msg_common = data["msg_common"] real_roomid = data["real_roomid"] msg_common = data["msg_common"].replace(" ", "") msg_common = msg_common.replace("“", "") msg_common = msg_common.replace("”", "") for each in ["~", "点击前往TA的直播间抽奖吧!", "快来抽奖吧!", "继续进击小电视地图哦!", "完成今日", "啦"]: msg_common = msg_common.replace(each, "") # 小电视,DokiDoki,摩天大楼之类的抽奖活动 if msg_type == 2 or msg_type == 8: str_gift = msg_common.split('%>')[-1].split(',')[0] if "个" in str_gift: raffle_num, raffle_name = str_gift.split("个") elif "了" in str_gift: raffle_num = 1 raffle_name = str_gift.split("了")[-1] else: raffle_num = 1 raffle_name = str_gift broadcast = '' # This method is abandoned if config["Raffle_Handler"]["TV"] != "False": Log.raffle("%s 号弹幕监控检测到 %s 的 %s 个 %s" % (self._area_id, real_roomid, raffle_num, raffle_name)) RaffleHandler.push2queue((real_roomid, raffle_name,), TvRaffleHandler.check) # 如果不是全区就设置为1(分区) broadcast_type = 0 if broadcast == '全区' else 1 Statistics.add2pushed_raffles('小电视类', broadcast_type, raffle_num) # 大航海 elif msg_type == 3: raffle_name = msg_common.split("开通了")[-1][:2] if config["Raffle_Handler"]["GUARD"] != "False": Log.raffle("%s 号弹幕监控检测到 %s 的 %s" % (self._area_id, real_roomid, raffle_name)) RaffleHandler.push2queue((real_roomid,), GuardRaffleHandler.check) # 如果不是总督就设置为2(本房间) broadcast_type = 0 if raffle_name == "总督" else 2 Statistics.add2pushed_raffles(raffle_name, broadcast_type) # 节奏风暴 elif msg_type == 6: raffle_name = "二十倍节奏风暴" if config["Raffle_Handler"]["STORM"] != "False": Log.raffle("%s 号弹幕监控检测到 %s 的 %s" % (self._area_id, real_roomid, raffle_name)) RaffleHandler.push2queue((real_roomid,), StormRaffleHandler.check) Statistics.add2pushed_raffles(raffle_name) return True
async def inspectRoom(self): room = self.queue.pop() if not await Utils.is_normal_room(room): return data = await BasicRequest.gift_req_check(room) if data["data"]["guard"]: Log.raffle("检测到%s房间的大航海" % (room)) RaffleHandler.push2queue((room,), GuardRaffleHandler.check) if data["data"]["pk"]: Log.raffle("检测到%s房间的大乱斗" % (room)) RaffleHandler.push2queue((room), PkRaffleHandler.check) if data["data"]["gift"]: Log.raffle("检测到%s房间的活动抽奖" % (room)) RaffleHandler.push2queue((room, ""), TvRaffleHandler.check)
from MatchTask import MatchTask # 初始化所有class API = API() Auth = Auth() Capsule = Capsule() CaseJudger = CaseJudger() Coin2Silver = Coin2Silver() DailyBag = DailyBag() GiftSend = GiftSend() Group = Group() Heart = Heart() Silver2Coin = Silver2Coin() SilverBox = SilverBox() Task = Task() rafflehandler = RaffleHandler() MainDailyTask = MainDailyTask() MatchTask = MatchTask() MonitorServer = MonitorServer(config["Server"]["ADDRESS"], config["Server"]["PASSWORD"]) parser = OptionParser() parser.add_option("-d", "--disable-console", action="store_true", dest="disable_console", default=False, help="disable console") (options, args) = parser.parse_args() # 开启时清理日志 Log.clean_log(startup=True) def signal_handler(signal, frame): os._exit(0)
from Task import Task from Sentence import Sentence from Timer import Timer from config import config # 初始化所有class Auth = Auth() Capsule = Capsule() Coin2Silver = Coin2Silver() GiftSend = GiftSend() Group = Group() Heart = Heart() Silver2Coin = Silver2Coin() SilverBox = SilverBox() Task = Task() rafflehandler = RaffleHandler() if config["Other"]["INFO_MESSAGE"] != "False": Log.info("BiliBiliHelper Python Version Beta 0.0.1") if config["Other"]["SENTENCE"] != "False": Log.info(Sentence().get_sentence()) loop = asyncio.get_event_loop() timer = Timer(loop) console = Console.Console(loop) area_ids = [ 1, 2, 3,
from CaseJudger import CaseJudger # 初始化所有class API = API() Auth = Auth() Capsule = Capsule() CaseJudger = CaseJudger() Coin2Silver = Coin2Silver() DailyBag = DailyBag() GiftSend = GiftSend() Group = Group() Heart = Heart() Silver2Coin = Silver2Coin() SilverBox = SilverBox() Task = Task() rafflehandler = RaffleHandler() MonitorServer = MonitorServer(config["Server"]["ADDRESS"], config["Server"]["PASSWORD"]) parser = OptionParser() parser.add_option("-d", "--disable-console", action="store_true", dest="disable_console", default=False, help="disable console") (options, args) = parser.parse_args() def main(): # 开启时清理日志