Beispiel #1
0
    def handle_danmu(self, dic):
        cmd = dic['cmd']

        if cmd == 'PREPARING':
            printer.info([f'{self.area_id}号弹幕监控房间下播({self.roomid})'], True)
            return False
        elif cmd == 'SYS_GIFT':
            if 'giftId' in dic:
                if dic['giftId'] == 39:
                    pass
                    '''
                    printer.info(["节奏风暴"], True)
                    temp = await bilibili.get_giftlist_of_storm(dic)
                    check = len(temp['data'])
                    if check != 0 and temp['data']['hasJoin'] != 1:
                        id = temp['data']['id']
                        json_response1 = await bilibili.get_gift_of_storm(id)
                        print(json_response1)
                    else:
                        printer.info([dic, "请联系开发者"])
                    '''
                else:
                    text1 = dic['real_roomid']
                    text2 = dic['url']
                    printer.info([dic, "请联系开发者"])
                    try:
                        giftId = dic['giftId']
                        printer.info(["检测到房间{:^9}的活动抽奖".format(text1)], True)
                        RaffleHandler().push2queue((giftId, text1, text2),
                                                   'handle_1_room_activity')
                        # Statistics.append2pushed_raffle('活动', area_id=area_id)

                    except:
                        printer.info([dic, "请联系开发者"])

            else:
                printer.info(['普通送礼提示', dic['msg_text']])
            return
        elif cmd == 'SYS_MSG':
            if 'real_roomid' in dic:
                real_roomid = dic['real_roomid']
                type_text = (dic['msg'].split(':?')[-1]).split(',')[0].replace(
                    '一个', '')
                printer.info(
                    [f'{self.area_id}号弹幕监控检测到{real_roomid:^9}的{type_text}'],
                    True)
                RaffleHandler().push2queue((real_roomid, ), 'handle_TV_raffle')

        elif cmd == 'GUARD_MSG':
            if 'buy_type' in dic and dic['buy_type'] == 1:
                print(dic)
                roomid = dic['roomid']
                printer.info([f'{self.area_id}号弹幕监控检测到{roomid:^9}的总督'], True)
                RaffleHandler().push2queue((roomid, ), 'handle_guard_raffle')
            if 'buy_type' in dic and dic['buy_type'] != 1:
                print(dic)
                printer.info([f'{self.area_id}号弹幕监控检测到{self.roomid:^9}的提督/舰长'],
                             True)
                RaffleHandler().push2queue((self.roomid, ),
                                           'handle_guard_raffle')
Beispiel #2
0
async def DanMuraffle(area_id, connect_roomid, dic):
    cmd = dic['cmd']
    # print(cmd)

    if cmd == 'PREPARING':
        printer.info([f'{area_id}号弹幕监控房间下播({connect_roomid})'], True)
        return False
    elif cmd == 'SYS_GIFT':
        if 'giftId' in dic:
            if dic['giftId'] == 39:
                pass
                '''
                printer.info(["节奏风暴"], True)
                temp = await bilibili.get_giftlist_of_storm(dic)
                check = len(temp['data'])
                if check != 0 and temp['data']['hasJoin'] != 1:
                    id = temp['data']['id']
                    json_response1 = await bilibili.get_gift_of_storm(id)
                    print(json_response1)
                else:
                    printer.info([dic, "请联系开发者"])
                '''
            else:
                text1 = dic['real_roomid']
                text2 = dic['url']
                printer.info([dic, "请联系开发者"])
                try:
                    giftId = dic['giftId']
                    printer.info(["检测到房间{:^9}的活动抽奖".format(text1)], True)
                    RaffleHandler().push2queue((giftId, text1, text2),
                                               'handle_1_room_activity')
                    # Statistics.append2pushed_raffle('活动', area_id=area_id)

                except:
                    printer.info([dic, "请联系开发者"])

        else:
            printer.info(['普通送礼提示', dic['msg_text']])
        return
    elif cmd == 'SYS_MSG':
        if 'real_roomid' in dic:
            real_roomid = dic['real_roomid']
            type_text = (dic['msg'].split(':?')[-1]).split(',')[0].replace(
                '一个', '')
            printer.info([f'{area_id}号弹幕监控检测到{real_roomid:^9}的{type_text}'],
                         True)
            RaffleHandler().push2queue((real_roomid, ), 'handle_1_room_TV', -1)
            # Statistics.append2pushed_raffle(type_text, area_id=area_id)

    elif cmd == 'GUARD_MSG':
        a = re.compile(r"(?<=在主播 )\S+(?= 的直播间开通了总督)")
        res = re.search(a, dic['msg'])
        if res is not None:
            name = str(res.group())
            printer.info([f'{area_id}号弹幕监控检测到{name:^9}的总督'], True)
            RaffleHandler().push2queue((name, ), 'handle_1_room_captain', -1)
