

___X_CMD_WEIXIN_BOT_DATA="$___X_CMD_ROOT_DATA/weixin/bot/data.tsv"
___X_CMD_WEIXIN_BOT_DATA_MEDIA_DIR="$___X_CMD_ROOT_DATA/weixin/bot/data"

___x_cmd_weixin_bot_data(){
    [ $# -gt 0 ]    ||  set -- which

    local op="$1" ;     shift
    case "$op" in
        -h|--help)      ___x_cmd help -m weixin bot data "$@" ; return 0 ;;
        which|which_)
                        ___x_cmd_weixin_bot_data_"$op"   "$@" ;;
    esac
}

___x_cmd_weixin_bot_data_which_(){
    x_="$___X_CMD_WEIXIN_BOT_DATA"
}

___x_cmd_weixin_bot_data_which(){
    local x_
    ___x_cmd_weixin_bot_data_which_ || return $?
    printf "%s\n" "$x_"
}

# x weixin bot data 10:100
___x_cmd_weixin_bot_data_slice(){
    local slice="$1"
    local begin="${slice%:*}"   # start from 1
    local end="${slice#*:}"     # inclusive

    ___x_cmd_cmds awk \
        -v begin="$begin" -v end="$end" \
        '(NR>=begin)&&(NR<=end){ print }' <"$___X_CMD_WEIXIN_BOT_DATA"
}

___x_cmd_weixin_bot_data_recent(){
    local offsetfile
    local offset=1

    while [ $# -gt 0 ]; do
        case "$1" in
            --offsetfile)       offsetfile="$2" ;   arg:2:shift ;;
            --offset)           offset="$2" ;       arg:2:shift ;;
            *)                  break ;;
        esac
    done

    if [ $# -gt 0 ]; then
        offset="$1" ; shift
    elif [ -n "$offset" ]; then
        :
    elif [ -n "$offsetfile" ]; then
        read -r offset <"$offset"
    else
        N=weixin M="Please provide offset by --offset or --offsetfile" log:ret:64
    fi

    ___x_cmd_cmds tail -n +"$offset" "$___X_CMD_WEIXIN_BOT_DATA"
}

