Exemplo n.º 1
0
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_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()