Beispiel #3
0
    def handle_danmu(self, body):
        dic = json.loads(body.decode('utf-8'))
        cmd = dic['cmd']

        if cmd == 'PREPARING':
            printer.info([f'{self._area_id}号弹幕监控房间下播({self._room_id})'], True)
            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 = dic['msg_type']
            msg_common = dic['msg_common']
            real_roomid = dic['real_roomid']
            msg_common = dic['msg_common'].replace(' ', '')
            if msg_type == 2:
                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 = msg_common.split('广播')[0]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                RaffleHandler().push2queue((real_roomid, ), 'handle_TV_raffle')
                broadcast_type = 0 if broadcast == '全区' else 1
                bili_stats.add2pushed_raffles(raffle_name, broadcast_type)
            elif msg_type == 3:
                raffle_name = msg_common.split('开通了')[-1][:2]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                RaffleHandler().push2queue((real_roomid, ),
                                           'handle_guard_raffle')
                broadcast_type = 0 if raffle_name == '总督' else 2
                bili_stats.add2pushed_raffles(raffle_name, broadcast_type)
            elif msg_type == 6:
                raffle_name = '二十倍节奏风暴'
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                # rafflehandler.Rafflehandler.Put2Queue((real_roomid,), rafflehandler.handle_1_room_storm)
                bili_stats.add2pushed_raffles(raffle_name)
        return True
Beispiel #4
0
 def handle_danmu(self, body):
     dic = json.loads(body.decode('utf-8'))
     cmd = dic['cmd']
     # print(cmd)
     if cmd == 'DANMU_MSG':
         info = dic['info']
         ori = info[1]
         uid = info[2][0]
         print(ori)
         try:
             msg = self.__reverse(ori)
             result = self.__combine_piece(uid, msg)
             print('监控read dic', self.__read)
             if result is None:
                 return True
             print(result)
             type, raffle_id, room_id = result
             if type == '+':
                 printer.info([
                     f'{self._area_id}号弹幕监控检测到{room_id:^9}的大航海(id: {raffle_id})'
                 ], True)
                 RaffleHandler().push2queue((room_id, raffle_id),
                                            'handle_guard_raffle')
                 bili_stats.add2pushed_raffles('Yj协同大航海', 2)
         except Exception:
             printer.warn(f'Yj监控房间内可能有恶意干扰{uid}: {ori}')
     return True
Beispiel #5
0
    async def handle_1_room_captain(self, roomid):
        result = await self.enter_room(roomid)
        if result:
            while True:
                json_response1 = await self.webhub.get_giftlist_of_captain(roomid)
                # print(json_response1['data']['guard'])
                if not json_response1['data']['guard']:
                    await asyncio.sleep(1)
                else:
                    break

            list_available_raffleid = []
            # guard这里领取后,list对应会消失,其实就没有status了,这里是为了统一
            for j in json_response1['data']['guard']:
                id = j['id']
                status = j['status']
                if status == 1:
                    # print('未参加')
                    list_available_raffleid.append(id)
                elif status == 2:
                    # print('过滤')
                    pass
                else:
                    print(json_response1)

            tasklist = []
            num_available = len(list_available_raffleid)
            for raffleid in list_available_raffleid:
                task = asyncio.ensure_future(self.handle_1_captain_raffle(num_available, roomid, raffleid))
                tasklist.append(task)
            if tasklist:
                raffle_results = await asyncio.gather(*tasklist)
                if False in raffle_results:
                    print('有繁忙提示,稍后重新尝试')
                    RaffleHandler().Put2Queue((roomid,), 'handle_1_room_captain', self.user_id)
