def notify_wds_pk(bot): """ 播报微打赏集资PK情况 :return: """ if global_config.WDS_NEED_DISPLAY_PK is False: return global modian_handler # wds_handler = WDSHandler([], []) INFO('摩点集资PK播报') for modian_entity in global_config.WDS_PK_ARRAY: target, current, pro_name = modian_handler.get_current_and_target( modian_entity) msg = '当前集资PK战况播报:\n' sorted(global_config.WDS_PK_ARRAY, key=lambda x: x.current, reverse=True) for i in range(len(global_config.WDS_PK_ARRAY)): wds = global_config.WDS_PK_ARRAY[i] sub_msg = '%d. %s\t当前进度: %.2f元\n' % (i + 1, wds.title, wds.current) msg += sub_msg INFO(msg) QQHandler.send_to_groups(modian_handler.modian_notify_groups, msg)
def get_member_room_msg_lite(self): """ 发送成员房间消息(简易版,只提醒在房间里出现) :return: """ time_now = time.time() msg = '' if self.unread_other_member_msg_amount > 0 and len( self.member_room_msg_lite_groups) > 0: if self.last_other_member_msg_time < 0 or time_now - self.last_other_member_msg_time >= 10 * 60: DEBUG('其他成员出现在房间中') member_name = ', '.join(self.other_members_names) QQHandler.send_to_groups(self.member_room_msg_lite_groups, '%s来你们灰的房间里串门啦~' % member_name) self.unread_other_member_msg_amount = 0 self.last_other_member_msg_time = time_now if self.unread_msg_amount > 0 and len( self.member_room_msg_lite_groups) > 0: # 距离上一次提醒时间超过10分钟且有未读消息 if self.last_msg_time < 0 or time_now - self.last_msg_time >= 10 * 60: DEBUG('向大群发送简易版提醒') msg = util.random_str(global_config.ROOM_MSG_LITE_NOTIFY) QQHandler.send_to_groups(self.member_room_msg_lite_groups, msg) INFO(msg) self.unread_msg_amount = 0 else: DEBUG('不向大群发送简易版提醒') self.last_msg_time = time_now else: INFO('最近10分钟内没有未读消息')
def notify_wds_pk(bot): """ 播报微打赏集资PK情况 :param bot: :return: """ if global_config.WDS_NEED_DISPLAY_PK is False: return global wds_handler # wds_handler = WDSHandler([], []) INFO('微打赏集资PK播报') for wds in global_config.WDS_PK_ARRAY: support_num, current, target = wds_handler.get_current_and_target(wds) msg = '当前集资PK战况播报:\n' sorted(global_config.WDS_PK_ARRAY, wds_pk_sort) for i in range(len(global_config.WDS_PK_ARRAY)): wds = global_config.WDS_PK_ARRAY[i] sub_msg = '%d. %s\t当前进度: %.2f元\n' % (i+1, wds.title, wds.current) msg += sub_msg INFO(msg) QQHandler.send_to_groups(wds_handler.wds_notify_groups, msg)
def parse_member_live(self, response, member_id): """ 对直播列表进行处理,找到正在直播的指定成员 :param member_id: :param response: :return: """ rsp_json = json.loads(response) # DEBUG('keys of parse member live: %s', rsp_json['content'].keys()) # 当前没有人在直播 if 'liveList' not in rsp_json['content'].keys(): # print 'no live' DEBUG('当前没有人在直播') return live_list = rsp_json['content']["liveList"] DEBUG('当前正在直播的人数: %d', len(live_list)) # print '当前正在直播的人数: %d' % len(live_list) msg = '' # DEBUG('直播ID列表: %s', ','.join(self.member_live_ids)) for live in live_list: live_id = live['liveId'] # DEBUG(live.keys()) # print '直播人: %s' % live['memberId'] # DEBUG('直播人(response): %s, 类型: %s', live['memberId'], type(live['memberId'])) # DEBUG('member_id(参数): %s, 类型: %s', member_id, type(member_id)) DEBUG('memberId %s is in live: %s, live_id: %s', live['memberId'], live['title'], live_id) DEBUG('stream path: %s', live['streamPath']) # DEBUG('member_live_ids list: %s', ','.join(self.member_live_ids)) # DEBUG('live_id is in member_live_ids: %s', str(live_id in self.member_live_ids)) if live['memberId'] == int( member_id) and live_id not in self.member_live_ids: DEBUG('[被监控成员正在直播]member_id: %s, live_id: %', member_id, live_id) start_time = util.convert_timestamp_to_timestr( live['startTime']) stream_path = live['streamPath'] # 流地址 sub_title = live['subTitle'] # 直播名称 live_type = live['liveType'] url = 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=%s' % live_id if live_type == 1: # 露脸直播 msg += '你的小宝贝儿开露脸直播了: %s\n直播链接: %s\n开始时间: %s' % ( sub_title, url, start_time) elif live_type == 2: # 电台直播 msg += '你的小宝贝儿开电台直播了: %s\n直播链接: %s\n开始时间: %s' % ( sub_title, url, start_time) self.member_live_ids.append(live_id) # 录制直播 # name = '%s_%s' % (member_id, live['startTime']) # # self.download.setName(name) # self.live_urls.put(name) # self.live_urls.put(stream_path) DEBUG(msg) if msg and len(self.member_live_groups) > 0: QQHandler.send_to_groups(self.member_live_groups, msg)
def monitor_member_weibo(bot): global weibo_monitor newWB = weibo_monitor.startMonitor() if newWB is not None: DEBUG(newWB) member_weibo_groups = QQHandler.list_group( global_config.MEMBER_WEIBO_GROUPS) message = '官博有新消息啦:\n %s\n发送时间: %s' % (newWB['scheme'], newWB['created_at']) if newWB['created_at'] == '刚刚': QQHandler.send_to_groups(member_weibo_groups, message)
def get_current_ticket_info_msg(self, schedules): ''' 自动回复票务信息 最近公演:msg ''' schedules.reverse() msg = '票务:\n' now = time.time() for s in schedules: msg += '%s\n时间:%s\n特殊说明:%s\n' % (s['title'], s['addtime'], s['special']) QQHandler.send_to_groups(self.auto_reply_groups, msg)
def parse_bilibili_video_list(self, bilibili_video_list): msg = '' for bilibili_video in bilibili_video_list: video_id = bilibili_video['aid'] if video_id not in self.bilibili_video_ids: timeStamp = bilibili_video['created'] localTime = time.localtime(timeStamp) strTime = time.strftime("%Y-%m-%d %H:%M:%S", localTime) address = 'https://www.bilibili.com/video/av%s' % (video_id) msg += '%s\n投稿时间:%s\n传送门:%s\n' % (bilibili_video['title'], strTime, address) self.bilibili_video_ids.append(video_id) DEBUG(msg) if msg and len(self.member_room_msg_groups) > 0: msg = 'b站官方账号更新:\n' + msg QQHandler.send_to_groups(self.member_room_msg_groups, msg)
def notify_performance(self): f = open('data/schedule.json') schedules = json.load(f) for s in schedules['schedules']: perform_time = util.convert_timestr_to_timestamp(s['time']) diff = perform_time - time.time() if 0 < diff <= 15 * 60: live_link = '\n'.join(global_config.LIVE_LINK) live_msg = '直播传送门: %s' % live_link notify_str = '%s\n公演: %s\n时间: %s\n队伍: %s\n%s' % ( global_config.PERFORMANCE_NOTIFY, s['name'], s['time'], s['team'], live_msg) INFO('notify str: %s', notify_str) QQHandler.send_to_groups(self.member_room_msg_lite_groups, notify_str)
def notify_performance(self, schedules): ''' 直播提醒 ''' notify_str = '' if len(schedules) > 0: for s in schedules: perform_time = int(s['pretime']) diff = perform_time - time.time() if 0 < diff <= 15 * 60: live_link = self.live_url_bilibili_or_migu(s) live_msg = '直播传送门: %s' % live_link notify_str += '%s\n %s\n 时间:%s\n %s\n' % ( global_config.PERFORMANCE_NOTIFY, s['title'], s['addtime'], live_msg) INFO('notify str: %s', notify_str) if notify_str: QQHandler.send_to_groups(self.member_room_msg_groups, notify_str) else: QQHandler.send_to_groups(self.member_room_msg_groups, '近期没有票务')
def active_member_by_name(self, name): pin_yin = util.get_member_pinyin(name) msg = '' stop_loop = False for index, deactive_item in enumerate( global_config.DEACTIVE_MEMBER_ROOM_ID_LIST): if pin_yin == deactive_item[0]: pop = global_config.DEACTIVE_MEMBER_ROOM_ID_LIST.pop(index) # 先请求这个id的消息 放进消息列表里面 r1 = self.get_member_room_msg(pop[1]) r1_json = json.loads(r1) for r in r1_json['content']['data']: msg_id = r['msgidClient'] self.member_room_msg_ids.append(msg_id) global_config.ACTIVE_MEMBER_ROOM_ID_LIST.append(pop) msg = '已开启%s房间消息' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg) break else: if stop_loop is True: break for active_item in global_config.ACTIVE_MEMBER_ROOM_ID_LIST: if pin_yin == active_item[0]: msg = '%s已在小白屋内' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg) stop_loop = True break if msg == '': msg = '%s不在监控范围内' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg)
def update_group_size(self, member_name): """ 获取群人数 :param member_name: :return: """ cursor = self.conn.cursor() DEBUG('更新群信息') QQHandler.update() try: # 获取群号 DEBUG('获取成员群号') c = cursor.execute( """ select group_number from member WHERE member_name=? """, (member_name, )) group_number = c.fetchone()[0] DEBUG('群号: %s', group_number) number = QQHandler.get_group_number(str(group_number)) DEBUG('群%s人数: %s', group_number, number) # number = 800 cur_date = util.convert_timestamp_to_timestr(time.time() * 1000) DEBUG('记录时间: %s', cur_date) DEBUG('统计:成员: %s, 群号: %s, 人数: %s, 时间: %s', member_name, group_number, number, cur_date) cursor.execute( """ INSERT INTO `group` (`member_name`, `group_number`, `group_size`, `date`) VALUES (?, ?, ?, ?) """, (member_name, group_number, number, cur_date)) self.conn.commit() except Exception as e: ERROR(e) finally: cursor.close()
def parse_room_comment(self, response): """ 对房间评论进行处理 :param response: :return: """ rsp_json = json.loads(response) msgs = rsp_json['content']['data'] # DEBUG('parse room comment reponse: %s', response) message = '' for msg in msgs: extInfo = json.loads(msg['extInfo']) platform = extInfo['platform'] msg_id = msg['msgidClient'] message_object = extInfo['messageObject'] if msg_id in self.member_room_comment_ids: continue self.member_room_comment_ids.append(msg_id) if extInfo['contentType'] == 1: # 普通评论 DEBUG('房间评论') message = ('【房间评论】[%s]-%s: %s\n' % (msg['msgTimeStr'], extInfo['senderName'], extInfo['text'])) + message elif extInfo['contentType'] == 3: # 房间礼物 DEBUG('礼物') else: DEBUG('其他类型评论') INFO('message: %s', message) DEBUG('length of comment groups: %d', len(self.member_room_comment_msg_groups)) if message and len(self.member_room_comment_msg_groups) > 0: QQHandler.send_to_groups(self.member_room_comment_msg_groups, message) DEBUG('房间评论队列: %s', len(self.member_room_comment_ids))
def notify_group_number(bot): INFO('检查群内人数') QQHandler.update() for g_number in global_config.MEMBER_ROOM_MSG_LITE_GROUPS: number = QQHandler.get_group_number(g_number) DEBUG('群%s: %d人', g_number, number) DEBUG('global_config.GROUP_MEMBER_NUM: %d', global_config.GROUP_MEMBER_NUM[g_number]) if 0 < global_config.GROUP_MEMBER_NUM[g_number] < number: INFO('有新人入群啦~') g_obj = QQHandler.list_group([g_number]) QQHandler.send_to_groups(g_obj, '中泰机器人欢迎你~/好棒') global_config.GROUP_MEMBER_NUM[g_number] = number
def update_wds_conf(bot): global wds_handler DEBUG('读取微打赏配置') ConfigReader.read_conf() wds_json = json.load(open("data/wds.json")) global_config.WDS_POSTSCRIPTS = wds_json['wds_postscripts'] # 微打赏集资PK链接数组初始化 global_config.WDS_NEED_DISPLAY_PK = wds_json['wds_need_display_pk'] for wds_pk_j in wds_json['wds_pk_activities']: wds = WDS(wds_pk_j['wds_pk_link'], wds_pk_j['wds_pk_title'], '', '', False) global_config.WDS_PK_ARRAY.append(wds) # 需要适应同时开多个链接的情况 global_config.WDS_ARRAY = [] for wds_j in wds_json['monitor_activities']: if wds_j['wds_need_display_rank'] is False: wds = WDS(wds_j['wds_link'], wds_j['wds_title'], wds_j['wds_moxi_id'], wds_j['wds_pro_id'], False) elif wds_j['wds_need_display_rank'] is True: wds = WDS(wds_j['wds_link'], wds_j['wds_title'], wds_j['wds_moxi_id'], wds_j['wds_pro_id'], True) global_config.WDS_ARRAY.append(wds) wds_handler.wds_array = global_config.WDS_ARRAY wds_handler.init_comment_queues() global_config.JIZI_NOTIFY_GROUPS = ConfigReader.get_property('qq_conf', 'jizi_notify_groups').split(';') wds_groups = QQHandler.list_group(global_config.JIZI_NOTIFY_GROUPS) wds_handler.wds_notify_groups = wds_groups DEBUG('JIZI_NOTIFY_GROUPS: %s, length: %d', ','.join(global_config.JIZI_NOTIFY_GROUPS), len(wds_handler.wds_notify_groups))
def deactive_member_by_name(self, name): pin_yin = util.get_member_pinyin(name) msg = '' stop_loop = False for index, item in enumerate(global_config.ACTIVE_MEMBER_ROOM_ID_LIST): if pin_yin == item[0]: pop = global_config.ACTIVE_MEMBER_ROOM_ID_LIST.pop(index) global_config.DEACTIVE_MEMBER_ROOM_ID_LIST.append(pop) msg = '已屏蔽%s房间消息' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg) break else: if stop_loop is True: break for item in global_config.DEACTIVE_MEMBER_ROOM_ID_LIST: if pin_yin == item[0]: msg = '%s已在小黑屋内' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg) stop_loop = True break if msg == '': msg = '%s不在监控范围内' % (name) QQHandler.send_to_groups(self.member_room_msg_groups, msg)
def parse_wds_comment2(self, r, wds): """ 对评论进行处理(微打赏接口变更,r变为html) :param r: :param wds: :return: """ PAGE_SIZE = 20 soup = BeautifulSoup(r, 'lxml') # print soup.prettify() comment_list = soup.findAll(name='li') support_num, current, target = self.get_current_and_target(wds) # project_info = '当前进度: %s元, 目标金额: %s元\n当前集资人数: %s\n' % (current, target, support_num) page_num = int(support_num) / PAGE_SIZE + 1 wds_rank_list = [] for i in range(page_num): rank_html = self.get_wds_rank(wds, page=i + 1) if rank_html is None: break soup2 = BeautifulSoup(rank_html, 'lxml') wds_rank_list.extend(soup2.findAll(name='li')) project_info = '当前进度: %s元, 目标金额: %s元\n当前集资人数: %s\n' % ( current, target, len(wds_rank_list)) for comment in comment_list: comment_id = comment.find(class_='add-jubao').get('to_comid') # print comment_id comment_id_queue = self.wds_queue_map[wds] if comment_id in comment_id_queue: continue comment_id_queue.append(comment_id) nickname = comment.find(class_='nick').string nick_sup = comment.find(class_='nick_sup').string user_id = comment.find(class_='add-jubao').get('to_user') msg = '感谢 %s %s, %s\n' % (nickname, nick_sup, util.random_str( global_config.WDS_POSTSCRIPTS)) rank_msg = '' DEBUG('WDS USER ID: %s', user_id) for rank in wds_rank_list: user_a = rank.a['href'] uid = re.findall(r"\d+\.?\d*", user_a)[0] DEBUG('user_a: %s, uid: %s', user_a, uid) if uid == user_id: cur_rank = rank.find(class_='suport_ran').string total_amount = rank.find(class_='money').string total_amount = total_amount.replace('¥ ', '') if wds.need_display_rank is True: rank_msg = "当前累计集资%s元,当前排名: %s\n" % (total_amount, cur_rank) else: rank_msg = "当前累计集资%s元\n" % total_amount break if rank_msg and len(rank_msg) > 0: msg += rank_msg if msg and len(msg) > 0: msg += project_info msg += '集资项目: %s\n链接: %s' % (wds.title, wds.link) QQHandler.send_to_groups(self.wds_notify_groups, msg) INFO('wds_message: %s', msg) DEBUG('集资评论队列: %d', len(comment_id_queue)) time.sleep(3)
def parse_order_details(self, orders, modian_entity): if len(self.order_queues[modian_entity.pro_id]) == 0 and len( orders) == 0: my_logger.debug('订单队列为空') return jiebang_activities = global_config.MODIAN_JIEBANG_ACTIVITIES[ modian_entity.pro_id] flag_activities = global_config.MODIAN_FLAG_ACTIVITIES[ modian_entity.pro_id] count_flag_activities = global_config.MODIAN_COUNT_FLAG_ACTIVITIES[ modian_entity.pro_id] # 查询集资情况 target, current, pro_name, backer_count = self.get_current_and_target( modian_entity) project_info = '当前进度: %s元, 目标金额: %s元' % (current, target) modian_entity.current = current modian_entity.title = pro_name modian_entity.target = target modian_entity.support_num = backer_count my_logger.debug('size of order %s queue: %s', modian_entity.pro_id, len(self.order_queues[modian_entity.pro_id])) for order in orders: user_id = order['user_id'] nickname = order['nickname'] pay_time = order['pay_time'] backer_money = order['backer_money'] oid = uuid.uuid3(uuid.NAMESPACE_OID, str(user_id) + pay_time) my_logger.debug('oid: %s', oid) if oid in self.order_queues[modian_entity.pro_id]: continue my_logger.debug('项目%s队列长度: %s', modian_entity.pro_id, len(self.order_queues[modian_entity.pro_id])) # 每次需要更新一下昵称 try: # supporter = Supporter(id=user_id, name=nickname) # self.alchemy_session.merge(supporter) mysql_util.query( """ INSERT INTO `supporter` (`id`, `name`) VALUES (%s, %s) ON DUPLICATE KEY UPDATE `name`=%s """, (user_id, nickname, nickname)) except Exception as e: my_logger.exception(e) try: # 创建对象 # modian_order = ModianOrder(id=str(oid), supporter_id=user_id, backer_money=backer_money, pay_time=pay_time, # pro_id=modian_entity.pro_id) # self.alchemy_session.merge(modian_order) mysql_util.query( """ INSERT INTO `order` (`id`,`supporter_id`,`backer_money`,`pay_time`, `pro_id`) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE `id`=%s """, (str(oid), user_id, backer_money, pay_time, modian_entity.pro_id, str(oid))) except Exception as e: my_logger.exception(e) msg = '感谢 %s(%s) 支持了%s元, %s\n' % ( nickname, user_id, backer_money, util.random_str(global_config.MODIAN_POSTSCRIPTS)) daka_rank, support_days = self.find_user_daka_rank( user_id, modian_entity.pro_id) if daka_rank != -1 and support_days: msg += '当前项目已打卡%s天\n' % support_days if modian_entity.need_display_rank is True: jizi_rank, backer_money = self.find_user_jizi_rank( user_id, modian_entity.pro_id) if jizi_rank != -1: msg += '当前项目已集资%s元, 排名: %s' % (backer_money, jizi_rank) else: pass # 统计当前人数 msg += '当前集资人数: %s\n' % backer_count # 抽卡播报 card_report = '' if global_config.MODIAN_CARD_DRAW: card_report = self.card_draw_handler.draw( user_id, nickname, backer_money, pay_time) '''接棒相关''' my_logger.debug('接棒情况更新') for jiebang in jiebang_activities: # if jiebang.start_time > time.time(): # continue my_logger.debug('接棒活动详情: 【%s】', jiebang.name) my_logger.debug('集资金额: %s, 接棒最小金额: %s', backer_money, jiebang.min_stick_amount) if backer_money >= jiebang.min_stick_amount: stick_num = util.compute_stick_num( jiebang.min_stick_amount, backer_money) jiebang.current_stick_num += stick_num jiebang.last_record_time = util.convert_timestamp_to_timestr( int(time.time() * 1000)) # 数据库也要更新 try: mysql_util.query( """ UPDATE jiebang SET `current_stick_num`=%s, `last_record_time`=%s WHERE `name`=%s """, (jiebang.current_stick_num, jiebang.last_record_time, jiebang.name)) except Exception as e: my_logger.error('更新接棒数据失败') my_logger.exception(e) my_logger.debug('数据库接棒数据更新完成') test_msg = '' if jiebang.need_detail == 1: test_msg = '【%s】, 当前第%s棒, 目标%s棒\n' \ % (jiebang.name, jiebang.current_stick_num, jiebang.target_stick_num) elif jiebang.need_detail == 0: test_msg = '【%s】\n' % jiebang.name elif jiebang.need_detail == 2: test_msg = '【%s】, 当前第%s棒\n' \ % (jiebang.name, jiebang.current_stick_num) elif jiebang.need_detail == 3: if stick_num > 1: test_msg = '抽奖号: {}~{}\n'.format( jiebang.current_stick_num - stick_num + 1, jiebang.current_stick_num) else: test_msg = '抽奖号: {}\n'.format( jiebang.current_stick_num) my_logger.debug(test_msg) if len(test_msg) > 0: msg += test_msg QQHandler.send_to_groups(['483548995'], test_msg) '''金额类flag相关''' my_logger.debug('flag情况更新') flag_test_msgs = '' for flag in flag_activities: my_logger.debug('Flag活动详情: %s', flag.name) my_logger.debug('Flag金额: %s, 结束时间: %s', flag.target_flag_amount, flag.end_time) diff = flag.target_flag_amount - current test_msgs = '【%s】, 目标金额: %s元, ' % (flag.name, flag.target_flag_amount) if diff > 0: test_msgs += '距离目标还差%s元\n' % round(diff, 2) flag_test_msgs += test_msgs else: test_msgs += '已经达成目标\n' my_logger.debug(flag_test_msgs) if len(flag_test_msgs) > 0: QQHandler.send_to_groups(['483548995'], flag_test_msgs) # msg += flag_test_msgs '''人头类flag相关''' my_logger.debug('人头flag情况更新') count_flag_test_msgs = '' for flag in count_flag_activities: my_logger.debug('人头Flag活动详情: %s', flag.name) my_logger.debug('人头Flag目标: %s, 开始时间: %s, 结束时间: %s', flag.target_flag_amount, flag.start_time, flag.end_time) target = flag.target_flag_amount # 统计当前人数 rst = mysql_util.select_one( """ select count(distinct(`supporter_id`)) from `order` where `pro_id` = %s and `pay_time` <= %s and `pay_time` >= %s """, (modian_entity.pro_id, flag.end_time, flag.start_time)) # 目标人数为0,代表特殊类flag,只报人数 if target == 0: count_flag_test_msgs += '【%s】, 当前人数: %s ' % (flag.name, rst[0]) else: count_flag_test_msgs += '【%s】, 当前人数: %s, 目标人数: %s ' % ( flag.name, rst[0], flag.target_flag_amount) my_logger.debug(count_flag_test_msgs) if len(count_flag_test_msgs) > 0: QQHandler.send_to_groups(['483548995'], count_flag_test_msgs) # msg += flag_test_msgs msg += '%s\n集资项目: %s\n链接: %s\n' % (project_info, pro_name, modian_entity.link) # msg += jizi_pk_report my_logger.info(msg) if global_config.USING_COOLQ_PRO is True: my_logger.debug('使用酷Q PRO发送图片') msg += '\n[CQ:image,file=http://wx1.sinaimg.cn/large/439a9f3fgy1fpllweknr6j201i01g0lz.jpg]\n' # if global_config.MODIAN_NEED_DISPLAY_PK: # msg += self.pk_modian_activity() QQHandler.send_to_groups(modian_entity.broadcast_groups, msg) if card_report: QQHandler.send_to_groups(modian_entity.broadcast_groups, card_report) # QQHandler.send_to_groups(['483548995'], card_report) self.order_queues[modian_entity.pro_id].add(oid) # 更新接棒的数据库 try: my_logger.debug('更新接棒活动信息:') for jiebang in jiebang_activities: my_logger.debug( 'current_stick_num: %s, last_record_time: %s, name: %s', jiebang.current_stick_num, jiebang.last_record_time, jiebang.name) mysql_util.query( """ UPDATE jiebang SET current_stick_num=%s WHERE name=%s """, (jiebang.current_stick_num, jiebang.name)) except Exception as e: my_logger.exception(e)
def onQQMessage(bot, contact, member, content): # 当收到 QQ 消息时被调用 # bot : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节 # contact : QContact 对象,消息的发送者 # member : QContact 对象,仅当本消息为 群或讨论组 消息时有效,代表实际发消息的成员 # content : str 对象,消息内容 # DEBUG('member: %s', str(getattr(member, 'uin'))) # DEBUG('content: %s', content) # DEBUG('contact: %s', contact.ctype) global pocket48_handler if contact.ctype == 'group': if '@ME' in content: # 在群中@机器人 strs = content.split('[@ME]')[1].strip() if strs : id = contact.uin bot.SendTo(contact, pocket48_handler.get_tuling_ai(id, strs)) else: bot.SendTo(contact, util.random_str(global_config.AT_AUTO_REPLY)) elif content.startswith('-'): # 以'-'开头才能触发自动回复 if content == '-version': bot.SendTo(contact, 'QQbot-' + bot.conf.version) elif content == '-票务' or content == '-公演': pocket48_handler.get_current_ticket_info_msg(global_config.TICKET_INFO) elif content == '-屏蔽全部消息' or content == '-屏蔽所有消息': if len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) > 0: global_config.DEACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list() global_config.ACTIVE_MEMBER_ROOM_ID_LIST = [] QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '已屏蔽全部房间消息') else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已屏蔽全部房间消息,请不要重复输入命令') elif content == '-开启全部消息' or content == '-开启全部消息': if len(global_config.DEACTIVE_MEMBER_ROOM_ID_LIST) > 0: global_config.ACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list() global_config.DEACTIVE_MEMBER_ROOM_ID_LIST = [] pocket48_handler.init_msg_queues(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '已开启全部房间消息') else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已开启全部房间消息,请不要重复输入命令') elif content == '-关闭': bot.SendTo(contact, 'QQ机器人已关闭') bot.Stop() elif '-屏蔽' in content and '消息' in content: if len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) > 0: name = util.get_order_name(content) # 命令是否包含成员名字 if util.is_name_in_member_list(name): # 屏蔽逻辑 pocket48_handler.deactive_member_by_name(name) else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '屏蔽失败, 无法识别该成员,请确保命令输入正确') else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已屏蔽全部房间消息,无法再进行屏蔽') elif '-开启' in content and '消息' in content: if len(global_config.DEACTIVE_MEMBER_ROOM_ID_LIST) > 0: name = util.get_order_name(content) # 命令是否包含成员名字 if util.is_name_in_member_list(name): # 开启逻辑 pocket48_handler.active_member_by_name(name) else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '开启失败, 无法识别该成员,请确保命令输入正确') else: QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已开启全部房间消息,无法再进行开启') elif content == '-直播': r = pocket48_handler.get_member_live_msg() pocket48_handler.parse_member_live_now(r, global_config.LIVING_MEMBER_ID_LIST) elif content == '-小黑屋': msg = util.get_black_room_list() QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg) elif content == '-小白屋': msg = util.get_white_room_list() QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg) elif content == '-使用说明': msg = ''' 机器人使用说明: 一、命令类型(输入一次即可, 没回复可能是机器人没开启 或者 机器人卡住了): (1)'-票务': 查看尚未公演的票务信息. (2)'-直播': 查看所有正在直播的直播间. (3)'-使用说明': 机器人使用说明. (4)'-屏蔽全部(所有)消息': 屏蔽全部成员房间消息. (5)'-开启全部(所有)消息': 开启全部成员房间消息. (6)'-屏蔽' + 成员名字 + '消息': 屏蔽某个成员房间消息. (7)'-开启' + 成员名字 + '消息': 开启某个成员房间消息. (8)'-小黑屋': 查看被屏蔽房间消息的成员. (9)'-小白屋': 查看已开启房间消息的成员 其余命令均无法识别 二、聊天 '@机器人' + 聊天内容: 与图灵机器人聊天 (每天上限1000次, 河内梗完善中...)''' QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg) else: # 无法识别命令 no_such_command = ConfigReader.get_property('profile', 'no_such_command') bot.SendTo(contact, no_such_command)
def onStartupComplete(bot): # 启动完成时被调用 # bot : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节 DEBUG('%s.onStartupComplete', __name__) global pocket48_handler # 实例化PocketHandler pocket48_handler = Pocket48Handler([], [], [], [], []) # 获取票务 global_config.TICKET_INFO = pocket48_handler.get_ticket_info() # 登录口袋48 username = ConfigReader.get_property('user', 'username') password = ConfigReader.get_property('user', 'password') pocket48_handler.login(username, password) DEBUG('读取配置文件') ConfigReader.read_conf() global_config.ACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list() global_config.LIVING_MEMBER_ID_LIST = ConfigReader.get_living_member_id_list() global_config.AUTO_REPLY_GROUPS = ConfigReader.get_property('qq_conf', 'auto_reply_groups').split(';') global_config.MEMBER_ROOM_MSG_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_msg_groups').split(';') global_config.MEMBER_ROOM_COMMENT_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_comment_groups').split(';') global_config.MEMBER_LIVE_GROUPS = ConfigReader.get_property('qq_conf', 'member_live_groups').split(';') global_config.MEMBER_ROOM_MSG_LITE_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_comment_lite_groups').split(';') auto_reply_groups = QQHandler.list_group(global_config.AUTO_REPLY_GROUPS) member_room_msg_groups = QQHandler.list_group(global_config.MEMBER_ROOM_MSG_GROUPS) member_room_comment_msg_groups = QQHandler.list_group(global_config.MEMBER_ROOM_COMMENT_GROUPS) member_live_groups = QQHandler.list_group(global_config.MEMBER_LIVE_GROUPS) member_room_msg_lite_groups = QQHandler.list_group(global_config.MEMBER_ROOM_MSG_LITE_GROUPS) pocket48_handler.member_room_msg_groups = member_room_msg_groups pocket48_handler.member_room_comment_msg_groups = member_room_comment_msg_groups pocket48_handler.auto_reply_groups = auto_reply_groups pocket48_handler.member_live_groups = member_live_groups pocket48_handler.member_room_msg_lite_groups = member_room_msg_lite_groups global_config.JIZI_KEYWORDS = ConfigReader.get_property('profile', 'jizi_keywords').split(';') global_config.JIZI_LINK = ConfigReader.get_property('profile', 'jizi_link').split(';') global_config.WEIBO_KEYWORDS = ConfigReader.get_property('profile', 'weibo_keywords').split(';') global_config.GONGYAN_KEYWORDS = ConfigReader.get_property('profile', 'gongyan_keywords').split(';') global_config.LIVE_LINK=ConfigReader.get_property('profile', 'live_link').split(';') global_config.LIVE_SCHEDULE = ConfigReader.get_property('profile', 'live_schedule').split(';') global_config.WEIBO_LINK = ConfigReader.get_property('profile', 'weibo_link') global_config.SUPER_TAG = ConfigReader.get_property('profile', 'super_tag') global_config.MEMBER_ATTR = ConfigReader.get_property('profile', 'member_attr') global_config.I_LOVE = ConfigReader.get_property('profile', 'i_love').split(';') global_config.AT_AUTO_REPLY = ConfigReader.get_property('profile', 'at_auto_reply').split(';') global_config.ROOM_MSG_LITE_NOTIFY = ConfigReader.get_property('profile', 'room_msg_lite_notify').split(';') global_config.PERFORMANCE_NOTIFY = ConfigReader.get_property('profile', 'performance_notify') # 哔哩哔哩消息初始化 bilibili_video_list = pocket48_handler.get_bilibili_video_list() pocket48_handler.init_bilibili_video_queues(bilibili_video_list) # 成员房间消息初始队列化 pocket48_handler.init_msg_queues(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) # 先更新配置 update_conf(bot)
def parse_room_msg(self, response): """ 对成员消息进行处理 :param response: :return: """ DEBUG('parse room msg response: %s', response) rsp_json = json.loads(response) msgs = {} try: msgs = rsp_json['content']['data'] except Exception as e: ERROR('房间消息异常') ERROR(e) return message = '' for msg in msgs: extInfo = json.loads(msg['extInfo']) msg_id = msg['msgidClient'] # 消息id if msg_id in self.member_room_msg_ids: continue if extInfo['senderRole'] != 1: # 其他成员的消息 self.unread_other_member_msg_amount += 1 member_name = extInfo['senderName'] if member_name == '你们的小可爱': member_name = 'YBY' if member_name not in self.other_members_names: self.other_members_names.append(member_name) else: self.unread_msg_amount += 1 DEBUG('成员消息') self.member_room_msg_ids.append(msg_id) message_object = extInfo['messageObject'] DEBUG('extInfo.keys():' + ','.join(extInfo.keys())) if msg['msgType'] == 0: # 文字消息 if message_object == 'text': # 普通消息 DEBUG('普通消息') name = extInfo['senderName'] default_name = '成员' nickname = util.get_member_nickname(name, default_name) message = ( '【%s消息】[%s]-%s: %s\n' % (nickname, msg['msgTimeStr'], extInfo['senderName'], extInfo['text'])) + message elif message_object == 'faipaiText': # 翻牌消息 DEBUG('翻牌') member_msg = extInfo['messageText'] fanpai_msg = extInfo['faipaiContent'] name = extInfo['senderName'] nickname = util.get_member_nickname(name) message = ( '【%s翻牌】[%s]-%s: %s\n【被翻牌】%s\n' % (nickname, msg['msgTimeStr'], extInfo['senderName'], member_msg, fanpai_msg)) + message # TODO: 直播可以直接在房间里监控 elif message_object == 'diantai': # 电台直播 DEBUG('电台直播') reference_content = extInfo['referenceContent'] live_id = extInfo['referenceObjectId'] elif message_object == 'live': # 露脸直播 DEBUG('露脸直播') reference_content = extInfo['referenceContent'] live_id = extInfo['referenceObjectId'] elif msg['msgType'] == 1: # 图片消息 bodys = json.loads(msg['bodys']) DEBUG('图片') if 'url' in bodys.keys(): url = bodys['url'] message = ('【图片】[%s]-%s: %s\n' % (msg['msgTimeStr'], extInfo['senderName'], url)) + message elif msg['msgType'] == 2: # 语音消息 DEBUG('语音消息') bodys = json.loads(msg['bodys']) if 'url' in bodys.keys(): url = bodys['url'] message = ('【语音】[%s]-%s: %s\n' % (msg['msgTimeStr'], extInfo['senderName'], url)) + message elif msg['msgType'] == 3: # 小视频 DEBUG('房间小视频') bodys = json.loads(msg['bodys']) if 'url' in bodys.keys(): url = bodys['url'] message = ('【小视频】[%s]-%s: %s\n' % (msg['msgTimeStr'], extInfo['senderName'], url)) + message if message and len(self.member_room_msg_groups) > 0: QQHandler.send_to_groups(self.member_room_msg_groups, message) # self.get_member_room_msg_lite() INFO('message: %s', message) DEBUG('成员消息队列: %s', len(self.member_room_msg_ids))
def kuan_time_broadcast(self): """ 款时播报 :return: """ QQHandler.send_to_groups(['101724227'], '款时')