예제 #1
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('测试', self.__read, ori)
         try:
             msg = self.__reverse(ori)
             if msg is not None:
                 msg_id, type, id = msg
                 if type == '~' and not msg_id % 2:
                     raffle_id = id
                     printer.info([
                         f'{self._area_id}号弹幕监控检测到{"0":^9}的节奏风暴(id: {raffle_id})'
                     ], True)
                     # raffle_handler.exec_at_once(StormRaffleHandlerTask, 0, raffle_id)
                     bili_statistics.add2pushed_raffles('Yj协同节奏风暴', 2)
             result = self.__combine_piece(uid, msg)
             if result is None:
                 return True
             type, raffle_id, real_roomid = result
             if type == '+':
                 printer.info([
                     f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的大航海(id: {raffle_id})'
                 ], True)
                 raffle_handler.push2queue(GuardRaffleHandlerTask,
                                           real_roomid, raffle_id)
                 bili_statistics.add2pushed_raffles('Yj协同大航海', 2)
         except Exception:
             printer.warn(f'Yj监控房间内可能有恶意干扰{uid}: {ori}')
     return True
예제 #2
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(' ', '')
            msg_common = msg_common.replace('”', '')
            msg_common = msg_common.replace('“', '')
            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 = msg_common.split('广播')[0]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                raffle_handler.push2queue(TvRaffleHandlerTask, real_roomid)
                broadcast_type = 0 if broadcast == '全区' else 1
                bili_statistics.add2pushed_raffles(raffle_name, broadcast_type,
                                                   raffle_num)
            elif msg_type == 3:
                raffle_name = msg_common.split('开通了')[-1][:2]
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                raffle_handler.push2queue(GuardRaffleHandlerTask, real_roomid)
                broadcast_type = 0 if raffle_name == '总督' else 2
                bili_statistics.add2pushed_raffles(raffle_name, broadcast_type)
            elif msg_type == 6:
                raffle_name = '二十倍节奏风暴'
                printer.info(
                    [f'{self._area_id}号弹幕监控检测到{real_roomid:^9}的{raffle_name}'],
                    True)
                # raffle_handler.push2queue(StormRaffleHandlerTask, real_roomid)
                bili_statistics.add2pushed_raffles(raffle_name)
        return True