Beispiel #6
0
 def handle_danmu(self, dic):
     cmd = dic['cmd']
     if cmd == 'DANMU_MSG':
         msg = dic['info'][1]
         if '+' in msg:
             list_word = msg.split('+')
             try:
                 roomid = self.base2dec(list_word[0], 62)
                 raffleid = self.base2dec(list_word[1], 62)
                 printer.info([f'弹幕监控检测到{roomid:^9}的提督/舰长{raffleid}'], True)
                 RaffleHandler().push2queue((roomid, raffleid),
                                            'handle_guard_raffle')
             except ValueError:
                 print(msg)
         Printer().print_danmu(dic)
Beispiel #7
0
 async def handle_1_room_activity(self, giftId, text1, text2):
     result = True
     if result:
         json_response = await self.webhub.get_giftlist_of_events(text1)
         checklen = json_response['data']
         list_available_raffleid = []
         for j in checklen:
             # await asyncio.sleep(random.uniform(0.5, 1))
             # resttime = j['time']
             raffleid = j['raffleId']
             # if self.statistics.check_activitylist(text1, raffleid):
             #    list_available_raffleid.append(raffleid)
             list_available_raffleid.append(raffleid)
         tasklist = []
         num_available = len(list_available_raffleid)
         for raffleid in list_available_raffleid:
             task = asyncio.ensure_future(self.handle_1_activity_raffle(num_available, giftId, text1, text2, raffleid))
             tasklist.append(task)
         if tasklist:
             raffle_results = await asyncio.gather(*tasklist)
             if False in raffle_results:
                 print('有繁忙提示,稍后重新尝试')
                 RaffleHandler().Put2Queue((giftId, text1, text2), 'handle_1_room_activity', self.user_id)
Beispiel #8
0
    for user in users:
        if not (await user.handle_login_status()):
            sys.exit(-1)


loop.run_until_complete(asyncio.wait([login_all(users)]))

danmu_connection = connect.connect(
    dict_user['other_control']['default_monitor_roomid'])
list_raffle_connection = [connect.RaffleConnect(i) for i in range(1, 5)]
list_raffle_connection_task = [i.run() for i in list_raffle_connection]
yjconnection = connect.YjConnection(
    dict_user['other_control']['raffle_minitor_roomid'])

var_super_user = SuperUser(users[0])
raffle = RaffleHandler(users, var_super_user, loop, True)
normal_task = Task(users, var_super_user, loop)
state_task = StateTask(users, var_super_user, loop)

var_console = bili_console.Biliconsole(users, var_super_user, loop)
console_thread = threading.Thread(target=var_console.cmdloop)
console_thread.start()
normal_task.init()

tasks = [
    raffle.join_raffle(),
    danmu_connection.run(),
    state_task.run_workstate(),
    state_task.run_timestate(),
    yjconnection.run()
]
Beispiel #9
0
 def fall_in_jail(self):
     DelayRaffleHandler().remove(self.user_id)
     RaffleHandler().remove(self.user_id)
     Task().remove(self.user_id)
     self.printer_with_id([f'抽奖脚本检测{self.user_id}为小黑屋'], True)
Beispiel #10
0
    ]
else:
    host = Host(dict_ip['list_ips'])
    loop.run_until_complete(host.proxies_filter())
    users = [
        User(i, user_info, dict_bili, task_control, True)
        for i, user_info in enumerate(dict_user['users'])
    ]

danmu_connection = connect.connect(
    dict_user['other_control']['default_monitor_roomid'])
list_raffle_connection = [connect.RaffleConnect(i) for i in range(1, 5)]
list_raffle_connection_task = [i.run() for i in list_raffle_connection]

var_super_user = SuperUser()
raffle = RaffleHandler(users, var_super_user)
delayraffle = DelayRaffleHandler(users, var_super_user)
normal_task = Task(users, var_super_user)

queue = asyncio.Queue()
bili_console.Biliconsole(loop, queue, users)
console_thread = threading.Thread(target=bili_console.controler)
console_thread.start()

tasks = [
    raffle.join_raffle(),
    delayraffle.join_raffle(),
    normal_task.heartbeat(),
    danmu_connection.run(),
    normal_task.run(),
    bili_console.Biliconsole().run()